:root {
  --paper: #f3eee4;
  --paper-deep: #e5d8c2;
  --card: #fffdf8;
  --ink: #1c1915;
  --ink-soft: #3f382f;
  --muted: #5c5348;
  --cinnabar: #7a261f;
  --lake: #143648;
  --lake-mid: #1c4f68;
  --gold: #8a6230;
  --line: #ddcfb8;
  --ok: #0f5c38;
  --ok-bg: #e5f4eb;
  --bad: #7a261f;
  --bad-bg: #fdecea;
  --note: #f8f1dc;
  --seal: #9a3b2f;
  --shadow: 0 8px 24px rgba(20, 54, 72, 0.08);
  --radius: 1rem;
  --font-sans: "PingFang TC", "Noto Sans CJK TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", "Source Han Sans TC", sans-serif;
  --font-serif: "Songti TC", "PMingLiU", "Noto Serif CJK TC", "Source Han Serif TC", "Noto Serif TC", serif;
  --fs: 1.05rem;
}

html[data-font="md"] { --fs: 1rem; }
html[data-font="lg"] { --fs: 1.1rem; }
html[data-font="xl"] { --fs: 1.22rem; }
html[data-font="xxl"] { --fs: 1.35rem; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--fs);
  line-height: 1.7;
  color: var(--ink);
  background:
    radial-gradient(ellipse at top, rgba(28, 79, 104, 0.06), transparent 50%),
    linear-gradient(180deg, #efe6d6 0%, var(--paper) 40%, #ebe4d6 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  z-index: 0;
}

a { color: var(--lake-mid); }
button, input, select, textarea { font: inherit; }
button {
  cursor: pointer;
  border-radius: 0.75rem;
  border: 2px solid var(--lake);
  background: var(--card);
  color: var(--lake);
  padding: 0.55rem 1rem;
  min-height: 48px;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}
button:hover:not(:disabled) { background: #e8f1f5; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}
button.primary {
  background: var(--lake);
  color: #fff;
  border-color: var(--lake);
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--lake-mid); }
button.ghost {
  background: transparent;
  border-color: rgba(255,255,255,0.55);
  color: #fff;
  min-height: 40px;
  padding: 0.35rem 0.8rem;
}
button.ghost:hover { background: rgba(255,255,255,0.12); }
button.seal {
  background: var(--cinnabar);
  border-color: var(--cinnabar);
  color: #fff;
}
button.seal:hover:not(:disabled) { filter: brightness(1.05); }

#app { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  background: linear-gradient(135deg, var(--lake) 0%, #0f2c3a 55%, var(--lake-mid) 100%);
  color: #f4efe6;
  padding: 0.7rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--gold);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
}
.brand { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.brand-mark {
  width: 2.4rem; height: 2.4rem; border-radius: 0.55rem;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(215,181,106,0.45);
  display: grid; place-items: center;
  font-family: var(--font-serif);
  color: var(--gold);
  font-weight: 700;
  flex: none;
}
.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.12em;
  font-family: var(--font-serif);
  font-weight: 700;
}
.brand small { display: block; opacity: 0.8; letter-spacing: 0.06em; font-size: 0.75rem; margin-top: 0.1rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.toolbar label { font-size: 0.85rem; opacity: 0.9; }
.toolbar select {
  border-radius: 0.55rem;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.2);
  color: #fff;
  padding: 0.35rem 0.5rem;
  min-height: 40px;
}
.toolbar .tog {
  min-height: 40px;
  padding: 0.35rem 0.7rem;
  border-radius: 0.55rem;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.15);
  color: #fff;
}
.toolbar .tog[aria-pressed="true"] {
  background: var(--gold);
  border-color: var(--gold);
  color: #1c1915;
  font-weight: 600;
}

.nav {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  padding: 0.55rem 0.75rem;
  background: rgba(20,54,72,0.06);
  border-bottom: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}
.nav button {
  flex: none;
  border-color: transparent;
  background: transparent;
  color: var(--ink-soft);
  min-height: 44px;
  border-radius: 999px;
  padding: 0.4rem 0.95rem;
}
.nav button[aria-current="page"] {
  background: var(--lake);
  color: #fff;
  border-color: var(--lake);
  font-weight: 600;
}

main.wrap {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
  flex: 1;
}

