/* ============================================================
   GLOBAL DESIGN SYSTEM  —  styles.css
   Single entry point imported by all pages.
   
   STRUCTURE:
   1.  Fonts
   2.  Design Tokens  (Light theme defaults)
   3.  Dark theme overrides  (media + data-theme)
   4.  Responsive token scaling  (height breakpoints)
   5.  Base / Reset
   6.  Core Components
       a. .app-shell  (universal page wrapper)
       b. .theme-switch  (theme toggle buttons)
       c. .btn  (button system)
       d. .form-input  (text/password inputs)
       e. .card  (surface cards)
       f. .modal-overlay  (dialog backdrops)
       g. .status  (status messages)
       h. .is-hidden  (visibility utility)
   7.  Page-specific styles
       @import  login/styles.css
       @import  kanji/styles.css
       body.page-home  ...
   ============================================================ */

/* ──────────────────────────────────────────────
   1.  FONTS
   ────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+HK:wght@400;500;600;700&family=Noto+Serif+JP:wght@400;500;600;700&family=Kosugi+Maru&display=swap');
@import url('/login/styles.css');
@import url('/kanji/styles.css');
@import url('/vocab/styles.css');
@import url('/listening/styles.css');

/* ──────────────────────────────────────────────
   2.  DESIGN TOKENS  (light theme default & manual)
   ────────────────────────────────────────────── */
:root {
  /* — Base colours (light default & fallback) — */
  --bg-base:    #f6f1e8;   /* page background              */
  --bg-panel:   #fffaf1;   /* card / panel fill            */
  --text-main:  #1f1d19;   /* primary text                 */
  --text-muted: #6c6559;   /* secondary / placeholder text */
  --border:     #dfd3c1;   /* dividers, input borders      */

  /* Accent colours — unchanged across themes */
  --accent-green:  #567a4f;
  --accent-orange: #cf6f47;
  --accent-blue:   #4a6d8f;

  /* — Typography — */
  --font-body:  "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-title: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-zh-hk: "Noto Serif HK", "PingFang TC", "Heiti TC", serif;

  /* — Spacing scale — */
  --page-pad-y:    22px;
  --page-pad-x:    18px;
  --section-gap:   16px;
  --card-pad-y:    20px;
  --card-pad-x:    18px;
  --control-pad-y: 11px;
  --control-pad-x: 12px;
  --btn-pad-y:     11px;
  --btn-pad-x:     14px;

  /* — Radius — */
  --radius-sm:  8px;
  --radius-md:  14px;
  --radius-lg:  20px;
  --radius-pill: 999px;

  /* — Shadows — */
  --shadow-card:   0 4px 12px rgba(31,29,25,0.06);
  --shadow-modal:  0 20px 40px rgba(20,20,19,0.12), 0 8px 16px rgba(20,20,19,0.04);
  --shadow-focus:  0 0 0 3px rgba(74,109,143,0.22);

  /* — Transitions — */
  --transition-color:  background 0.3s ease, color 0.3s ease;
  --transition-ui:     all 0.2s cubic-bezier(0.2,0.8,0.2,1);
  --transition-lift:   all 0.25s cubic-bezier(0.2,0.8,0.2,1);

  /* — Page-specific helpers (home) — */
  --home-title-size:      clamp(1.7rem, 4.8vw, 2.55rem);
  --home-subtitle-size:   0.96rem;
  --home-feature-min-h:   148px;
  --home-feature-lines:   3;
}

/* ──────────────────────────────────────────────
   3.  LIGHT / DARK THEME OVERRIDES
   ────────────────────────────────────────────── */
html[data-theme="light"] {
  --bg-base:    #f6f1e8;
  --bg-panel:   #fffaf1;
  --text-main:  #1f1d19;
  --text-muted: #6c6559;
  --border:     #dfd3c1;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg-base:    #141413;
  --bg-panel:   #1f1d19;
  --text-main:  #faf9f5;
  --text-muted: #959388;
  --border:     #3a3834;
  color-scheme: dark;
}

html[data-theme-mode="system"] {
  --bg-base:    #f6f1e8;
  --bg-panel:   #fffaf1;
  --text-main:  #1f1d19;
  --text-muted: #6c6559;
  --border:     #dfd3c1;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  html[data-theme-mode="system"] {
    --bg-base:    #141413;
    --bg-panel:   #1f1d19;
    --text-main:  #faf9f5;
    --text-muted: #959388;
    --border:     #3a3834;
    color-scheme: dark;
  }
}

/* ──────────────────────────────────────────────
   4.  RESPONSIVE TOKEN SCALING
       Height breakpoints — compact all inter-element
       gaps proportionally so the layout never needs
       to scroll on small-screen devices.
   ────────────────────────────────────────────── */
