* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, #2c2c2c, #3a3a3a);
  color: white;
  padding: 2rem 1rem;
  text-align: center;
}
header h1 {
  font-size: 1.8rem;
  margin-bottom: 0.3rem;
}
header p {
  font-size: 0.95rem;
  opacity: 0.9;
}
header .hanzi-decoration {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  letter-spacing: 0.3em;
}

.container {
  max-width: 720px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card h2 {
  font-size: 1.1rem;
  color: #3a3a3a;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e8e4e0;
}

/* Character input */
.input-section textarea {
  width: 100%;
  height: 140px;
  padding: 0.75rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1.3rem;
  font-family: 'AR PL UKai CN', 'STKaiti', 'Kaiti SC', 'KaiTi', serif;
  line-height: 1.8;
  resize: vertical;
  transition: border-color 0.2s;
}
.input-section textarea:focus {
  outline: none;
  border-color: #555;
}
.input-section textarea::placeholder {
  font-size: 0.9rem;
  color: #aaa;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
}
.input-hint {
  font-size: 0.8rem;
  color: #888;
}
.char-count {
  font-size: 0.8rem;
  color: #888;
  white-space: nowrap;
}

.option-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Character set toggle */
.toggle-group {
  display: flex;
  gap: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #e0e0e0;
  width: fit-content;
}
.toggle-group label {
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  border-right: 1px solid #e0e0e0;
  transition: all 0.2s;
  user-select: none;
}
.toggle-group label:last-child { border-right: none; }
.toggle-group input[type="radio"] { display: none; }
.toggle-group input[type="radio"]:checked + label {
  background: #3a3a3a;
  color: white;
}

/* Options grid */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 500px) {
  .options-grid { grid-template-columns: 1fr; }
}

.option-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.option-item label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.option-item select,
.option-item input[type="text"],
.option-item input[type="number"] {
  padding: 0.5rem 0.6rem;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  font-size: 0.9rem;
  background: white;
  transition: border-color 0.2s;
}
.option-item select:focus,
.option-item input:focus {
  outline: none;
  border-color: #555;
}

/* Toggle switches */
.toggles-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #f0f0f0;
}
.toggle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.toggle-item span {
  font-size: 0.85rem;
  color: #555;
}
.switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 24px;
  cursor: pointer;
  transition: 0.3s;
}
.switch .slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}
.switch input:checked + .slider { background: #4caf50; }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* Color swatches */
.color-options {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.color-swatch {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
}
.color-swatch input[type="radio"] { display: none; }
.color-swatch .dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #ddd;
  transition: border-color 0.2s, transform 0.2s;
}
.color-swatch input:checked + .dot {
  border-color: #333;
  transform: scale(1.15);
}
.color-swatch .dot.green { background: #4caf50; }
.color-swatch .dot.gray { background: #9e9e9e; }
.color-swatch .dot.red { background: #e53935; }
.color-swatch .dot.blue { background: #1e88e5; }
.color-swatch .dot.black { background: #333; }
.color-swatch span:last-child {
  font-size: 0.75rem;
  color: #777;
}

/* Collapsible options */
.options-card details summary {
  cursor: pointer;
  list-style: none;
}
.options-card details summary::-webkit-details-marker { display: none; }
.options-card details summary h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.options-card details summary h2::after {
  content: '▾';
  font-size: 1rem;
  color: #999;
  transition: transform 0.2s;
}
.options-card details:not([open]) summary h2::after {
  transform: rotate(-90deg);
}

/* Preview */
.preview-card { padding: 1.2rem 1.5rem; }
.preview-row {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.preview-pinyin {
  font-size: 0.7rem;
  color: #888;
}
.preview-def {
  font-size: 0.65rem;
  color: #aaa;
  font-style: italic;
}
.preview-cells {
  display: flex;
  gap: 2px;
}
.preview-cell {
  width: 48px;
  height: 48px;
  border: 1.5px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-family: 'AR PL UKai CN', 'STKaiti', 'Kaiti SC', 'KaiTi', serif;
  position: relative;
  background: white;
}
.preview-cell.model {
  font-weight: bold;
}
.preview-cell.traced {
  color: #d0d0d0;
}
.preview-cell.empty {
}
.preview-label {
  text-align: center;
  font-size: 0.7rem;
  color: #aaa;
  margin-top: 0.5rem;
}
@media (max-width: 500px) {
  .preview-cell { width: 36px; height: 36px; font-size: 1.1rem; }
}

/* Generate button */
.generate-section {
  text-align: center;
  padding: 0.5rem 0 1rem;
}
.page-estimate {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: #666;
}
.btn-generate {
  background: linear-gradient(135deg, #3a3a3a, #2c2c2c);
  color: white;
  border: none;
  padding: 0.9rem 2.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}
.btn-generate:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.3);
}
.btn-generate:active { transform: translateY(0); }
.btn-generate:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.status-message {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  min-height: 1.2em;
}
.status-message.error { color: #c62828; }
.status-message.loading { color: #666; }

footer {
  text-align: center;
  padding: 1.5rem;
  color: #aaa;
  font-size: 0.8rem;
}
