/* 谜宴：主题变量按剧本切换（ink 水墨 / ward 病院）。 */
:root {
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --sans: -apple-system, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
body[data-theme="ink"] {
  --paper: #E8ECE5;
  --raise: #F5F7F3;
  --ink: #1F2623;
  --ink-2: #4A5650;
  --ink-3: #7D8983;
  --line: #CAD6CE;
  --accent: #6E8F82;
  --accent-ink: #3F5F53;
  --mark: #A33A2E;
  --dm: #2E3F38;
  --dm-paper: #DDE5DF;
}
body[data-theme="ward"] {
  --paper: #D9DED8;
  --raise: #EEF1EC;
  --ink: #15191A;
  --ink-2: #3E4746;
  --ink-3: #6C7775;
  --line: #B7C2BD;
  --accent: #4E6E6A;
  --accent-ink: #2F4A47;
  --mark: #8E1F1F;
  --dm: #1E2A2A;
  --dm-paper: #C9D2CD;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
#app { height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- 基础控件 ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--raise); color: var(--ink);
  padding: .62em 1.15em; border-radius: 10px; cursor: pointer; font-size: 16px; line-height: 1.3;
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: var(--raise); border-color: var(--ink); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: .38em .8em; font-size: 14px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--raise); border-radius: 10px;
  padding: .65em .8em; font-size: 16px; outline: none;
}
.input:focus { border-color: var(--accent); }
.muted { color: var(--ink-3); }
.small { font-size: 14px; }
.mark-dot { display: inline-block; width: .5em; height: .5em; background: var(--mark); vertical-align: .18em; }
.row { display: flex; gap: .6em; align-items: center; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

#toasts { position: fixed; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%); z-index: 90; width: min(92vw, 420px); display: grid; gap: 8px; }
.toast { background: var(--ink); color: var(--raise); padding: .6em .9em; border-radius: 10px; font-size: 15px; box-shadow: 0 6px 24px rgba(20, 30, 25, .25); }
.toast.bad { background: var(--mark); }

/* ---------- 门 ---------- */
.gate { min-height: 100dvh; display: grid; place-items: end start; padding: 0; position: relative; overflow: hidden; background: #141917; }
.gate .veil { position: absolute; inset: 0; }
.gate .veil img { width: 100%; height: 100%; object-fit: cover; }
.gate .veil::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 35%, rgba(16, 20, 18, .88) 72%); }
.gate .btn.primary { background: var(--raise); color: var(--ink); border-color: var(--raise); margin-top: 6px; }
.gate form { position: relative; padding: 28px 24px calc(36px + var(--safe-b)); width: min(100%, 520px); color: var(--raise); }
.gate h1 { font: 600 44px/1.1 var(--serif); letter-spacing: .12em; margin: 0 0 .25em; }
.gate p { margin: 0 0 1.4em; color: #dfe6e1; }
.gate .input { background: rgba(245, 247, 243, .92); color: var(--ink); border-color: transparent; }
.gate label { display: block; margin-bottom: .8em; }
.gate label span { display: block; font-size: 14px; margin-bottom: .3em; color: #cfd9d3; }

/* ---------- 首页 ---------- */
.home { max-width: 1100px; margin: 0 auto; padding: calc(18px + var(--safe-t)) 18px calc(40px + var(--safe-b)); }
.home header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; }
.home header h1 { font: 600 28px/1.2 var(--serif); letter-spacing: .14em; margin: 0; }
.home h2 { font: 600 19px/1.3 var(--serif); margin: 28px 0 12px; }
.posters { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.poster { position: relative; border-radius: 6px; overflow: hidden; background: var(--ink); cursor: pointer; aspect-ratio: 3 / 4; border: 0; padding: 0; text-align: left; color: var(--raise); }
.poster img { width: 100%; height: 100%; object-fit: cover; }
.poster .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 48px 16px 14px; background: linear-gradient(transparent, rgba(15, 20, 18, .85)); }
.poster .cap b { display: block; font: 600 26px/1.2 var(--serif); letter-spacing: .1em; }
.poster .cap span { font-size: 14px; color: #d8e0db; }
.joinbar { display: flex; gap: 10px; }
.joinbar .input { max-width: 200px; letter-spacing: .2em; text-transform: lowercase; }
.roomlist { display: grid; gap: 10px; }
.roomitem { display: flex; gap: 12px; align-items: center; padding: 10px; background: var(--raise); border-radius: 10px; border: 1px solid var(--line); cursor: pointer; }
.roomitem img { width: 46px; height: 62px; object-fit: cover; border-radius: 3px; }

/* ---------- 房间：大厅（开局前） ---------- */
.lobby { min-height: 100%; }
.hero { position: relative; min-height: 62vh; background: var(--ink); color: var(--raise); display: flex; align-items: flex-end; overflow: hidden; }
.hero > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 30%; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(15, 20, 18, .15) 30%, rgba(15, 20, 18, .82)); }
.hero .t { position: relative; z-index: 1; padding: 20px 20px 22px; width: 100%; max-width: 1100px; margin: 0 auto; }
.hero h1 { font: 600 46px/1.08 var(--serif); letter-spacing: .14em; margin: 0 0 .2em; }
.hero .sub { color: #dbe3de; font-size: 15px; }
.hero .back { position: absolute; z-index: 2; top: calc(12px + var(--safe-t)); left: 12px; }
.hero .back .btn { background: rgba(245, 247, 243, .18); border-color: transparent; color: #fff; backdrop-filter: blur(6px); }
.lobby .body { max-width: 1100px; margin: 0 auto; padding: 18px 18px calc(120px + var(--safe-b)); }
.invite { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; background: var(--raise); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.invite .qr { width: 112px; height: 112px; background: #fff; padding: 6px; border-radius: 6px; }
.invite .qr img { width: 100%; height: 100%; image-rendering: pixelated; }
.invite .code { font: 600 34px/1 var(--serif); letter-spacing: .3em; }
.story { font: 17px/1.95 var(--serif); max-width: 36em; white-space: pre-wrap; }
.roles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.role { position: relative; border-radius: 8px; overflow: hidden; background: var(--raise); border: 2px solid transparent; cursor: pointer; padding: 0; text-align: left; display: flex; flex-direction: column; justify-content: flex-start; }
.role img { width: 100%; aspect-ratio: 1080 / 1528; object-fit: cover; }
.role .meta { padding: 8px 10px 10px; }
.role .meta b { font: 600 18px/1.3 var(--serif); display: block; }
.role .meta span { font-size: 13px; color: var(--ink-3); display: block; }
.role .who { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; justify-content: space-between; }
.role .who em { font-style: normal; background: rgba(31, 38, 35, .82); color: #fff; font-size: 13px; padding: 2px 8px; border-radius: 999px; }
.role.mine { border-color: var(--mark); }
.role.taken:not(.mine) img { filter: grayscale(.7) brightness(.85); }
.dock { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + var(--safe-b)); background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--line); z-index: 20; }
.dock .inner { max-width: 1100px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.players { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--raise); border: 1px solid var(--line); font-size: 14px; }
.chip .on { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.chip .on.yes { background: var(--accent); }

/* ---------- 房间：游戏中 ---------- */
.game { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.topbar { padding: calc(10px + var(--safe-t)) 16px 10px; border-bottom: 1px solid var(--line); background: var(--paper); position: relative; z-index: 5; }
.topbar .line1 { display: flex; align-items: center; gap: 10px; }
.topbar h2 { font: 600 20px/1.25 var(--serif); margin: 0; letter-spacing: .04em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer { font-variant-numeric: tabular-nums; font-size: 15px; color: var(--ink-2); }
.timer.over { color: var(--mark); }
.topbar .line2 { font-size: 14px; color: var(--ink-3); margin-top: 2px; display: flex; gap: 12px; flex-wrap: wrap; }
.dm-busy { display: inline-flex; align-items: center; gap: 6px; color: var(--accent-ink); }
.dm-busy i { width: 6px; height: 6px; background: var(--accent); display: inline-block; animation: pulse 1.2s infinite ease-in-out; }
@keyframes pulse { 50% { opacity: .2; } }
.main { overflow-y: auto; -webkit-overflow-scrolling: touch; position: relative; }
.pane { max-width: 760px; margin: 0 auto; padding: 16px 16px 28px; }
.bottom { border-top: 1px solid var(--line); background: var(--paper); padding-bottom: var(--safe-b); }
.action { padding: 10px 16px 0; max-width: 760px; margin: 0 auto; }
.action:empty { display: none; }
.action .btn { width: 100%; }
.action .note { font-size: 13px; color: var(--ink-3); text-align: center; margin-top: 4px; }
.action.compact .note { display: none; }
.action.compact .btn { padding: .45em 1em; font-size: 15px; }
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); max-width: 760px; margin: 0 auto; }
.tabs button { background: none; border: 0; padding: 10px 0 9px; font-size: 15px; color: var(--ink-3); position: relative; cursor: pointer; }
.tabs button.on { color: var(--ink); font-weight: 600; }
.tabs button.on::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 2px; background: var(--ink); }
.tabs button .dot { position: absolute; top: 9px; right: calc(50% - 22px); width: 7px; height: 7px; background: var(--mark); }

/* 剧本阅读 */
.reader { font: 18px/1.95 var(--serif); }
.reader .acthead { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 26px 0 10px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.reader .acthead:first-child { margin-top: 4px; }
.reader .acthead h3 { font: 600 24px/1.3 var(--serif); margin: 0; letter-spacing: .12em; }
.reader p { margin: 0 0 .85em; text-indent: 2em; }
.reader p.dialog { text-indent: 0; }
.reader p.dialog.me { background: var(--dm-paper); margin-left: -8px; margin-right: -8px; padding: 2px 8px; border-radius: 4px; }
.reader h4 { font: 600 19px/1.4 var(--serif); margin: 1.4em 0 .5em; letter-spacing: .08em; }
.reader .tasks { border-left: 3px solid var(--mark); padding: .2em 0 .2em .9em; margin: 1.2em 0; }
.reader .tasks p { text-indent: 0; margin: .2em 0; }
.reader .locked { text-align: center; color: var(--ink-3); font-size: 15px; padding: 26px 0 8px; font-family: var(--sans); }
.pages img { width: 100%; margin: 0 0 12px; border: 1px solid var(--line); background: #fff; }
.who-switch { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px; }

/* 搜证桌面 */
.board-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.board-head h3 { font: 600 20px/1.3 var(--serif); margin: 0; }
.turn { font-size: 15px; }
.turn.me { color: var(--mark); font-weight: 600; }
.locs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px 10px; }
.loc { background: none; border: 0; padding: 0; cursor: pointer; text-align: center; color: inherit; width: 100%; display: block; }
.loc .stack { position: relative; aspect-ratio: 463 / 700; width: 100%; }
.loc .stack img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 6px; box-shadow: 0 1px 0 rgba(0, 0, 0, .08); }
.loc .stack img.under { transform: translate(4px, 4px) rotate(2deg); filter: brightness(.9); }
.loc .stack .n { position: absolute; right: -6px; top: -6px; min-width: 24px; height: 24px; border-radius: 12px; background: var(--ink); color: var(--raise); font-size: 13px; display: grid; place-items: center; z-index: 2; padding: 0 6px; }
.loc.empty .stack img { opacity: .3; filter: grayscale(1); }
.loc .name { font-size: 14px; margin-top: 6px; display: block; }
.loc.self .name::after { content: "（自己）"; color: var(--ink-3); }
.sheet-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; margin-top: 10px; }
.flipbar { position: sticky; bottom: calc(-18px - var(--safe-b)); background: var(--paper); padding: 12px 0 calc(6px + var(--safe-b)); margin-top: 10px; }
.flipbar:empty { display: none; }
.card { perspective: 900px; background: none; border: 0; padding: 0; cursor: pointer; aspect-ratio: 463 / 700; position: relative; width: 100%; display: block; }
.card .face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 6px; overflow: hidden; transition: transform .7s cubic-bezier(.2, .7, .2, 1); }
.card .face img { width: 100%; height: 100%; object-fit: cover; }
.card .front { transform: rotateY(180deg); }
.card.flipped .back { transform: rotateY(-180deg); }
.card.flipped .front { transform: rotateY(0); }
.card.taken { opacity: .25; pointer-events: none; }
.card .lock { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 26, 24, .55); color: #fff; font-size: 14px; border-radius: 6px; padding: 8px; text-align: center; }

/* 线索 */
.section-title { font: 600 18px/1.3 var(--serif); margin: 22px 0 10px; display: flex; align-items: baseline; justify-content: space-between; }
.section-title:first-child { margin-top: 2px; }
.clues { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px 12px; }
.clue { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; color: inherit; width: 100%; display: block; }
.clue img { width: 100%; aspect-ratio: 1080 / 1528; object-fit: cover; border-radius: 6px; background: var(--raise); }
.clue .cap { font-size: 14px; margin-top: 5px; line-height: 1.35; }
.clue .tag { font-size: 12px; color: var(--ink-3); }
.clue .tag.hid { color: var(--mark); }
.clue.pending img { outline: 2px solid var(--mark); outline-offset: 2px; }
.handout-list { display: grid; gap: 8px; }
.handout-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 10px; background: var(--raise); border: 1px solid var(--line); cursor: pointer; text-align: left; width: 100%; }
.handout-item b { font: 600 17px/1.3 var(--serif); }

