:root {
  color-scheme: light;
  --ink: #172622;
  --muted: #60706b;
  --paper: #f4f1e8;
  --surface: #fffdf8;
  --surface-2: #e8eee9;
  --forest: #143d34;
  --forest-2: #235e50;
  --gold: #f7c860;
  --gold-dark: #8b6511;
  --danger: #a93838;
  --success: #18734c;
  --border: #ced8d2;
  --shadow: 0 18px 50px rgba(23,38,34,.1);
  --radius: 18px;
  --font: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 95% 0, rgba(247,200,96,.2), transparent 28rem),
    linear-gradient(180deg, #f8f6ef, var(--paper));
  font-family: var(--font);
  line-height: 1.55;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: var(--forest-2); }
:focus-visible { outline: 3px solid #2e7de9; outline-offset: 2px; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 999; background: white; padding: .75rem; }
.skip-link:focus { top: 1rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.danger-text { color: var(--danger); }
.success-text { color: var(--success); }
.small { font-size: .84rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.nowrap { white-space: nowrap; }

.splash, .login-page {
  min-height: 100vh;
  display: grid;
  place-content: center;
  padding: 1.5rem;
  text-align: center;
}
.brand-mark {
  width: 4rem; height: 4rem; margin: 0 auto 1rem;
  display: grid; place-content: center;
  border-radius: 1.2rem;
  background: var(--forest); color: var(--gold);
  font: 800 2.2rem/1 Georgia, serif;
  box-shadow: var(--shadow);
}
.login-card {
  width: min(100%, 430px);
  background: rgba(255,253,248,.92);
  border: 1px solid rgba(20,61,52,.12);
  border-radius: 28px;
  padding: clamp(1.5rem, 5vw, 2.5rem);
  box-shadow: var(--shadow);
  text-align: left;
}
.login-card h1 { margin: 0; font: 700 clamp(1.8rem, 6vw, 2.55rem)/1.1 Georgia, "Noto Serif TC", serif; }
.login-card .eyebrow { margin: 0 0 .45rem; color: var(--gold-dark); font-weight: 800; letter-spacing: .1em; }
.login-card .subtitle { margin: .8rem 0 1.7rem; color: var(--muted); }

.field { display: grid; gap: .42rem; margin: 0 0 1rem; }
.field label, .label { color: #354742; font-weight: 750; font-size: .9rem; }
.field input, .field select, .field textarea, .control {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  padding: .68rem .8rem;
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .control:focus {
  border-color: var(--forest-2);
  box-shadow: 0 0 0 3px rgba(35,94,80,.12);
  outline: 0;
}
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1rem; }
.field-hint { margin: -.15rem 0 0; color: var(--muted); font-size: .8rem; }

.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: .6rem .9rem;
  background: var(--forest);
  color: #fff;
  font-weight: 750;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .52; cursor: not-allowed; }
.btn-secondary { background: white; border-color: var(--border); color: var(--forest); }
.btn-gold { background: var(--gold); color: #362c14; }
.btn-danger { background: white; border-color: #e5baba; color: var(--danger); }
.btn-small { min-height: 34px; padding: .36rem .65rem; font-size: .84rem; }
.btn-block { width: 100%; }
.button-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 245px minmax(0,1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  color: #eff8f3; background: var(--forest);
  padding: 1.2rem .9rem;
  overflow-y: auto;
}
.sidebar-brand { display: flex; gap: .75rem; align-items: center; padding: .25rem .45rem 1.15rem; }
.sidebar-brand .brand-mark { margin: 0; width: 2.7rem; height: 2.7rem; border: 1px solid rgba(255,255,255,.2); box-shadow: none; font-size: 1.35rem; }
.sidebar-brand strong { display: block; font: 700 1.08rem/1.15 Georgia, serif; }
.sidebar-brand span { color: #afd0c5; font-size: .74rem; }
.nav-list { display: grid; gap: .25rem; }
.nav-item {
  width: 100%; border: 0; background: transparent; color: #d5e8e1;
  display: flex; gap: .7rem; align-items: center;
  border-radius: 10px; padding: .65rem .75rem; text-align: left;
}
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.12); color: white; }
.nav-icon { width: 1.4rem; text-align: center; }
.sidebar-user { margin-top: auto; border-top: 1px solid rgba(255,255,255,.16); padding: 1rem .45rem 0; }
.sidebar-user strong, .sidebar-user span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user span { color: #afd0c5; font-size: .78rem; }
.sidebar-user .btn { margin-top: .7rem; border-color: rgba(255,255,255,.25); color: white; background: transparent; width: 100%; }

.workspace { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  min-height: 70px; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .8rem clamp(1rem,4vw,2.2rem);
  background: rgba(248,246,239,.88); backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(20,61,52,.1);
}
.topbar h1 { margin: 0; font: 700 clamp(1.25rem,3vw,1.75rem)/1.15 Georgia, "Noto Serif TC", serif; }
.topbar p { margin: .15rem 0 0; color: var(--muted); font-size: .8rem; }
.menu-toggle { display: none; }
.main-content { width: min(100%, 1500px); margin: 0 auto; padding: clamp(1rem,3vw,2rem); }

.page-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.page-head h2 { margin: 0; font: 700 clamp(1.5rem,4vw,2.15rem)/1.15 Georgia, "Noto Serif TC", serif; }
.page-head p { margin: .35rem 0 0; color: var(--muted); }
.card {
  background: var(--surface); border: 1px solid rgba(20,61,52,.11);
  border-radius: var(--radius); box-shadow: 0 5px 24px rgba(23,38,34,.055);
  padding: clamp(1rem,2.5vw,1.35rem);
}
.grid { display: grid; gap: 1rem; }
.stats-grid { grid-template-columns: repeat(5,minmax(0,1fr)); margin-bottom: 1rem; }
.stat-card { position: relative; overflow: hidden; }
.stat-card::after { content: ""; position: absolute; width: 5rem; height: 5rem; border-radius: 50%; right: -2rem; top: -2.2rem; background: rgba(247,200,96,.22); }
.stat-value { display: block; margin: .25rem 0; font: 700 2rem/1.1 Georgia, serif; color: var(--forest); }
.stat-label { color: var(--muted); font-size: .82rem; font-weight: 700; }
.accent-grid { grid-template-columns: repeat(4,minmax(0,1fr)); }
.accent-card { min-height: 145px; }
.accent-code { display: inline-grid; place-content: center; width: 2.2rem; height: 2.2rem; border-radius: .65rem; background: var(--surface-2); color: var(--forest); font-weight: 900; }
.accent-card h3 { margin: .8rem 0 .25rem; }
.accent-card p { margin: 0; color: var(--muted); font-size: .85rem; }

.toolbar { display: grid; grid-template-columns: minmax(220px,1fr) repeat(3,minmax(120px,.35fr)) auto; gap: .65rem; margin-bottom: 1rem; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 13px; background: white; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .72rem .75rem; border-bottom: 1px solid #e7ece8; text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; background: #eef3ef; color: #3e514b; white-space: nowrap; font-size: .8rem; letter-spacing: .02em; }
tbody tr:hover { background: #fbfaf5; }
tbody tr:last-child td { border-bottom: 0; }
.sort-btn { all: unset; cursor: pointer; font: inherit; }
.english-cell strong { display: block; font-size: 1rem; color: var(--forest); }
.english-cell span { display: block; max-width: 35ch; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  border-radius: 999px; padding: .2rem .5rem;
  background: var(--surface-2); color: #385148; font-size: .74rem; font-weight: 800; white-space: nowrap;
}
.badge-success { background: #dff4e8; color: #155c3c; }
.badge-warning { background: #fff0ca; color: #795408; }
.badge-danger { background: #f9dddd; color: #8f2828; }
.progress-mini { width: 90px; height: 7px; border-radius: 999px; background: #e4e8e5; overflow: hidden; margin-top: .28rem; }
.progress-mini > span { display: block; height: 100%; background: var(--success); }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1rem; }

.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: .25rem; }
.loading { min-height: 220px; display: grid; place-content: center; color: var(--muted); }
.spinner { width: 2rem; height: 2rem; margin: 0 auto .8rem; border: 3px solid #d5ddd8; border-top-color: var(--forest); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.dialog-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 1rem;
  background: rgba(10,25,21,.6); backdrop-filter: blur(4px);
}
.dialog {
  width: min(100%, 760px); max-height: calc(100vh - 2rem); overflow: auto;
  background: var(--surface); border-radius: 20px; box-shadow: 0 24px 80px rgba(0,0,0,.3);
}
.dialog-wide { width: min(100%, 1100px); }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font: 700 1.35rem/1.2 Georgia, serif; }
.dialog-body { padding: 1.2rem; }
.dialog-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.2rem; background: var(--surface); border-top: 1px solid var(--border); }

.readiness { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .75rem; margin: 1rem 0; }
.readiness-item { padding: .85rem; border-radius: 12px; background: var(--surface-2); }
.readiness-item strong { display: block; }
.voice-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .75rem; }
.voice-card { border: 1px solid var(--border); border-radius: 12px; padding: .85rem; background: white; }
.voice-head { display: flex; justify-content: space-between; gap: .5rem; margin-bottom: .65rem; }
.voice-title { display: flex; gap: .55rem; align-items: center; }
.gender-dot { width: .65rem; height: .65rem; border-radius: 50%; background: #9157b5; }
.gender-dot.male { background: #3278b7; }
.voice-card audio { width: 100%; height: 38px; }
.ipa-list { display: grid; gap: .6rem; }
.ipa-row { display: grid; grid-template-columns: 80px minmax(0,1fr) auto; gap: .55rem; align-items: center; }

.study-stage { max-width: 900px; margin: 0 auto; }
.study-card { min-height: 390px; padding: clamp(1.4rem,5vw,3rem); text-align: center; display: flex; flex-direction: column; justify-content: center; }
.study-type { color: var(--gold-dark); font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.study-word { margin: .5rem 0; font: 700 clamp(2rem,8vw,4.5rem)/1.05 Georgia, serif; color: var(--forest); overflow-wrap: anywhere; }
.study-ipa { margin: .1rem 0 1.2rem; color: var(--muted); font-size: 1.08rem; }
.study-meaning { font-size: 1.2rem; }
.study-voices { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: .6rem; margin: 1.4rem 0; }
.voice-play { min-height: 62px; display: grid; gap: .1rem; place-content: center; border: 1px solid var(--border); border-radius: 12px; background: white; color: var(--forest); }
.voice-play span { font-size: .75rem; color: var(--muted); }
.score-row { display: grid; grid-template-columns: repeat(6,1fr); gap: .5rem; margin-top: 1rem; }
.score-btn { border: 1px solid var(--border); background: white; border-radius: 10px; min-height: 48px; font-weight: 850; }
.score-btn:hover { border-color: var(--forest-2); background: var(--surface-2); }

.toast-region { position: fixed; z-index: 999; right: 1rem; bottom: 1rem; width: min(390px,calc(100% - 2rem)); display: grid; gap: .55rem; }
.toast { border-radius: 12px; padding: .85rem 1rem; background: var(--forest); color: white; box-shadow: var(--shadow); animation: enter .18s ease-out; }
.toast.error { background: #822d2d; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }

.mobile-overlay { display: none; }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .accent-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .toolbar { grid-template-columns: 1fr 1fr 1fr; }
  .toolbar .search-control { grid-column: 1 / -1; }
}

@media (max-width: 780px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 60; left: 0; width: min(82vw,290px); transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .app-shell.menu-open .sidebar { transform: translateX(0); }
  .mobile-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.38); }
  .app-shell.menu-open .mobile-overlay { display: block; }
  .menu-toggle { display: inline-flex; }
  .topbar { min-height: 62px; padding: .65rem 1rem; }
  .topbar .topbar-meta { display: none; }
  .main-content { padding: 1rem; }
  .page-head { align-items: start; flex-direction: column; }
  .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar .search-control { grid-column: 1 / -1; }
  .table-wrap table { min-width: 800px; }
  .voice-grid { grid-template-columns: 1fr; }
  .study-voices { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .score-row { grid-template-columns: repeat(3,1fr); }
  .field-row { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 480px) {
  .stats-grid, .accent-grid, .readiness { grid-template-columns: 1fr; }
  .toolbar { display: grid; grid-template-columns: 1fr; }
  .toolbar .search-control { grid-column: auto; }
  .pagination { align-items: stretch; flex-direction: column; }
  .pagination .button-row { justify-content: space-between; }
  .ipa-row { grid-template-columns: 1fr; }
  .dialog-backdrop { padding: 0; align-items: end; }
  .dialog { max-height: 95vh; border-radius: 20px 20px 0 0; }
}

@media print {
  body { background: white; }
  .sidebar, .topbar, .page-head .button-row, .toolbar, .pagination, .no-print, .toast-region { display: none !important; }
  .app-shell { display: block; }
  .main-content { width: 100%; padding: 0; }
  .card, .table-wrap { border: 0; box-shadow: none; }
  .table-wrap { overflow: visible; }
  table { font-size: 9pt; }
  th { position: static; }
  tr { break-inside: avoid; }
  a { color: black; text-decoration: none; }
}

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