.hero {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 0.25rem);
  padding: 1.25rem 1.2rem 1.4rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "逍遙";
  position: absolute;
  right: -0.2rem;
  bottom: -0.6rem;
  font-family: var(--font-serif);
  font-size: 5rem;
  color: rgba(20,54,72,0.06);
  letter-spacing: 0.2em;
  pointer-events: none;
}
.hero .seal-tag {
  display: inline-block;
  background: var(--cinnabar);
  color: #fff;
  font-size: 0.78rem;
  letter-spacing: 0.15em;
  padding: 0.2rem 0.55rem;
  border-radius: 0.3rem;
  margin-bottom: 0.6rem;
}
.hero h2 {
  margin: 0 0 0.4rem;
  font-family: var(--font-serif);
  font-size: 1.65rem;
  letter-spacing: 0.08em;
  color: var(--lake);
}
.hero p { margin: 0.35rem 0; color: var(--ink-soft); }
.scope-box {
  margin-top: 0.9rem;
  padding: 0.7rem 0.85rem;
  background: var(--note);
  border-left: 4px solid var(--gold);
  border-radius: 0.5rem;
  font-size: 0.95em;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.card-link {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  color: var(--ink);
  box-shadow: var(--shadow);
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.card-link:hover { border-color: var(--lake-mid); background: #f7fbfc; }
.card-link b {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  color: var(--lake);
  letter-spacing: 0.06em;
}
.card-link span { color: var(--muted); font-size: 0.92em; line-height: 1.5; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.panel h2, .panel h3 {
  font-family: var(--font-serif);
  color: var(--lake);
  letter-spacing: 0.06em;
  margin: 0 0 0.6rem;
}
.panel h2 { font-size: 1.35rem; border-left: 0.35rem solid var(--gold); padding-left: 0.55rem; }
.muted { color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.5rem 0; }

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  background: var(--paper-deep);
  padding: 0.25rem;
  border-radius: 999px;
}
.seg button {
  border: none;
  background: transparent;
  min-height: 40px;
  border-radius: 999px;
  color: var(--ink-soft);
  padding: 0.35rem 0.85rem;
}
.seg button[aria-pressed="true"] {
  background: var(--lake);
  color: #fff;
  font-weight: 600;
}

.classical {
  font-family: var(--font-serif);
  font-size: 1.2em;
  line-height: 2;
  letter-spacing: 0.04em;
}
.gloss-word {
  color: var(--lake-mid);
  border-bottom: 2px dotted var(--gold);
  cursor: pointer;
  background: transparent;
  border-top: none;
  border-left: none;
  border-right: none;
  border-radius: 0;
  padding: 0 0.05em;
  min-height: 0;
  font: inherit;
  font-family: var(--font-serif);
}
.gloss-word:hover, .gloss-word.active {
  background: #fff3cd;
  color: var(--cinnabar);
}

.gloss-pop {
  margin-top: 0.75rem;
  padding: 0.75rem 0.9rem;
  background: var(--note);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
}
.gloss-pop strong { color: var(--cinnabar); font-size: 1.15em; }
.gloss-pop .rd { color: var(--muted); font-size: 0.9em; margin-left: 0.4rem; }

.trans-block {
  background: #fffbe8;
  border-left: 4px solid var(--gold);
  padding: 0.75rem 0.9rem;
  border-radius: 0.5rem;
  line-height: 1.85;
}
.note-list { margin: 0; padding-left: 1.2rem; }
.note-list li { margin: 0.35rem 0; }
.note-list b { color: var(--lake); }

/* games */
.mgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 0.9rem;
}
.mgrid h4 { margin: 0; text-align: center; color: var(--muted); font-weight: 600; font-size: 0.95rem; }
.mbtn {
  width: 100%;
  text-align: left;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0.55rem 0.7rem;
  min-height: 56px;
  line-height: 1.45;
}
.mbtn.sel {
  border-color: var(--lake-mid);
  background: #e3f1f7;
  box-shadow: inset 0 0 0 2px var(--lake-mid);
}
.mbtn.done {
  background: var(--ok-bg);
  border-color: var(--ok);
  color: var(--ok);
  opacity: 0.8;
  cursor: default;
}
.mbtn.shake { animation: sh 0.35s; border-color: var(--bad); background: var(--bad-bg); }
@keyframes sh {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.order-list { display: grid; gap: 0.45rem; }
.order-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.5rem;
  align-items: center;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.45rem 0.55rem;
}
.order-item .idx {
  width: 1.8rem; height: 1.8rem; border-radius: 50%;
  background: var(--paper-deep); display: grid; place-items: center;
  font-weight: 700; color: var(--lake);
}
.order-item .moves { display: flex; gap: 0.25rem; }
.order-item .moves button {
  min-height: 40px;
  padding: 0.25rem 0.55rem;
  border-color: var(--line);
}

.cloze-prompt {
  font-family: var(--font-serif);
  font-size: 1.15em;
  line-height: 1.9;
  margin: 0.5rem 0;
}
.cloze-prompt .blank {
  display: inline-block;
  min-width: 4.5em;
  border-bottom: 2px solid var(--lake);
  color: var(--cinnabar);
  font-weight: 700;
  padding: 0 0.2em;
}
input.txt {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 3px solid var(--lake-mid);
  border-radius: 0.75rem;
  min-height: 56px;
  background: #fff;
  margin: 0.4rem 0;
}

.rush-top {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  text-align: center;
  margin-bottom: 0.6rem;
}
.rush-top small { display: block; color: var(--muted); font-size: 0.8rem; }
.rush-top b { font-size: 1.7rem; color: var(--lake); line-height: 1.2; }
.rush-top b.low { color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }

.opts { display: grid; gap: 0.55rem; margin-top: 0.6rem; }
.opt {
  text-align: left;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0.7rem 0.9rem;
  min-height: 56px;
}
.opt .k {
  display: inline-grid;
  place-items: center;
  width: 1.7rem; height: 1.7rem;
  border-radius: 50%;
  background: var(--paper-deep);
  margin-right: 0.55rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--lake);
}
.opt.ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.opt.bad { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.opt.dim { opacity: 0.55; }

.fb {
  margin-top: 0.8rem;
  padding: 0.75rem 0.95rem;
  border-radius: 0.75rem;
  font-size: 1.02em;
}
.fb.ok { background: var(--ok-bg); color: var(--ok); }
.fb.bad { background: var(--bad-bg); color: var(--bad); }
.fb .note { display: block; color: var(--ink); margin-top: 0.35rem; font-size: 0.95em; }
.fb .cheer { display: block; margin-top: 0.35rem; font-weight: 600; }

.big-score {
  font-size: 3rem;
  font-weight: 700;
  color: var(--lake);
  text-align: center;
  font-family: var(--font-serif);
}
.hintbox {
  margin: 0.5rem 0;
  padding: 0.55rem 0.75rem;
  background: #eef6ff;
  border-left: 4px solid var(--lake-mid);
  border-radius: 0.5rem;
  color: var(--ink-soft);
  font-size: 0.95em;
}
.bar {
  height: 12px;
  background: var(--paper-deep);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.5rem 0;
}
.bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--lake), var(--lake-mid));
  width: 0;
  transition: width 0.3s;
}

.faq-list { display: grid; gap: 0.55rem; }
.faq-item {
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: #fff;
  overflow: hidden;
}
.faq-item button.q {
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 0;
  background: var(--paper);
  color: var(--lake);
  font-weight: 600;
  padding: 0.75rem 0.9rem;
  min-height: 52px;
}
.faq-item .a {
  padding: 0.75rem 0.9rem 1rem;
  border-top: 1px solid var(--line);
  display: none;
}
.faq-item.open .a { display: block; }
.faq-item .plain {
  margin-top: 0.55rem;
  padding: 0.55rem 0.7rem;
  background: #eef6ff;
  border-radius: 0.5rem;
  color: var(--ink-soft);
}
.search {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 2px solid var(--line);
  border-radius: 0.75rem;
  min-height: 48px;
  background: #fff;
  margin-bottom: 0.7rem;
}

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 1rem;
  border-top: 1px solid var(--line);
  background: rgba(255,253,248,0.7);
}

@media (max-width: 640px) {
  .brand h1 { font-size: 1rem; }
  .hero h2 { font-size: 1.35rem; }
  .mgrid { gap: 0.4rem; }
  .classical { font-size: 1.08em; }
  .rush-top b { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
