/* ═══════════════════════════════════════════════════════════════
   Character Engine (cr-*)
   Shared by study-space.html and learning-space.html
   ═══════════════════════════════════════════════════════════════ */

/* Mode picker */
.cr-mode-picker { text-align: center; padding: 0 16px 32px; }
.cr-mode-title {
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--text);
  text-align: center;
  margin-bottom: clamp(12px, 2vh, 20px);
}
.cr-mode-heading { font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.cr-mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  max-width: 640px;
  margin: 0 auto;
}
.cr-mode-cards {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  max-width: 580px;
  margin: 0 auto;
}
.cr-mode-cards .cr-mode-card {
  flex: 1 1 0;
  min-width: 0;
}
.cr-mode-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
  font-family: inherit;
}
.cr-mode-card:hover:not(.cr-mode-disabled) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow), 0 4px 20px var(--accent-glow);
  transform: translateY(-2px);
}
.cr-mode-disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}
.cr-mode-icon { font-size: 32px; display: block; margin-bottom: 8px; }
.cr-mode-card h3 { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.cr-mode-card p { font-size: 12px; color: var(--muted); line-height: 1.4; }
.cr-mode-soon {
  display: inline-block;
  font-size: 10px;
  background: var(--surface2);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 8px;
  margin-top: 6px;
}

/* Write mode layout */
.cr-write-wrap { padding: 12px 16px; max-width: 480px; margin: 0 auto; }
.cr-top-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.cr-top-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cr-back-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 0;
  font-family: inherit;
}
/* Progress bar */
.cr-progress-bar-wrap {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 0;
  row-gap: 5px;
  width: 100%;
}
.cr-progress-track {
  grid-column: 1/4;
  grid-row: 1;
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.cr-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4A9E6B, #5CC87E);
  border-radius: 4px;
  transition: width 0.4s ease;
}
.cr-progress-label {
  grid-column: 1;
  grid-row: 2;
  font-size: 11px;
  color: var(--muted);
}
.cr-progress-total {
  grid-column: 3;
  grid-row: 2;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}
.cr-progress { font-size: 13px; color: var(--muted); }

/* Character info */
.cr-char-info { text-align: center; margin-bottom: 16px; }
.cr-char-pinyin {
  font-size: 28px;
  font-weight: 700;
  font-family: 'DM Sans', sans-serif;
}
.cr-char-meaning {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
}

/* HanziWriter canvas */
.cr-canvas-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.cr-writer-target {
  width: 300px;
  height: 300px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  position: relative;
}
/* Grid lines inside writer */
.cr-writer-target::before,
.cr-writer-target::after {
  content: '';
  position: absolute;
  background: var(--border);
  opacity: 0.3;
  z-index: 0;
}
.cr-writer-target::before {
  top: 50%;
  left: 10%;
  right: 10%;
  height: 1px;
}
.cr-writer-target::after {
  left: 50%;
  top: 10%;
  bottom: 10%;
  width: 1px;
}

/* Controls */
.cr-controls { text-align: center; }
.cr-difficulty-toggle {
  display: inline-flex;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 14px;
}
.cr-diff-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.cr-diff-btn:hover { background: var(--surface2); }
.cr-diff-active {
  background: var(--accent) !important;
  color: #fff !important;
}
.cr-action-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.cr-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.cr-btn:hover {
  border-color: var(--accent);
  background: var(--surface2);
}
.cr-btn-quiz {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.cr-btn-quiz:hover {
  background: var(--accent-hover, var(--accent));
}

/* Feedback area */
.cr-feedback {
  text-align: center;
  min-height: 24px;
  font-size: 14px;
  margin-top: 14px;
  transition: opacity 0.2s;
}

/* Completion screen */
.cr-completion {
  text-align: center;
  padding: 48px 24px;
}
.cr-completion-icon { font-size: 48px; margin-bottom: 12px; }
.cr-completion h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 16px;
}
.cr-completion-score {
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 4px;
}
.cr-completion-pct {
  font-size: 36px;
  font-weight: 700;
  color: var(--t3);
  margin-bottom: 24px;
}
.cr-completion-btns {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.cr-completion-btns button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 24px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.cr-completion-btns button:first-child {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Responsive */
@media (max-width: 480px) {
  .cr-writer-target { width: 250px; height: 250px; }
  .cr-char-pinyin { font-size: 24px; }
  .cr-diff-btn { padding: 6px 12px; font-size: 12px; }
  .cr-btn { padding: 8px 16px; font-size: 13px; }
}

/* ── Discriminate mode ────────────────────────────────────────── */
.cr-disc-wrap { padding: 12px 16px; max-width: 480px; margin: 0 auto; }
.cr-disc-prompt { text-align: center; margin-bottom: 24px; }
.cr-disc-meaning {
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 8px;
}
.cr-disc-target {
  font-size: 64px;
  font-family: 'Noto Serif SC', serif;
  font-weight: 700;
  line-height: 1.2;
}
.cr-disc-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 12px;
  max-width: 360px;
  margin: 0 auto 20px;
}
.cr-disc-option {
  font-size: 40px;
  font-family: 'Noto Serif SC', serif;
  padding: 16px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  color: var(--text);
}
.cr-disc-option:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.cr-disc-option:disabled { cursor: default; }
.cr-disc-hint {
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  min-height: 24px;
  margin-bottom: 8px;
}
.cr-disc-hint-text {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  padding: 12px;
  background: var(--surface);
  border-radius: 10px;
  max-width: 400px;
  margin: 0 auto;
}

/* ── Component Explorer mode ──────────────────────────────────── */
.cr-comp-wrap { padding: 12px 16px; max-width: 520px; margin: 0 auto; }
.cr-comp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}
.cr-comp-char-btn {
  font-size: 28px;
  font-family: 'Noto Serif SC', serif;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.15s, transform 0.1s;
}
.cr-comp-char-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.cr-comp-char-active {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 1px var(--accent-glow);
}

/* Detail panel */
.cr-comp-detail-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  text-align: center;
}
.cr-comp-detail-char {
  font-size: 56px;
  font-family: 'Noto Serif SC', serif;
  font-weight: 700;
  margin-bottom: 8px;
}
.cr-comp-detail-radical {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 16px;
}

/* Component breakdown display */
.cr-comp-breakdown {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 12px;
}
.cr-comp-piece { text-align: center; }
.cr-comp-piece-char {
  display: block;
  font-size: 32px;
  font-family: 'Noto Serif SC', serif;
  font-weight: 700;
}
.cr-comp-piece-result { color: var(--accent); }
.cr-comp-piece-meaning {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.cr-comp-plus, .cr-comp-equals {
  font-size: 20px;
  color: var(--muted);
  font-weight: 700;
}

/* Hint / mnemonic */
.cr-comp-hint {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: 10px;
  margin-top: 10px;
  font-style: italic;
}

/* Radical quiz */
.cr-rq-prompt {
  text-align: center;
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 12px;
}
.cr-rq-radical {
  text-align: center;
  font-size: 64px;
  font-family: 'Noto Serif SC', serif;
  font-weight: 700;
  margin-bottom: 20px;
}
.cr-rq-option.cr-rq-selected {
  border-color: var(--accent);
  background: rgba(91, 141, 239, 0.1);
}
.cr-rq-confirm {
  display: block;
}

/* Builder */
.cr-builder-prompt {
  text-align: center;
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 16px;
}
