/* ============================================================================
   KiraKira Nihongo — "Sumi & Urushi" Editorial Design System
   5-Token Palette: Urushi Red, Sumi Ink, Washi/Obsidian Canvas, Slate Rule, Aizome Blue
   Typography: IBM Plex Sans (tabular data) + Noto Sans JP (reading) + Klee One (Kana strokes)
   ============================================================================ */

/* ==================== 1. ROOT COLOR SCHEME & MODERN TOKENS ==================== */
:root {
  color-scheme: dark;

  /* Tier 1: Literal Sumi & Urushi Palette */
  --su-urushi-light: #7a131e;
  --su-urushi-dark: #991b1b;
  --su-urushi-hover-light: #5f0e17;
  --su-urushi-hover-dark: #b91c1c;

  --su-aizome-light: #1d3e8a;
  --su-aizome-dark: #60a5fa;
  --su-aizome-hover-light: #162f6b;
  --su-aizome-hover-dark: #3b82f6;

  --su-canvas-light: #f3f4f6;
  --su-canvas-dark: #0b0e14;
  --su-surface-light: #ffffff;
  --su-surface-dark: #131720;
  --su-well-light: #f8f9fb;
  --su-well-dark: #0e121a;
  --su-rule-light: #d8dee6;
  --su-rule-dark: #232a38;

  --su-ink-light: #10131a;
  --su-ink-dark: #f4f5f7;
  --su-muted-light: #4b5563;
  --su-muted-dark: #9ca3af;
  --su-faint-light: #6b7280;
  --su-faint-dark: #6b7280;

  /* Typography */
  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-japanese: 'Noto Sans JP', 'Hiragino Sans', 'Yu Gothic', Meiryo, sans-serif;

  /* Semantic tokens (Dark default) */
  --bg-primary: var(--su-canvas-dark);
  --bg-secondary: var(--su-well-dark);
  --bg-card: var(--su-surface-dark);
  --bg-card-hover: #191f2c;
  --bg-input: #0d1118;
  --border-subtle: var(--su-rule-dark);
  --border-focus: var(--su-aizome-dark);
  --border-accent: var(--su-urushi-dark);

  --text-main: var(--su-ink-dark);
  --text-muted: var(--su-muted-dark);
  --text-faint: var(--su-faint-dark);

  --accent-red: var(--su-urushi-dark);
  --accent-red-hover: var(--su-urushi-hover-dark);
  --accent-indigo: #2563eb;
  --accent-indigo-hover: #1d4ed8;
  --ruby-color: #f87171;
  --kanji-color: var(--su-ink-dark);

  /* Native browser UI theming */
  accent-color: var(--su-urushi-dark);
  --su-scroll-thumb: #3b4458;
  --su-scroll-track: #0e121a;
  scrollbar-color: var(--su-scroll-thumb) var(--su-scroll-track);
}

html[data-theme="light"] {
  color-scheme: light;
  accent-color: var(--su-urushi-light);
  --su-scroll-thumb: #94a3b8;
  --su-scroll-track: #edf0f4;
  scrollbar-color: var(--su-scroll-thumb) var(--su-scroll-track);
}

body.light-theme {
  color-scheme: light;
  --bg-primary: var(--su-canvas-light);
  --bg-secondary: var(--su-well-light);
  --bg-card: var(--su-surface-light);
  --bg-card-hover: #f3f5f9;
  --bg-input: #ffffff;
  --bg-accent-soft: rgba(29, 62, 138, 0.07);

  --border-subtle: var(--su-rule-light);
  --border-focus: var(--su-aizome-light);
  --border-accent: var(--su-urushi-light);

  --text-main: var(--su-ink-light);
  --text-muted: var(--su-muted-light);
  --text-faint: var(--su-faint-light);

  --accent-red: var(--su-urushi-light);
  --accent-red-hover: var(--su-urushi-hover-light);
  --accent-indigo: var(--su-aizome-light);
  --accent-indigo-hover: var(--su-aizome-hover-light);
  --ruby-color: #991b1b;
  --kanji-color: var(--su-ink-light);

  --shadow-sm: 0 1px 2px rgba(16, 19, 26, 0.05);
  --shadow-md: 0 3px 10px rgba(16, 19, 26, 0.06);
  --shadow-lg: 0 10px 24px rgba(16, 19, 26, 0.08);
}

@supports not (scrollbar-color: auto) {
  html::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  html::-webkit-scrollbar-thumb {
    background: var(--su-scroll-thumb);
  }
  html::-webkit-scrollbar-track {
    background: var(--su-scroll-track);
  }
}

/* ==================== 2. TYPOGRAPHIC DISCIPLINE ==================== */
body {
  font-family: var(--font-sans);
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

h1, h2, h3,
.hero-title,
.card-title,
.leaderboard-table th {
  text-wrap: balance;
}

p,
.hero-desc,
.card-desc,
.ai-bullet-text {
  text-wrap: pretty;
}

.hero-desc,
.card-desc {
  max-width: 65ch;
}

/* Tabular numerals for scores, timers, XP, streak, and rankings */
.pill-val,
.stat-number,
.sc-lesson-percent,
.sc-lesson-count,
.lb-rank-cell,
.leaderboard-table td,
.q-timer-sec,
.badge-coverage-summary {
  font-variant-numeric: tabular-nums;
}

/* Eliminate ALL-CAPS eyebrow shoutiness — quiet, refined sentence-case markers */
.subheading-tag {
  text-transform: none;
  letter-spacing: 0.01em;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-red);
}