/* 消息流 */
.stream { display: grid; gap: 10px; }
.msg { max-width: 92%; }
.msg .who { font-size: 13px; color: var(--ink-3); margin: 0 0 2px 2px; }
.msg .bubble { background: var(--raise); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; white-space: pre-wrap; word-break: break-word; }
.msg.mine { justify-self: end; }
.msg.mine .bubble { background: var(--ink); color: var(--raise); border-color: var(--ink); }
.msg.dm { max-width: 100%; }
.msg.dm .bubble { background: var(--dm-paper); border-color: transparent; font: 17px/1.85 var(--serif); }
.msg.dm .bubble strong { font-weight: 700; color: var(--ink); }
.msg.dm.private .bubble { border-left: 3px solid var(--mark); }
.msg.ask .bubble::before { content: "问主持人 "; color: var(--accent-ink); font-size: 13px; }
.msg.mine.ask .bubble::before { color: #b9d0c6; }
.evt { font-size: 13px; color: var(--ink-3); text-align: center; padding: 0 10px; }
.evt.phase { color: var(--ink-2); font: 600 15px/1.4 var(--serif); letter-spacing: .1em; margin: 6px 0; }
.evt.priv { color: var(--mark); }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 16px 0; max-width: 760px; margin: 0 auto; }
.composer textarea { resize: none; min-height: 44px; max-height: 120px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-2); user-select: none; cursor: pointer; white-space: nowrap; }
.toggle input { accent-color: var(--accent); width: 18px; height: 18px; }
.empty { text-align: center; color: var(--ink-3); padding: 40px 10px; font-size: 15px; }

