:root {
  --bg: #f5efe4;
  --paper: #fffdf8;
  --ink: #1d2733;
  --ink-2: #4a5563;
  --ink-3: #8a8f98;
  --line: #e4dccd;
  --red: #b3322a;
  --red-soft: #f6e2dd;
  --navy: #22344d;
  --navy-soft: #e3e9f1;
  --gold: #a87b2c;
  --gold-soft: #f4ead3;
  --green: #2f7a52;
  --green-soft: #e0f0e6;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 14px rgba(40, 30, 10, .06);
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", serif;
  --sans: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --tabh: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181f; --paper: #1d232c; --ink: #ece7dd; --ink-2: #b6b0a5; --ink-3: #7d7a74; --line: #2e3540;
    --red: #e0675c; --red-soft: #3a2422; --navy: #9db4d6; --navy-soft: #233142; --gold: #d4a957; --gold-soft: #3a3020;
    --green: #6cc496; --green-soft: #1e3329; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14181f; --paper: #1d232c; --ink: #ece7dd; --ink-2: #b6b0a5; --ink-3: #7d7a74; --line: #2e3540;
  --red: #e0675c; --red-soft: #3a2422; --navy: #9db4d6; --navy-soft: #233142; --gold: #d4a957; --gold-soft: #3a3020;
  --green: #6cc496; --green-soft: #1e3329; color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.6; }
body { min-height: 100dvh; padding-top: var(--safe-t); }
#app { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(var(--tabh) + var(--safe-b) + 24px); }
a { color: inherit; }
button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.35; margin: 0; }
h1 { font-size: 26px; letter-spacing: .02em; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* header */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 18px; }
.top .eyebrow { font-size: 12px; color: var(--red); letter-spacing: .18em; font-weight: 600; }
.back { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; color: var(--ink-2); font-size: 15px; margin-bottom: 8px; padding: 6px 0; }

