/* EnglishTaiwan Classroom design system.
   Teacher UI: neutral, calm, dense enough. Game stage: bold color, huge type, projector contrast.
   Themes: [data-theme=light|dark] on <html>, "system" follows prefers-color-scheme. */

:root {
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 12px; --radius-sm: 8px; --radius-lg: 18px;
  --gap: 16px;
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef0f4; --surface-3: #e2e6ec;
  --text: #15181e; --muted: #5a6270; --faint: #8a92a0; --border: #d9dee6;
  --accent: #2456d6; --accent-ink: #ffffff; --accent-soft: #e6edfd;
  --good: #11804a; --good-soft: #e3f5ea; --bad: #c4302b; --bad-soft: #fde8e7; --warn: #a45b00; --warn-soft: #fff1dc;
  --focus: #ffb703;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .14);
  /* Game palette: saturated, all pass 4.5:1 with white text. */
  --c-sky: #0b6fb8; --c-coral: #c2412d; --c-violet: #6d3fc4; --c-teal: #087a72; --c-indigo: #3b44b8;
  --c-amber: #9a5b00; --c-green: #1d7a3a; --c-slate: #3d4a5c; --c-rose: #b4235a; --c-gold: #8a6500;
  --c-orange: #b44d0b; --c-cyan: #0a6f86; --c-pink: #b0287c; --c-lime: #4f7a0c; --c-purple: #7a2fa8; --c-navy: #233a7a;
  --team-1: #1f6feb; --team-2: #d1382c; --team-3: #1a8a4a; --team-4: #8e44c9; --team-5: #c76a00; --team-6: #0b8a96; --team-7: #c2307e; --team-8: #5b6b0b;
  --stage-bg: #10141c; --stage-surface: #1b2230; --stage-text: #ffffff; --stage-muted: #b9c2d3;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1218; --surface: #171b23; --surface-2: #1f2430; --surface-3: #2a303d;
  --text: #eef1f6; --muted: #a9b1c0; --faint: #7d8696; --border: #2f3644;
  --accent: #7aa2ff; --accent-ink: #0b1020; --accent-soft: #1d2a4a;
  --good: #4cc98a; --good-soft: #14301f; --bad: #ff7a72; --bad-soft: #3a1714; --warn: #ffb35c; --warn-soft: #3a2810;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --surface: #171b23; --surface-2: #1f2430; --surface-3: #2a303d;
    --text: #eef1f6; --muted: #a9b1c0; --faint: #7d8696; --border: #2f3644;
    --accent: #7aa2ff; --accent-ink: #0b1020; --accent-soft: #1d2a4a;
    --good: #4cc98a; --good-soft: #14301f; --bad: #ff7a72; --bad-soft: #3a1714; --warn: #ffb35c; --warn-soft: #3a2810;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 var(--font); background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; }
img { max-width: 100%; }
a { color: var(--accent); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.6rem, 3vw, 2.3rem); letter-spacing: -.02em; }
h2 { font-size: 1.35rem; letter-spacing: -.01em; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip-link:focus { top: 8px; }
[hidden] { display: none !important; }

/* Layout */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 64px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.grid.tight { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.spacer { flex: 1; }

/* Header */
.site-header { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.site-header .wrap { display: flex; align-items: center; gap: 12px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; text-decoration: none; color: var(--text); white-space: nowrap; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: 15px; }
.brand small { font-weight: 500; color: var(--muted); }
.nav { display: flex; gap: 2px; margin-left: 12px; overflow-x: auto; scrollbar-width: none; }
.nav a { padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 550; font-size: .95rem; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.btn.menu-toggle { display: none; }
@media (max-width: 1180px) {
  .nav { display: none; position: absolute; top: 60px; left: 0; right: 0; flex-direction: column; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 16px 16px; margin: 0; box-shadow: var(--shadow-lg); }
  .nav.open { display: flex; }
  .nav a { padding: 12px; }
  .btn.menu-toggle { display: inline-flex; }
  .brand small { display: none; }
}

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; transition: background .12s, border-color .12s, transform .06s; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { min-height: 34px; padding: 5px 11px; font-size: .9rem; border-radius: 8px; }
.btn.big { min-height: 56px; padding: 12px 26px; font-size: 1.15rem; border-radius: 14px; }
.btn.play { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 750; letter-spacing: .04em; }
.btn.icon { padding: 0; width: 42px; }
.btn.icon.small { width: 34px; }
.btn svg { width: 20px; height: 20px; flex: none; }

/* Forms */
label { font-weight: 600; font-size: .92rem; }
.field { display: grid; gap: 6px; }
.field small { color: var(--muted); font-weight: 400; }
.input, input[type=text], input[type=number], input[type=search], input[type=email], input[type=url], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.45; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: transparent; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: 20px; height: 20px; }

/* Chips (finder, filters) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 38px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 550; font-size: .95rem; }
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card h3 { margin-bottom: 4px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px; }
.game-card { display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; padding: 0; }
.game-card .gc-top { display: flex; gap: 12px; align-items: center; padding: 16px 16px 0; }
.game-card .gc-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; color: #fff; flex: none; }
.game-card .gc-icon svg { width: 26px; height: 26px; }
.game-card h3 { margin: 0; font-size: 1.12rem; }
.game-card .gc-body { padding: 0 16px; color: var(--muted); font-size: .94rem; flex: 1; }
.game-card .gc-actions { display: flex; gap: 8px; padding: 0 16px 16px; align-items: center; }
.meta-list { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0; }
.meta-list li { font-size: .8rem; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-weight: 550; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.badge.official { background: var(--accent-soft); color: var(--accent); }
.badge.local { background: var(--warn-soft); color: var(--warn); }
.badge.good { background: var(--good-soft); color: var(--good); }

.hero { padding: 36px 0 20px; }
.hero p.lead { font-size: 1.15rem; color: var(--muted); max-width: 640px; }
.section { margin-top: 36px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }

.finder { display: grid; gap: 16px; }
.finder .q { display: grid; grid-template-columns: 130px 1fr; gap: 12px; align-items: center; }
.finder .q > span { font-weight: 650; color: var(--muted); font-size: .92rem; }
@media (max-width: 640px) { .finder .q { grid-template-columns: 1fr; gap: 6px; } }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); border: 2px dashed var(--border); border-radius: var(--radius); }
.empty h3 { color: var(--text); }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.notice.warn { background: var(--warn-soft); border-color: transparent; color: var(--text); }
.notice.bad { background: var(--bad-soft); border-color: transparent; }
.notice.good { background: var(--good-soft); border-color: transparent; }

/* Tables (deck editor) */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.sheet { border-collapse: collapse; width: 100%; min-width: 760px; }
.sheet th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px; background: var(--surface-2); position: sticky; top: 0; }
.sheet td { border-top: 1px solid var(--border); padding: 2px; vertical-align: top; }
.sheet td input, .sheet td select { border: 1px solid transparent; border-radius: 6px; min-height: 38px; background: transparent; }
.sheet td input:hover { border-color: var(--border); }
.sheet td.num { width: 36px; text-align: right; color: var(--faint); font-size: .8rem; padding: 12px 6px; }
.sheet td.act { width: 44px; }
.sheet tr.dragging { opacity: .4; }

/* Toasts + dialogs */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 200; width: min(520px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); display: flex; gap: 12px; align-items: center; }
.toast button { background: transparent; color: inherit; border: 1px solid currentColor; border-radius: 8px; padding: 4px 10px; cursor: pointer; font-weight: 650; }
dialog { border: none; border-radius: var(--radius-lg); padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); }
dialog::backdrop { background: rgba(10, 14, 22, .55); }
dialog .dlg-head { padding: 18px 20px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
dialog .dlg-body { padding: 14px 20px; display: grid; gap: 14px; }
dialog .dlg-foot { padding: 0 20px 18px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.save-state { font-size: .88rem; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.save-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.save-state[data-state="saved"]::before { background: var(--good); }
.save-state[data-state="saving"]::before { background: var(--warn); }
.save-state[data-state="offline"]::before, .save-state[data-state="error"]::before { background: var(--bad); }

.feedback-fab { position: fixed; right: 16px; bottom: 16px; z-index: 40; border-radius: 999px; box-shadow: var(--shadow); }
.site-footer { border-top: 1px solid var(--border); padding: 24px 0 70px; color: var(--muted); font-size: .9rem; }
.site-footer .wrap { display: flex; gap: 16px; flex-wrap: wrap; justify-content: space-between; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.tag-input { display: flex; gap: 6px; flex-wrap: wrap; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; } }
:root[data-motion="none"] *, :root[data-motion="none"] *::before { animation: none !important; transition: none !important; }