/* 人物 */
.cast { display: grid; gap: 10px; }
.castrow { display: flex; gap: 12px; align-items: center; padding: 8px; background: var(--raise); border-radius: 10px; border: 1px solid var(--line); }
.castrow img { width: 54px; height: 76px; object-fit: cover; border-radius: 4px; }
.castrow b { font: 600 18px/1.3 var(--serif); }
.castrow .ctr { margin-left: auto; text-align: right; font-size: 14px; }
.castrow .ctr strong { font-size: 22px; font-family: var(--serif); }
.flow { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; }
.flow li { padding: 7px 10px; border-radius: 8px; font-size: 15px; display: flex; gap: 10px; align-items: center; color: var(--ink-3); }
.flow li.done { color: var(--ink-2); }
.flow li.cur { background: var(--raise); color: var(--ink); font-weight: 600; }
.flow li .ix { width: 1.6em; text-align: right; font-variant-numeric: tabular-nums; }
.hostbox { margin-top: 18px; padding: 14px; border: 1px dashed var(--line); border-radius: 12px; display: grid; gap: 10px; }
.hostbox .row { flex-wrap: wrap; }

/* 浮层 */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(18, 24, 21, .55); display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--paper); width: min(100%, 760px); max-height: 92vh; max-height: 92dvh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); animation: rise .24s cubic-bezier(.2, .7, .2, 1); }
@keyframes rise { from { transform: translateY(30px); opacity: .4; } }
.sheet h3 { font: 600 22px/1.3 var(--serif); margin: 0 0 6px; }
.sheet .close { float: right; }
.options { display: grid; gap: 10px; margin-top: 14px; }
.option { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--raise); cursor: pointer; text-align: left; width: 100%; }
.option img { width: 42px; height: 58px; object-fit: cover; border-radius: 4px; }
.option b { font: 600 18px/1.3 var(--serif); }
.option.picked { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.tally { display: grid; gap: 6px; margin-top: 10px; }
.tally .bar { display: grid; grid-template-columns: 7em 1fr 2.5em; gap: 8px; align-items: center; font-size: 15px; }
.tally .bar i { display: block; height: 10px; background: var(--accent); border-radius: 2px; }
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(12, 16, 14, .94); display: flex; flex-direction: column; }
.lightbox .scroll { flex: 1; overflow: auto; display: grid; place-items: center; padding: 12px; touch-action: pinch-zoom pan-x pan-y; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .bar { padding: 12px 16px calc(14px + var(--safe-b)); color: #e3e9e5; display: grid; gap: 10px; }
.lightbox .bar .txt { font: 16px/1.8 var(--serif); white-space: pre-wrap; max-height: 30vh; overflow: auto; }
.handout-view { font: 18px/1.95 var(--serif); white-space: pre-wrap; }
.audio-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 14px; }
.audio-row audio { flex: 1; height: 36px; }

@media (min-width: 900px) {
  .hero { min-height: 70vh; }
  .hero h1 { font-size: 64px; }
  .pane { padding-top: 22px; }
}
