:root {
  --bg: #131a28;
  --surface: #151d30;
  --surface-2: #222b40;
  --border: #284381;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #6aa9ff;
  --accent-irr: #c0392b;
  --accent-2: #8be7c0;
  --error: #ff7a8a;
  --success: #5fd699;
  --warning: #ffd66a;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Malgun Gothic", "Noto Sans KR", Roboto, sans-serif;
}

/* Irregulars mode: swap accent to burgundy + reddish background */
body.irr-mode {
  --accent:    #c0392b;
  --bg:        #120a0a;
  --surface:   #1d0f0f;
  --surface-2: #261414;
  --border:    #3d1c1c;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 12px;
}

.topbar-left  { display: flex; align-items: center; }
.topbar-right { display: flex; align-items: center; }

/* ── App brand + mode dropdown ───────────────────────────────────────────── */
.app-brand {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent);
  margin-right: 12px;
  white-space: nowrap;
  user-select: none;
}

/* Custom visual dropdown */
.mode-dropdown {
  position: relative;
}

.mode-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.mode-dropdown-trigger:hover,
.mode-dropdown[aria-expanded="true"] .mode-dropdown-trigger {
  border-color: var(--accent);
  background: var(--surface-2);
}
.mode-dropdown-trigger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mode-dropdown-arrow {
  color: var(--muted);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}
.mode-dropdown[aria-expanded="true"] .mode-dropdown-arrow {
  transform: rotate(180deg);
}

.mode-dropdown-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 4px;
  z-index: 100;
  list-style: none;
  margin: 0;
  transform-origin: top left;
  animation: dropdownOpen 0.15s ease;
}
@keyframes dropdownOpen {
  from { opacity: 0; transform: scaleY(0.92) translateY(-4px); }
  to   { opacity: 1; transform: scaleY(1)    translateY(0); }
}

.mode-dropdown-option {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.mode-dropdown-option:hover {
  background: var(--surface-2);
  color: var(--text);
}
.mode-dropdown-option.active {
  color: var(--accent);
  font-weight: 600;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--border); }
.icon-btn .gear { font-size: 16px; }

.topbar-actions {
  display: flex;
  gap: 8px;
}

.history-empty {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 0 0;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.history-item.correct  { border-left-color: var(--success); }
.history-item.wrong    { border-left-color: var(--error); }
.history-item.skipped  { border-left-color: var(--muted); }
.history-item.revealed { border-left-color: var(--warning); }

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.history-result-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.history-result-tag.correct  { color: var(--success); }
.history-result-tag.wrong    { color: var(--error); }
.history-result-tag.skipped  { color: var(--muted); }
.history-result-tag.revealed { color: var(--warning); }

.history-cat {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}

.history-question {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  word-wrap: break-word;
}

.history-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  word-wrap: break-word;
}
.history-meta code {
  background: var(--surface);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
}

.history-try-btn {
  margin-top: 8px;
  font-size: 12px;
  padding: 5px 10px;
}
[hidden] {
  display: none !important;
}

.settings-panel {
  position: fixed;
  top: 56px;
  right: 20px;
  width: min(420px, calc(100vw - 40px));
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  z-index: 20;
  transform-origin: top right;
  animation: panelSlideIn 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
.settings-panel[hidden] { display: none; }
.settings-panel.panel-closing {
  animation: panelSlideOut 0.1s ease forwards;
  pointer-events: none;
}

/* Panel header row: title + close button side by side */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}
.panel-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.settings-close-btn {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}
.settings-close-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.category-group-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.category-group-label input { cursor: pointer; }

.settings-section {
  margin-bottom: 18px;
}
.settings-section:last-child { margin-bottom: 0; }
.settings-section h3 {
  margin: 0 0 10px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-head h3 { margin: 0; }
.section-actions { display: flex; gap: 8px; }

.link-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  font-family: inherit;
}
.link-btn:hover { text-decoration: underline; }

.category-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.category-group {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.category-group-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px 0;
}
.subcategory-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-left: 4px;
}
.cat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.cat-row input { cursor: pointer; }

.number-system-filter {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.filter-label {
  color: var(--muted);
  font-size: 12px;
  margin-right: 2px;
}
.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}
.filter-pill input { margin: 0; cursor: pointer; }

.inline-number {
  width: 70px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 13px;
  font-family: inherit;
  margin: 0 4px;
}
.inline-number:focus {
  outline: none;
  border-color: var(--accent);
}

.full-width-btn {
  width: 100%;
  margin-top: 8px;
}

.mode-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 14px;
  gap: 2px;
}
.mode-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  background: var(--accent);
  color: #0f1115;
}