/* cards */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card.tight { padding: 12px 14px; }
.card h3 { margin-bottom: 6px; }
.seal { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: var(--red); color: #fff; font-family: var(--serif); font-weight: 700; font-size: 17px; flex: none; }
.seal.navy { background: var(--navy); color: var(--paper); }
.seal.gold { background: var(--gold); color: var(--paper); }
.pill { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--navy-soft); color: var(--navy); font-weight: 600; }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }
.pill.green { background: var(--green-soft); color: var(--green); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); font-weight: 600; font-size: 16px; cursor: pointer; text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.navy { background: var(--navy); border-color: var(--navy); color: var(--paper); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.seg { display: flex; background: var(--line); padding: 3px; border-radius: 11px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 4px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
label.field { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; font-weight: 600; }
input, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; }
textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
input:focus, textarea:focus { outline: 2px solid var(--navy); outline-offset: -1px; }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around; background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); height: calc(var(--tabh) + var(--safe-b)); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; text-decoration: none; color: var(--ink-3); font-size: 11px; font-weight: 600; }
.tabs .ti { font-family: var(--serif); font-size: 19px; line-height: 1.1; }
.tabs a.on { color: var(--red); }
.tabs a.tab-main .ti { display: grid; place-items: center; width: 40px; height: 32px; border-radius: 10px; background: var(--red); color: #fff; font-size: 17px; }
.tabs a.tab-main.on .ti { box-shadow: 0 0 0 3px var(--red-soft); }

/* home */
.hero { background: var(--navy); color: #f5efe4; border-radius: 18px; padding: 18px; position: relative; overflow: hidden; }
.hero::after { content: "正"; position: absolute; right: -8px; bottom: -34px; font-family: var(--serif); font-size: 150px; font-weight: 700; opacity: .08; line-height: 1; }
.hero .motion { font-family: var(--serif); font-size: 18px; line-height: 1.5; margin: 6px 0 12px; }
.hero .meta { font-size: 13px; opacity: .8; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.stat b { display: block; font-family: var(--serif); font-size: 26px; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--ink-3); }
.todo { display: flex; gap: 12px; align-items: center; text-decoration: none; }
.todo .grow p { margin: 2px 0 0; font-size: 13px; color: var(--ink-3); }
.chev { color: var(--ink-3); font-size: 20px; }

/* book */
.toc a { display: flex; gap: 12px; align-items: center; text-decoration: none; padding: 13px 0; border-bottom: 1px solid var(--line); }
.toc a:last-child { border-bottom: 0; }
.toc .n { font-family: var(--serif); color: var(--red); font-weight: 700; width: 24px; }
.md h2 { margin: 22px 0 10px; font-size: 19px; padding-left: 10px; border-left: 4px solid var(--red); }
.md h3 { margin: 18px 0 6px; }
.md p { margin: 8px 0; }
.md ul, .md ol { padding-left: 22px; margin: 8px 0; }
.md li { margin: 5px 0; }
.md blockquote { margin: 12px 0; padding: 10px 14px; background: var(--gold-soft); border-radius: 10px; font-family: var(--serif); font-size: 17px; }
.md blockquote p { margin: 4px 0; }
.md strong { color: var(--red); }
.md hr { border: 0; border-top: 1px dashed var(--line); margin: 18px 0; }
.md code { font-family: var(--sans); background: var(--navy-soft); color: var(--navy); padding: 1px 6px; border-radius: 6px; font-size: 14px; }
.md .tbl { overflow-x: auto; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 10px 0; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--navy-soft); }

/* drill hub */
.mode { display: flex; gap: 14px; align-items: flex-start; text-decoration: none; }
.mode p { margin: 3px 0 0; font-size: 14px; color: var(--ink-2); }

/* arena */
.arena { display: flex; flex-direction: column; min-height: calc(100dvh - var(--tabh) - var(--safe-b) - 60px); }
.clocks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; position: sticky; top: calc(var(--safe-t)); z-index: 5; background: var(--bg); padding: 6px 0 10px; }
.clock { border-radius: 14px; padding: 10px 12px; border: 2px solid var(--line); background: var(--paper); transition: border-color .2s, transform .2s; }
.clock .who { font-size: 12px; font-weight: 700; color: var(--ink-3); }
.clock .t { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 32px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.clock.me .t { color: var(--red); }
.clock.ai .t { color: var(--navy); }
.clock.live { border-color: currentColor; transform: scale(1.02); }
.clock.me.live { border-color: var(--red); }
.clock.ai.live { border-color: var(--navy); }
.clock.low .t { animation: blink 1s infinite; }
.clock.out { opacity: .5; }
@keyframes blink { 50% { opacity: .35; } }
.feed { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 6px 0 16px; }
.bubble { max-width: 88%; padding: 10px 13px; border-radius: 14px; font-size: 16px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.bubble.me { align-self: flex-end; background: var(--red-soft); border-bottom-right-radius: 4px; }
.bubble.ai { align-self: flex-start; background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble .tag { display: block; font-size: 11px; font-weight: 700; color: var(--ink-3); margin-bottom: 2px; }
.bubble.sys { align-self: center; background: transparent; color: var(--ink-3); font-size: 13px; text-align: center; }
.dots::after { content: "…"; animation: dots 1s steps(3) infinite; display: inline-block; width: 1.2em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { 0% { width: 0 } 100% { width: 1.2em } }
.dock { position: sticky; bottom: calc(var(--tabh) + var(--safe-b) + 8px); background: var(--bg); padding: 8px 0 4px; }
.mic { width: 100%; min-height: 64px; border-radius: 18px; border: 0; background: var(--red); color: #fff; font-size: 18px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer; }
.mic.rec { background: var(--ink); animation: pulse 1.4s infinite; }
.mic[disabled] { background: var(--ink-3); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(179,50,42,.5); } 70% { box-shadow: 0 0 0 14px rgba(179,50,42,0); } 100% { box-shadow: 0 0 0 0 rgba(179,50,42,0); } }
.dock .sub { display: flex; gap: 8px; margin-top: 8px; }
.dock .sub .btn { flex: 1; }
.typebox { display: flex; gap: 8px; margin-top: 8px; }
.typebox textarea { min-height: 70px; }

/* judge */
.score { display: flex; align-items: center; gap: 16px; }
.score .big { font-family: var(--serif); font-size: 56px; font-weight: 700; color: var(--red); line-height: 1; }
.bars { display: grid; gap: 7px; margin-top: 14px; }
.bar { display: grid; grid-template-columns: 64px 1fr 24px; gap: 8px; align-items: center; font-size: 13px; }
.bar .track { height: 8px; background: var(--line); border-radius: 9px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--navy); border-radius: 9px; }
.quote { font-family: var(--serif); font-size: 17px; padding: 10px 14px; background: var(--gold-soft); border-radius: 10px; }
.cmp { display: grid; gap: 8px; }
.cmp div { padding: 10px 12px; border-radius: 10px; font-size: 15px; }
.cmp .was { background: var(--line); color: var(--ink-2); }
.cmp .now { background: var(--green-soft); }

/* flash */
.flash { min-height: 210px; display: flex; flex-direction: column; justify-content: center; text-align: center; padding: 26px 18px; }
.flash .atk { font-family: var(--serif); font-size: 21px; line-height: 1.55; }
.flash .k { font-size: 12px; color: var(--red); font-weight: 700; letter-spacing: .15em; margin-bottom: 10px; }
.rate { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* cards (上场卡) */
.pcard { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; border-top: 5px solid var(--red); }
.pcard + .pcard { margin-top: 12px; }
.pcard .body { white-space: pre-wrap; font-size: 15px; line-height: 1.65; margin-top: 6px; }
.pcard.navy { border-top-color: var(--navy); }
.pcard.gold { border-top-color: var(--gold); }

/* login */
.login { min-height: 80dvh; display: flex; flex-direction: column; justify-content: center; gap: 18px; }
.login .mark { font-family: var(--serif); font-size: 64px; color: var(--red); line-height: 1; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabh) + var(--safe-b) + 90px); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.empty { text-align: center; color: var(--ink-3); padding: 40px 10px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media print {
  .tabs, .noprint, .toast { display: none !important; }
  body, html { background: #fff; }
  #app { padding: 0; max-width: none; }
  .pcard { break-inside: avoid; box-shadow: none; border: 1px solid #999; border-top: 4px solid #b3322a; margin: 0 0 8mm; font-size: 12pt; }
  .pcard .body { font-size: 12pt; }
}
