:root {
  color-scheme: dark;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --bg: #071117;
  --panel: #10212b;
  --panel-2: #162d39;
  --panel-3: #1d3946;
  --line: #365361;
  --line-soft: rgba(151, 192, 207, .18);
  --ink: #f0eee5;
  --muted: #a9bac1;
  --gold: #d7ae62;
  --gold-soft: #ffe0a0;
  --cyan: #8ed8d3;
  --danger: #dc786d;
  --safe: #91cf9d;
  --shadow: rgba(0, 0, 0, .38);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; min-height: 100vh; background: radial-gradient(circle at 50% -20%, #173747 0, #08151c 42%, #050b0f 100%); color: var(--ink); }
button, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 2px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

#app { width: min(1500px, 100%); min-height: 100vh; margin: 0 auto; padding: 16px 18px calc(20px + var(--safe-bottom)); }

.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 12px; }
.eyebrow { margin: 0 0 5px; color: var(--gold); font: 800 10px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .16em; }
h1, h2 { margin: 0; font-family: Georgia, "Noto Serif TC", serif; }
h1 { font-size: clamp(22px, 3vw, 36px); letter-spacing: .04em; }
h2 { font-size: clamp(20px, 2.2vw, 28px); }
.top-status { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.build-badge, .status-badge { padding: 7px 10px; border: 1px solid var(--line); background: rgba(15, 35, 45, .82); color: var(--muted); font: 700 10px ui-monospace, monospace; letter-spacing: .06em; box-shadow: 3px 3px 0 var(--shadow); }
.build-badge { border-color: #8a6a36; color: var(--gold-soft); }
.icon-button { width: 34px; height: 32px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; box-shadow: 3px 3px 0 var(--shadow); }
.icon-button:hover { border-color: var(--gold); color: var(--gold-soft); }

.train-stage { position: relative; min-height: 445px; overflow: hidden; border: 2px solid #4c6875; background: linear-gradient(180deg, #1d3947 0, #142934 48%, #0b181f 100%); box-shadow: 8px 8px 0 rgba(0,0,0,.42); }
.train-stage::before, .train-stage::after { content: ""; position: absolute; z-index: 2; top: 0; bottom: 0; width: 28px; background: repeating-linear-gradient(90deg, #283c45 0 6px, #1b2d35 6px 10px); box-shadow: inset 0 0 0 2px rgba(255,255,255,.04); }
.train-stage::before { left: 0; }
.train-stage::after { right: 0; }
.window-view { position: absolute; z-index: 0; left: 28px; right: 28px; top: 0; height: 190px; overflow: hidden; background: linear-gradient(180deg, #071827 0, #123245 54%, #5b5e54 100%); border-bottom: 5px solid #253d48; }
.window-view::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 0 45%, rgba(255,255,255,.05) 48%, transparent 52% 100%); animation: reflection 7s linear infinite; }
@keyframes reflection { from { transform: translateX(-75%); } to { transform: translateX(75%); } }
.moon { position: absolute; width: 52px; height: 52px; border-radius: 50%; top: 25px; right: 13%; background: #e7dfb8; box-shadow: 0 0 34px rgba(242,226,175,.3); }
.horizon { position: absolute; left: -10%; width: 120%; bottom: 0; transform-origin: bottom; }
.horizon-far { height: 82px; opacity: .6; background: repeating-linear-gradient(92deg, transparent 0 35px, #162b31 36px 52px, transparent 53px 84px), linear-gradient(180deg, transparent, #263c3d); animation: landscapeFar 18s linear infinite; }
.horizon-near { height: 58px; opacity: .9; background: repeating-linear-gradient(87deg, #0b191c 0 18px, #173035 18px 28px, #0b191c 28px 60px); animation: landscapeNear 6s linear infinite; }
.track-streaks { position: absolute; inset: auto 0 0; height: 26px; opacity: .45; background: repeating-linear-gradient(90deg, transparent 0 22px, rgba(236,220,166,.42) 23px 26px, transparent 27px 56px); animation: track 1.1s linear infinite; }
@keyframes landscapeFar { to { transform: translateX(-10%); } }
@keyframes landscapeNear { to { transform: translateX(-16%); } }
@keyframes track { to { background-position-x: -56px; } }

.mission-strip { position: relative; z-index: 3; display: grid; grid-template-columns: 118px 110px 120px minmax(220px, 1fr); gap: 5px; padding: 12px 42px 8px; background: linear-gradient(180deg, rgba(5,14,19,.88), rgba(5,14,19,.4)); }
.mission-strip > div { min-width: 0; padding: 8px 10px; border: 1px solid rgba(151,192,207,.28); background: rgba(12,29,38,.72); box-shadow: 3px 3px 0 rgba(0,0,0,.26); }
.mission-strip span { display: block; color: var(--muted); font-size: 9px; letter-spacing: .12em; }
.mission-strip strong { display: block; margin-top: 3px; color: #fff1c9; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mission-objective strong { color: var(--ink); }

.npc-grid { position: relative; z-index: 3; display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 12px; padding: 92px 46px 108px; }
.npc-card { position: relative; min-height: 214px; overflow: hidden; padding: 12px; border: 2px solid #405f6b; background: linear-gradient(165deg, rgba(35,64,76,.97), rgba(14,33,42,.98)); box-shadow: 5px 5px 0 rgba(0,0,0,.34); cursor: pointer; transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.npc-card:hover { transform: translateY(-3px); border-color: #7ca9b5; }
.npc-card.selected { border-color: var(--gold); background: linear-gradient(165deg, rgba(65,68,59,.98), rgba(30,39,42,.98)); box-shadow: 0 0 0 2px rgba(215,174,98,.16), 5px 5px 0 rgba(0,0,0,.34); }
.npc-card.changed { animation: cardPulse .6s steps(3); }
@keyframes cardPulse { 50% { filter: brightness(1.32); transform: translateY(-4px); } }
.npc-top { display: flex; gap: 10px; align-items: center; }
.avatar { position: relative; flex: 0 0 78px; width: 78px; height: 92px; border: 2px solid rgba(255,255,255,.15); background: linear-gradient(180deg, #6c8791 0, #263c45 100%); overflow: hidden; box-shadow: inset 0 -20px 24px rgba(0,0,0,.18); }
.avatar::before { content: ""; position: absolute; width: 42px; height: 44px; left: 18px; top: 12px; border-radius: 44% 44% 46% 46%; background: var(--skin, #cba98a); box-shadow: inset 0 -5px rgba(84,53,42,.15); }
.avatar::after { content: ""; position: absolute; width: 64px; height: 50px; left: 7px; bottom: -8px; border-radius: 34px 34px 6px 6px; background: var(--coat, #23313a); }
.avatar .hair { position: absolute; z-index: 2; width: 45px; height: 22px; top: 8px; left: 16px; border-radius: 45% 50% 25% 20%; background: var(--hair, #2d2624); }
.avatar .face-mark { position: absolute; z-index: 3; left: 27px; top: 34px; width: 24px; height: 3px; border-top: 2px solid rgba(40,31,29,.8); border-bottom: 1px solid rgba(40,31,29,.55); }
.avatar .accessory { position: absolute; z-index: 4; }
.avatar.professor .accessory { left: 18px; top: 32px; width: 43px; height: 13px; border: 2px solid #6e4d2f; border-radius: 7px; box-shadow: inset 20px 0 transparent; }
.avatar.reporter .hair { width: 54px; height: 54px; left: 13px; top: 5px; border-radius: 48% 48% 30% 30%; }
.avatar.reporter .accessory { right: 9px; bottom: 19px; width: 16px; height: 24px; background: #b54d49; transform: rotate(-8deg); box-shadow: inset 0 0 0 2px rgba(255,255,255,.14); }
.avatar.security .accessory { left: 12px; bottom: 15px; width: 54px; height: 14px; border-top: 3px solid #151d21; border-bottom: 3px solid #151d21; }
.avatar.diplomat .accessory { right: 7px; top: 21px; width: 9px; height: 34px; border-right: 3px solid #d9c6a4; transform: rotate(22deg); }
.npc-ident { min-width: 0; }
.npc-ident span { display: block; color: var(--muted); font-size: 10px; }
.npc-ident strong { display: block; margin-top: 2px; font-family: Georgia, "Noto Serif TC", serif; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.npc-mood { display: inline-block; margin-top: 6px; padding: 3px 6px; border: 1px solid rgba(255,255,255,.13); color: #d7e1e1; font-size: 10px; }
.npc-card p { margin: 10px 0 9px; min-height: 42px; color: #d2ddde; font-size: 12px; line-height: 1.5; }
.mini-meter { display: grid; grid-template-columns: 42px 1fr 24px; gap: 5px; align-items: center; margin-top: 5px; color: var(--muted); font-size: 9px; }
.mini-track { height: 6px; background: rgba(255,255,255,.08); overflow: hidden; }
.mini-track i { display: block; width: 0; height: 100%; background: var(--cyan); transition: width .35s ease; }
.mini-track.danger i { background: var(--danger); }
.npc-memory { margin-top: 9px; padding-top: 8px; border-top: 1px dashed rgba(255,255,255,.12); color: #9fb3b8; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.selected-panel { position: absolute; z-index: 4; left: 44px; right: 44px; bottom: 15px; display: grid; grid-template-columns: minmax(170px, .8fr) minmax(240px, 1.5fr) minmax(250px, 1fr); gap: 14px; align-items: center; padding: 10px 12px; border: 1px solid #55727e; background: rgba(7,19,25,.88); box-shadow: 4px 4px 0 rgba(0,0,0,.3); backdrop-filter: blur(5px); }
.selected-title span { display: block; color: var(--gold); font-size: 10px; }
.selected-title strong { display: block; margin-top: 2px; font-size: 17px; }
.selected-panel p { margin: 0; color: #c3d1d4; font-size: 11px; line-height: 1.5; }
.meter-row { display: grid; grid-template-columns: 72px 1fr; gap: 5px 8px; align-items: center; }
.meter-row label { color: var(--muted); font-size: 10px; }
.meter { height: 8px; overflow: hidden; background: rgba(255,255,255,.08); }
.meter i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, #5a9798, var(--cyan)); transition: width .35s ease; }
.meter.danger i { background: linear-gradient(90deg, #8a4743, var(--danger)); }

.play-area { display: grid; grid-template-columns: minmax(270px, 340px) minmax(0, 1fr); gap: 12px; margin-top: 12px; }
.evidence-panel, .dialogue-panel { min-height: 390px; border: 2px solid #385767; background: linear-gradient(180deg, rgba(17,39,50,.98), rgba(8,21,28,.99)); box-shadow: 6px 6px 0 rgba(0,0,0,.36); }
.evidence-panel { padding: 14px; }
.dialogue-panel { display: grid; grid-template-rows: auto minmax(160px, 1fr) auto auto auto; gap: 8px; padding: 14px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.panel-heading h2 { font-size: 21px; }
.quiet-button { padding: 6px 9px; border: 1px solid var(--line); background: #1b3541; color: #c7d6d9; cursor: pointer; font-size: 10px; }
.quiet-button:hover { border-color: var(--gold); }
.evidence-list { display: grid; gap: 7px; margin-top: 12px; }
.evidence-card { position: relative; padding: 9px 10px 9px 34px; border: 1px solid rgba(140,181,195,.25); background: rgba(11,29,37,.76); }
.evidence-card::before { content: attr(data-index); position: absolute; left: 8px; top: 9px; width: 17px; height: 17px; display: grid; place-items: center; border: 1px solid #796035; color: var(--gold-soft); font: 700 9px ui-monospace, monospace; }
.evidence-card strong { display: block; font-size: 11px; color: #f1e8d5; }
.evidence-card p { margin: 3px 0 0; color: #9fb2b7; font-size: 10px; line-height: 1.45; }
.evidence-empty { padding: 22px 12px; border: 1px dashed rgba(255,255,255,.16); color: var(--muted); font-size: 11px; text-align: center; line-height: 1.7; }
.pressure-card { margin-top: 12px; padding: 10px; border: 1px solid rgba(215,174,98,.25); background: rgba(55,47,31,.32); }
.pressure-card > span { font-size: 10px; color: var(--gold); }
.pressure-track { height: 8px; margin-top: 7px; background: rgba(255,255,255,.08); overflow: hidden; }
.pressure-track i { display: block; width: 10%; height: 100%; background: linear-gradient(90deg, #b18a46, #df6f5e); transition: width .4s ease; }
.pressure-card p { margin: 7px 0 0; color: #c5c0b1; font-size: 10px; line-height: 1.45; }

.dialogue-heading #saveStatus { color: var(--cyan); font-size: 10px; }
.message-log { min-height: 0; max-height: 370px; overflow-y: auto; padding: 10px 12px; border: 1px solid #38545f; background: #07161d; scrollbar-color: #52717e #0a1b22; }
.message { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 9px; padding: 7px 0; }
.message + .message { border-top: 1px dashed rgba(255,255,255,.08); }
.message .speaker { padding-top: 2px; color: var(--gold); font: 800 10px ui-monospace, monospace; letter-spacing: .04em; }
.message.player .speaker { color: var(--cyan); }
.message.system .speaker { color: #82969d; }
.message.npc .speaker { color: #f1c886; }
.message p { margin: 0; color: #dde6e5; font-size: 13px; line-height: 1.65; white-space: pre-wrap; }
.message .meta { display: block; margin-top: 4px; color: #7f969d; font-size: 9px; }
.typing-line { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.typing-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--gold); animation: typing 1s infinite alternate; }
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typing { to { opacity: .25; transform: translateY(-2px); } }

.idea-panel { padding: 9px 10px; border: 1px solid #4a6670; background: rgba(25,52,62,.72); }
.idea-title { display: flex; justify-content: space-between; align-items: center; color: var(--gold-soft); font-size: 10px; letter-spacing: .08em; }
.idea-list { display: flex; gap: 7px; overflow-x: auto; margin-top: 7px; padding-bottom: 2px; }
.idea-chip { flex: 0 0 auto; max-width: 360px; padding: 7px 9px; border: 1px solid rgba(151,192,207,.32); background: #122b35; color: #cfdddf; cursor: pointer; font-size: 10px; line-height: 1.45; text-align: left; }
.idea-chip:hover { border-color: var(--gold); color: #fff3d0; }
.text-button { border: 0; padding: 0; background: transparent; color: #b7c6ca; cursor: pointer; text-decoration: underline; font-size: 10px; }
.text-button:hover { color: var(--gold-soft); }
.text-button.accent { color: #f0c677; }

.command-form { display: grid; grid-template-columns: minmax(0, 1fr) 104px; gap: 8px; }
.command-form textarea { width: 100%; min-height: 58px; resize: vertical; border: 2px solid #50707d; border-radius: 0; background: #f0eee5; color: #17272f; padding: 9px 11px; line-height: 1.5; }
.command-form textarea::placeholder { color: #66777c; }
.command-form button, .primary-button { border: 2px solid #b88a40; background: #7d5928; color: #fff1c9; box-shadow: 4px 4px 0 rgba(0,0,0,.35); font-weight: 800; cursor: pointer; }
.command-form button:hover, .primary-button:hover { background: #936b31; }
.command-form button:disabled { opacity: .5; cursor: wait; }
.command-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: #879ca3; font-size: 9px; }
.command-footer > div { display: flex; gap: 11px; }

.overlay-screen, .modal { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(3,10,14,.82); backdrop-filter: blur(6px); }
.start-card, .modal-card { width: min(680px, 100%); max-height: 92vh; overflow-y: auto; padding: 25px; border: 3px solid #4e6a75; background: linear-gradient(145deg, #183641, #0b1d25); box-shadow: 10px 10px 0 rgba(0,0,0,.48); }
.start-card h2, .modal-card h2 { font-size: clamp(27px, 5vw, 44px); }
.start-card > p:not(.eyebrow):not(.fine-print), .modal-card > p { color: #cbd8d9; line-height: 1.75; }
.feature-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin: 18px 0; }
.feature-grid span { padding: 9px; border: 1px solid #4a6670; background: #102833; color: #dce6e5; font-size: 11px; text-align: center; }
.primary-button, .secondary-button { min-height: 44px; padding: 9px 16px; }
.secondary-button { margin-left: 7px; border: 2px solid #4c6873; background: #1c3945; color: #dae5e4; box-shadow: 4px 4px 0 rgba(0,0,0,.35); cursor: pointer; font-weight: 700; }
.fine-print { margin-top: 16px; color: #82979d !important; font-size: 10px; }
.modal-card { position: relative; }
.modal-close { position: absolute; top: 10px; right: 12px; width: 34px; height: 32px; border: 1px solid #4c6873; background: #15313c; cursor: pointer; }
.accuse-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 15px 0; }
.accuse-option { padding: 10px; border: 2px solid #405e69; background: #112a34; cursor: pointer; text-align: left; }
.accuse-option.selected { border-color: var(--gold); background: #393728; }
.accuse-option strong { display: block; font-size: 13px; }
.accuse-option span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.modal-card label { display: block; margin: 10px 0 5px; color: var(--gold-soft); font-size: 11px; }
.modal-card textarea { width: 100%; resize: vertical; border: 2px solid #52707c; background: #f0eee5; color: #17272f; padding: 9px; }
.modal-card .primary-button { margin-top: 12px; }
.ending-card { max-width: 720px; }
.ending-card h3 { color: var(--gold-soft); font-family: Georgia, "Noto Serif TC", serif; font-size: 22px; }
.ending-card p { color: #d3dddd; line-height: 1.75; }
.ending-score { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 14px 0; }
.ending-score div { padding: 9px; border: 1px solid #4c6974; background: #102832; text-align: center; }
.ending-score span { display: block; color: var(--muted); font-size: 9px; }
.ending-score strong { display: block; margin-top: 3px; color: var(--gold-soft); font-size: 17px; }
.toast { position: fixed; z-index: 150; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translate(-50%, 18px); max-width: min(90vw, 460px); padding: 9px 12px; border: 2px solid var(--gold); background: #17313b; color: #ffe6aa; box-shadow: 5px 5px 0 rgba(0,0,0,.4); opacity: 0; pointer-events: none; transition: .2s; font-size: 11px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1050px) {
  .npc-grid { grid-template-columns: repeat(2, minmax(190px, 1fr)); padding-top: 84px; padding-bottom: 122px; }
  .train-stage { min-height: 690px; }
  .selected-panel { grid-template-columns: 1fr 1.5fr; }
  .selected-panel .meter-row { grid-column: 1 / -1; }
  .play-area { grid-template-columns: 280px minmax(0, 1fr); }
}

@media (max-width: 760px) {
  #app { padding: 10px 10px calc(14px + var(--safe-bottom)); }
  .topbar { align-items: flex-start; }
  .top-status .status-badge { display: none; }
  h1 { font-size: 21px; }
  .build-badge { font-size: 8px; }
  .train-stage { min-height: 710px; }
  .mission-strip { grid-template-columns: repeat(3, 1fr); padding: 9px 36px 7px; }
  .mission-objective { grid-column: 1 / -1; }
  .npc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; padding: 100px 36px 150px; }
  .npc-card { min-height: 210px; padding: 9px; }
  .npc-top { gap: 7px; }
  .avatar { flex-basis: 58px; width: 58px; height: 74px; }
  .avatar::before { width: 34px; height: 36px; left: 12px; top: 10px; }
  .avatar::after { width: 50px; height: 42px; left: 4px; }
  .avatar .hair { width: 37px; left: 10px; }
  .avatar .face-mark { left: 18px; width: 22px; top: 29px; }
  .avatar.professor .accessory { left: 10px; top: 27px; width: 38px; }
  .avatar.reporter .hair { width: 43px; height: 48px; left: 8px; }
  .npc-ident strong { font-size: 16px; }
  .npc-card p { font-size: 10px; }
  .selected-panel { left: 35px; right: 35px; bottom: 9px; grid-template-columns: 1fr; gap: 5px; padding: 8px; }
  .selected-panel p { display: none; }
  .meter-row { grid-template-columns: 60px 1fr; }
  .play-area { grid-template-columns: 1fr; }
  .evidence-panel { min-height: auto; }
  .evidence-list { grid-template-columns: repeat(2, 1fr); }
  .dialogue-panel { min-height: 560px; }
  .message-log { max-height: 320px; }
  .command-form { grid-template-columns: 1fr; }
  .command-form button { min-height: 42px; }
  .command-footer { align-items: flex-start; flex-direction: column; }
  .accuse-options { grid-template-columns: 1fr; }
}

@media (max-width: 440px) {
  .topbar .eyebrow { max-width: 240px; }
  .mission-strip { padding-left: 33px; padding-right: 33px; }
  .mission-strip > div { padding: 6px; }
  .mission-strip strong { font-size: 11px; }
  .npc-grid { padding-left: 33px; padding-right: 33px; gap: 5px; }
  .npc-card { min-height: 197px; }
  .npc-card p { min-height: 45px; }
  .mini-meter { grid-template-columns: 34px 1fr 20px; }
  .evidence-list { grid-template-columns: 1fr; }
  .idea-chip { max-width: 280px; }
  .start-card, .modal-card { padding: 19px; }
}