.replay-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 22px;
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.replay-btn:hover { background: var(--border); }
.replay-btn:active { transform: scale(0.97); }
.replay-icon { font-size: 22px; line-height: 1; }
#listeningPrompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.speed-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 280px;
}
.speed-side {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.speed-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
}
.speed-row input[type="range"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.speed-val {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 14px;
  cursor: pointer;
}

.slider-row {
  margin-top: 12px;
}
.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 14px;
  margin-bottom: 8px;
}
.slider-value {
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.primary-btn {
  background: var(--accent);
  color: #0f1115;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.15s;
  width: 100%;
}
.primary-btn:hover { filter: brightness(1.08); }

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.ghost-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.main {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px 40px;
}

.loading, .empty-state {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.meta-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.help-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  line-height: 1;
}
.help-btn:hover,
.help-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f1115;
}
.help-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 13px;
  line-height: 1.6;
  animation: fadeIn 0.1s ease forwards;
}
.help-panel.help-closing {
  animation: fadeOut 0.1s ease forwards;
  pointer-events: none;
}
.help-panel[hidden] { display: none; }
.help-explanation {
  margin: 0 0 4px 0;
  color: var(--text);
}
.help-example {
  margin: 0;
  color: var(--muted);
  font-style: italic;
}
.badge {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}
.system-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.sys-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.sys-native { background: rgba(106, 169, 255, 0.12); color: var(--accent); border-color: rgba(106, 169, 255, 0.3); }
.sys-sino   { background: rgba(139, 231, 192, 0.12); color: var(--accent-2); border-color: rgba(139, 231, 192, 0.3); }
.sys-digit  { background: rgba(255, 214, 106, 0.12); color: var(--warning); border-color: rgba(255, 214, 106, 0.3); }

/* ── Subtle animations ──────────────────────────────────────────────────── */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes fadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}
@keyframes panelSlideIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}
@keyframes panelSlideOut {
  from { opacity: 1; transform: translateY(0)    scale(1); }
  to   { opacity: 0; transform: translateY(-10px) scale(0.97); }
}
@keyframes pageAppear {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Re-run animation by toggling this class off/on */
.anim-new {
  animation: fadeSlideUp 0.25s ease !important;
}

/* Page-level appear (game area first show) */
.anim-page-appear {
  animation: pageAppear 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
  margin-bottom: 16px;
  min-height: 185px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
#writingPrompt,
#listeningPrompt { width: 100%; }
.prompt-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 12px;
}
.question-display {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  word-wrap: break-word;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.answer-form {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}
.answer-input {
  flex: 1;
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 18px;
  font-family: inherit;
  transition: border-color 0.15s;
}
.answer-input:focus {
  outline: none;
  border-color: var(--accent);
}
.answer-form .primary-btn { width: auto; padding: 12px 24px; }

.feedback {
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.feedback.correct {
  border-color: rgba(95, 214, 153, 0.4);
  background: rgba(95, 214, 153, 0.08);
}
.feedback.incorrect {
  border-color: rgba(255, 122, 138, 0.4);
  background: rgba(255, 122, 138, 0.08);
}
.feedback.revealed {
  border-color: rgba(255, 214, 106, 0.4);
  background: rgba(255, 214, 106, 0.08);
}
.feedback-title {
  font-weight: 600;
  margin-bottom: 6px;
}
.feedback-title.correct { color: var(--success); }
.feedback-title.incorrect { color: var(--error); }
.feedback-title.revealed { color: var(--warning); }
.answer-list {
  margin: 4px 0 0 0;
  padding-left: 18px;
  color: var(--text);
}
.answer-list li {
  font-size: 16px;
  margin: 2px 0;
}
.user-answer {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}
.user-answer code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text);
}

.action-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 24px;
}

.score-row {
  display: flex;
  justify-content: center;
  gap: 24px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.score-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.score-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

@media (max-width: 540px) {
  .question-display { font-size: 26px; }
  .settings-panel { right: 10px; left: 10px; width: auto; }
  .main { padding: 20px 14px 30px; }
  .app-tab { padding: 6px 12px; font-size: 13px; }
}

/* ── Irregulars-specific styles ─────────────────────────────────────────── */

/* Active tab pill: use white text on burgundy bg */
body.irr-mode .app-tab.active { color: #fff; }

/* Badge tinted burgundy in irr mode */
body.irr-mode .badge {
  border-color: rgba(192, 57, 43, 0.35);
  color: var(--accent);
  background: rgba(192, 57, 43, 0.12);
}

/* Question card tint for irregulars */
.irr-card {
  border-color: rgba(192, 57, 43, 0.28);
  min-height: 200px;
}

/* Large verb display */
.irr-verb {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: 10px;
}

/* Ending label below the verb */
.irr-ending-label {
  font-size: 15px;
  color: var(--accent);
  font-weight: 500;
  letter-spacing: 0.01em;
  margin-top: 4px;
}

/* In irr mode all accent-driven elements use the inherited --accent var automatically;
   these overrides handle elements that reference the old hard-coded colors. */
body.irr-mode .help-panel                   { border-left-color: var(--accent); }
body.irr-mode .help-btn:hover,
body.irr-mode .help-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