@media (max-height: 900px) {
  :root {
    --page-pad-y:          18px;
    --section-gap:         12px;
    --card-pad-y:          14px;
    --home-feature-min-h:  138px;
    --home-feature-lines:  2;
  }
}

@media (max-height: 760px) {
  :root {
    --page-pad-y:          14px;
    --page-pad-x:          14px;
    --section-gap:         10px;
    --card-pad-y:          12px;
    --card-pad-x:          12px;
    --control-pad-y:       9px;
    --btn-pad-y:           9px;
    --home-subtitle-size:  0.9rem;
    --home-feature-min-h:  116px;
    --home-feature-lines:  1;
  }
}

@media (max-height: 680px) {
  :root {
    --page-pad-y:          10px;
    --section-gap:         8px;
    --btn-pad-y:           8px;
    --home-title-size:     clamp(1.35rem, 4.4vw, 2rem);
    --home-feature-min-h:  96px;
  }
}

/* Width breakpoint — tighten horizontal breathing room on phones */
@media (max-width: 700px) {
  :root {
    --page-pad-x: 13px;
    --card-pad-x: 12px;
  }
}

/* ──────────────────────────────────────────────
   5.  BASE / RESET
   ────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

/* All pages use a full-viewport, no-scroll container */
body.page-home,
body.page-login,
body.page-kanji,
body.page-vocab,
body.page-kanji-today,
body.page-listening {
  margin: 0;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-main);
  transition: var(--transition-color);
}

/* ──────────────────────────────────────────────
   6a.  CORE COMPONENT — .app-shell
        Universal centred column that every page
        drops its content into.
   ────────────────────────────────────────────── */
.app-shell {
  width: min(var(--shell-max-w, 980px), 100%);
  height: 100%;
  min-height: 0;
  margin: 0 auto;
  padding: var(--page-pad-y) var(--page-pad-x);
  display: flex;
  flex-direction: column;
}

/* ──────────────────────────────────────────────
   6b.  CORE COMPONENT — .theme-switch
        Lives inside the top banner.
   ────────────────────────────────────────────── */
.top-banner {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.banner-home {
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 3px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.banner-home:hover {
  background: var(--border);
  color: var(--text-main);
}

.banner-home svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  display: block;
}

.theme-switch {
  display: flex;
  gap: 2px;
  align-items: center;
  z-index: 10;
}

.theme-user {
  margin-left: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-username {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.theme-logout {
  border-radius: var(--radius-pill);
  padding: 4px 9px;
  font-size: 0.76rem;
}


.theme-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 3px;
  cursor: pointer;
  line-height: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.theme-btn:hover {
  background: var(--border);
}

.theme-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  display: block;
}

.theme-btn.is-active {
  color: var(--text-main);
}

/* ──────────────────────────────────────────────
   6c.  CORE COMPONENT — .btn
   ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: var(--btn-pad-y) var(--btn-pad-x);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition-ui);
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.06);
  box-shadow: 0 4px 14px rgba(0,0,0,0.13);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Variants */
.btn-primary   { background: var(--accent-green);  color: #fff; }
.btn-secondary { background: var(--accent-orange); color: #fff; }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-panel);
}

/* Size modifier */
.btn-sm, .btn-small {
  border-radius: var(--radius-md);
  padding: 4px 11px;
  font-size: 0.82rem;
  font-weight: 500;
}

/* Full-width helper */
.btn-block { width: 100%; }

/* ──────────────────────────────────────────────
   6d.  CORE COMPONENT — .form-input
   ────────────────────────────────────────────── */
.form-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  padding: var(--control-pad-y) var(--control-pad-x);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.form-input:focus-visible {
  outline: none;
  border-color: var(--accent-blue);
}

/* Remove browser autofill yellow wash */
.form-input:-webkit-autofill,
.form-input:-webkit-autofill:hover,
.form-input:-webkit-autofill:focus,
.form-input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-panel) inset !important;
  -webkit-text-fill-color: var(--text-main) !important;
  transition: background-color 5000s ease-in-out 0s;
  font-family: var(--font-body) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
}

/* Password eye button — used inside .form-password-wrap */
.form-password-wrap {
  position: relative;
}

.form-input-password {
  padding-right: 44px;
}

.form-eye-btn {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: background 0.15s ease;
}

.form-eye-btn:hover {
  background: var(--border);
}

.form-eye-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ──────────────────────────────────────────────
   6e.  CORE COMPONENT — .card
   ────────────────────────────────────────────── */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--card-pad-y) var(--card-pad-x);
  box-shadow: var(--shadow-card);
}

/* ──────────────────────────────────────────────
   6f.  CORE COMPONENT — .modal-overlay
   ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,20,19,0.28);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}

.modal-overlay.is-hidden {
  display: none;
}

/* ──────────────────────────────────────────────
   6g.  CORE COMPONENT — .status
   ────────────────────────────────────────────── */