body.dark-theme .subheading-tag {
  color: #fca5a5;
}

.config-label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
}

/* ==================== 3. URUSHI HEADER & KANJI HANKO NAV ==================== */
.app-header {
  background: linear-gradient(90deg, #4b0c14 0%, #31080f 30%, #151a26 70%, #0e121b 100%);
  border-top: 3px solid #991b1b;
  border-bottom: 1px solid rgba(153, 27, 27, 0.35);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.28);
}

body.light-theme .app-header {
  background: linear-gradient(90deg, #68101b 0%, #480b14 34%, #1a2030 74%, #111520 100%);
  border-top: 3px solid #991b1b;
  border-bottom: 1px solid rgba(16, 19, 26, 0.18);
  box-shadow: 0 2px 10px rgba(16, 19, 26, 0.12);
}

/* Japanese Kanji Hanko markers on Navigation Tabs */
.nav-tab-btn {
  min-block-size: 44px;
  gap: 0.5rem;
}

.nav-tab-btn .tab-kanji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: 1.5rem;
  min-block-size: 1.5rem;
  padding: 0 0.2rem;
  border-radius: 5px;
  font-family: var(--font-japanese);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  background: rgba(148, 163, 184, 0.14);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

body.light-theme .nav-tab-btn .tab-kanji {
  background: #f3f4f6;
  color: #374151;
  border-color: #d8dee6;
}

.nav-tab-btn.active .tab-kanji {
  background: #991b1b;
  color: #ffffff;
  border-color: #b91c1c;
}

body.light-theme .nav-tab-btn.active .tab-kanji {
  background: #7a131e;
  color: #ffffff;
  border-color: #7a131e;
}

/* ==================== 4. LEFT-ALIGNED EDITORIAL WORKBENCH ==================== */
.app-main {
  max-width: 1160px;
}

.drill-hero-card {
  max-width: 880px;
  margin: 1rem auto 2rem;
  text-align: start;
  padding: 1.75rem 2rem;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  border-top: 3px solid var(--accent-red);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

body.dark-theme .drill-hero-card {
  background: linear-gradient(180deg, #1b0d13 0%, #131720 26%, #11151e 100%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.hero-heading-block {
  padding-bottom: 1.15rem;
  margin-bottom: 1.35rem;
  border-bottom: 1px solid var(--border-subtle);
}

.drill-hero-card .hero-title {
  font-size: clamp(1.35rem, 1.1rem + 1vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
  color: var(--text-main);
}

.drill-hero-card .hero-desc {
  margin: 0;
  font-size: 0.94rem;
  line-height: 1.55;
  color: var(--text-muted);
}

/* Crisp, restrained cards — remove noisy hover-lift on static cards */
.card {
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

.weak-item-card:hover {
  transform: none;
  border-color: var(--accent-red);
}

/* Perbaiki Skor Saya Hero — Clean surface with Dark Red top accent border & crisp ink (no red fill) */
.weakness-hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-top: 3px solid var(--accent-red);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

body.dark-theme .weakness-hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-top: 3px solid var(--accent-red);
  box-shadow: var(--shadow-sm);
}

.weakness-hero-card .subheading-tag {
  color: var(--accent-red);
}

body.dark-theme .weakness-hero-card .subheading-tag {
  color: #fca5a5;
}

.weakness-hero-card .badge-accent {
  background: rgba(153, 27, 27, 0.16);
  color: #fca5a5;
  border: 1px solid rgba(248, 113, 113, 0.32);
}

body.light-theme .weakness-hero-card .badge-accent {
  background: #fef2f2;
  color: #7a131e;
  border-color: #fecaca;
}

.weakness-hero-card .card-title,
.weakness-hero-card .card-desc strong,
.weakness-hero-card .weak-stat-card .stat-number {
  color: var(--text-main);
}

.weakness-hero-card .card-desc,
.weakness-hero-card .weak-stat-card .stat-label {
  color: var(--text-muted);
}

.weakness-hero-card .weak-stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
}

.weakness-hero-card .btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
}

.weakness-hero-card .btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-red);
}

/* Restraint on primary CTA button */
.hero-primary-action .btn-primary,
.btn-start-cta {
  border-radius: 10px;
  letter-spacing: 0.04em;
  text-transform: none;
  font-size: 1.05rem;
  padding: 0.85rem 1.75rem;
  min-block-size: 48px;
  background: linear-gradient(135deg, #8b1523 0%, #6d101b 100%);
  box-shadow: 0 3px 12px rgba(122, 19, 30, 0.28);
}

.hero-primary-action .btn-primary:hover,
.btn-start-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(122, 19, 30, 0.36);
}

/* ==================== 5. ACCESSIBILITY, FOCUS & MOTION ==================== */
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {
  .app-header,
  .card,
  .nav-tab-btn.active,
  .btn-start-cta {
    border: 1px solid CanvasText;
  }
  .nav-tab-btn.active {
    outline: 2px solid Highlight;
  }
}

/* ==================== 6. MOBILE ERGONOMICS (<= 640px) ==================== */
@media (max-width: 640px) {
  .drill-hero-card {
    margin: 0.5rem auto 1.25rem;
    padding: 1.1rem 1rem;
  }
  .nav-tab-btn .tab-kanji {
    min-inline-size: 1.35rem;
    min-block-size: 1.35rem;
    font-size: 0.75rem;
  }
}