.status {
  margin: 0;
  min-height: 1.3em;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.status:empty {
  visibility: hidden;
}

/* ──────────────────────────────────────────────
   6h.  UTILITY — .is-hidden
   ────────────────────────────────────────────── */
.is-hidden {
  display: none !important;
}



/* ╔══════════════════════════════════════════════╗
   ║   body.page-home  —  HOME PAGE LAYOUT        ║
   ╚══════════════════════════════════════════════╝ */

body.page-home .app-shell {
  --shell-max-w: 980px;
  gap: var(--section-gap);
  align-items: center;
  padding-bottom: calc(var(--page-pad-y) + 4px);
}

/* Hero */
body.page-home .hero {
  min-height: 0;
  text-align: center;
}

body.page-home .eyebrow {
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-size: 0.74rem;
}

body.page-home .hero h1 {
  margin: 16px 0 20px;
  font-family: var(--font-title);
  font-size: var(--home-title-size);
  line-height: 1.08;
}

@media (max-width: 700px) {
  body.page-home .hero h1 {
    margin: 12px 0 16px;
  }
}

body.page-home .subtitle {
  margin: 0 auto;
  color: var(--text-muted);
  max-width: 58ch;
  line-height: 1.45;
  font-size: var(--home-subtitle-size);
}

/* Auth / dashboard sections */
body.page-home .auth-gate,
body.page-home .dashboard {
  min-height: 0;
  overflow: auto;
  margin: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

body.page-home .auth-gate {
  justify-content: center;
}

/* Auth card on home page */
body.page-home .auth-card {
  width: min(460px, 100%);
  text-align: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: calc(var(--card-pad-y) + 24px) calc(var(--card-pad-x) + 8px) calc(var(--card-pad-y) + 16px);
  box-shadow: var(--shadow-card);
}

body.page-home .auth-card h2 {
  margin: 0 0 12px;
  font-family: var(--font-title);
  font-size: 1.25rem;
  font-weight: 700;
}

body.page-home .auth-form {
  display: grid;
  gap: 12px;
}

body.page-home .field {
  display: grid;
  gap: 6px;
}

body.page-home .field span {
  font-size: 0.88rem;
  color: var(--text-muted);
}

body.page-home #homeStatus {
  margin: 0;
  width: 100%;
  max-width: 980px;
  text-align: right;
}

/* Text link button */
body.page-home .text-btn {
  margin-top: 10px;
  border: none;
  padding: 0;
  background: transparent;
  color: var(--text-muted);
  text-decoration: underline;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Dashboard layout */
body.page-home .dashboard {
  gap: 10px;
  padding: 12px var(--page-pad-x) 24px;
}

/* Feature grid */
body.page-home .feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  flex-shrink: 0;
  width: 100%;
  max-width: 980px;
  justify-content: center;
}

@media (max-width: 860px) {
  body.page-home .feature-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  body.page-home .feature-grid {
    gap: 8px;
  }
}

@media (max-width: 560px) {
  body.page-home .feature-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

body.page-home .feature {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  padding: calc(var(--card-pad-y) + 4px) var(--card-pad-x);
  text-decoration: none;
  color: inherit;
  min-height: var(--home-feature-min-h);
  box-shadow: var(--shadow-card);
  transition: var(--transition-lift);
}

body.page-home .feature h3 {
  margin: 0;
  font-family: var(--font-title);
  font-size: 1rem;
  line-height: 1.2;
}

@media (max-width: 420px) {
  body.page-home .feature h3 { font-size: 0.92rem; }
  body.page-home .feature p  { font-size: 0.8rem; }
}

body.page-home .feature p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--home-feature-lines);
  line-clamp: var(--home-feature-lines);
  flex: 1;
}

body.page-home .feature .feature-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

body.page-home .feature .module-go {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent-orange) 84%, var(--bg-panel) 16%);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-ui);
}

body.page-home .feature .module-go svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

body.page-home .feature .module-go-btn {
  border: none;
  font: inherit;
  padding: 0;
  cursor: pointer;
}

body.page-home .feature .module-go:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

body.page-home .feature:hover:not(.feature-disabled) .module-go {
  filter: brightness(1.06);
  transform: translateX(2px);
}

body.page-home .feature-vocab .vocab-label {
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

body.page-home .feature-vocab .vocab-select {
  margin-top: 6px;
  min-height: 38px;
}

body.page-home .feature:hover:not(.feature-disabled) {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(118, 88, 52, 0.16);
  border-color: color-mix(in srgb, var(--accent-orange) 72%, var(--border) 28%);
}

body.page-home .feature-disabled {
  opacity: 0.72;
}
