:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 16px;
  --ink: #171816;
  --ink-soft: #22231f;
  --panel: #292a25;
  --line: #3b3c35;
  --text: #f3f2eb;
  --muted: #aaa99f;
  --paper: #e8e4d8;
  --red: #d95d45;
  --red-dark: #b54734;
  --green: #79aa87;
  --cyan: #70a9ad;
  --warning: #e2b76a;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
}

button, input, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.app-shell { min-height: 100%; display: grid; grid-template-rows: 72px minmax(0, 1fr); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: #1c1d1a;
}

.brand-lockup, .topbar-actions, .connection, .command-button, .rail-heading { display: flex; align-items: center; }
.brand-lockup { gap: 12px; min-width: 0; }
.brand-mark, .dialog-brand {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: var(--red);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.brand-lockup h1 { margin: 0; font-size: 18px; font-weight: 680; }
.brand-lockup p { margin: 2px 0 0; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.brand-lockup p span { color: var(--warning); }
.topbar-actions { gap: 10px; }

.connection {
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  min-width: 94px;
  justify-content: flex-end;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #77776f; }
.connection[data-state="online"] .status-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(121, 170, 135, .12); }
.connection[data-state="busy"] .status-dot { background: var(--warning); }
.connection[data-state="error"] .status-dot { background: var(--red); }

.command-button, .icon-button, .text-button, .send-button, .primary-button {
  border: 0;
  cursor: pointer;
}
.command-button {
  gap: 7px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: 13px;
}
.command-button:hover, .icon-button:hover { border-color: #626359; background: #272823; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); background: transparent; font-size: 19px; }
.text-button { padding: 6px 0; background: transparent; color: var(--muted); font-size: 12px; }
.text-button:hover { color: var(--text); }

.workspace { min-height: 0; display: grid; grid-template-columns: minmax(260px, 330px) minmax(0, 1fr); }
.scene-rail { min-height: 0; overflow-y: auto; border-right: 1px solid var(--line); background: var(--ink-soft); }
.scene-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: #34352e;
  background-image: url("/campus-life.jpg");
  background-position: center;
  background-size: cover;
  border-bottom: 1px solid var(--line);
}
.scene-summary, .decision, .message-preview { padding: 22px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 9px; color: var(--red); font-size: 11px; font-weight: 750; text-transform: uppercase; }
.scene-time { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.scene-summary h2 { margin: 0; font-size: 18px; line-height: 1.45; font-weight: 620; overflow-wrap: anywhere; }
.scene-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 24px; }
.scene-facts span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; }
.scene-facts strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.decision { border-left: 3px solid var(--warning); background: #302d25; }
.decision .eyebrow { color: var(--warning); }
.decision p:last-child { margin: 0; color: #e8ddc7; font-size: 13px; line-height: 1.65; }
.rail-heading { justify-content: space-between; }
.rail-heading span { color: var(--muted); font-size: 11px; }
.message-preview ol { list-style: none; margin: 0; padding: 0; }
.message-preview li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.message-preview li:last-child { border-bottom: 0; }
.message-meta { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 10px; }
.message-preview li p { margin: 6px 0 0; color: #d6d5cc; font-size: 12px; line-height: 1.55; overflow-wrap: anywhere; }

.game-stage { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; background: #1b1c19; }
.conversation-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; padding: 24px clamp(20px, 5vw, 72px) 18px; border-bottom: 1px solid var(--line); }
.conversation-heading h2 { margin: 0; font-size: 22px; font-weight: 590; }
.conversation { overflow-y: auto; padding: 28px clamp(20px, 5vw, 72px) 36px; scroll-behavior: smooth; }
.empty-state { max-width: 560px; margin: 12vh auto 0; text-align: center; color: var(--muted); line-height: 1.8; }
.empty-state strong { display: block; margin-bottom: 8px; color: var(--text); font-size: 19px; font-weight: 580; }
.turn { max-width: 780px; margin: 0 auto 26px; }
.turn-label { margin: 0 0 8px; color: var(--muted); font-size: 10px; font-weight: 720; text-transform: uppercase; }
.turn-content { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.82; }
.turn.user { display: flex; flex-direction: column; align-items: flex-end; }
.turn.user .turn-content { max-width: min(680px, 90%); padding: 12px 15px; border-radius: 6px; background: var(--paper); color: #22231f; line-height: 1.6; }
.turn.assistant .turn-content { color: #e4e3da; }
.turn.assistant[data-streaming="true"] .turn-content::after { content: ""; display: inline-block; width: 7px; height: 14px; margin-left: 4px; background: var(--red); vertical-align: -2px; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.retry-bar { display: flex; justify-content: space-between; gap: 16px; padding: 10px clamp(20px, 5vw, 72px); border-top: 1px solid #594a32; color: #dfca9f; background: #302d25; font-size: 12px; }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) 44px; gap: 10px; margin: 0 clamp(20px, 5vw, 72px) max(18px, env(safe-area-inset-bottom)); padding: 10px 10px 10px 16px; border: 1px solid #4a4b43; border-radius: 8px; background: #242520; }
.composer:focus-within { border-color: var(--cyan); }
.composer textarea { resize: none; min-height: 42px; max-height: 160px; padding: 10px 0; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.5; }
.composer textarea::placeholder { color: #77776f; }
.send-button { width: 44px; height: 44px; align-self: end; border-radius: 6px; background: var(--red); color: white; font-size: 22px; font-weight: 500; }
.send-button:hover { background: var(--red-dark); }
.send-button:disabled, .command-button:disabled { cursor: not-allowed; opacity: .45; }

.access-dialog { width: min(420px, calc(100vw - 32px)); padding: 0; border: 1px solid #4a4b43; border-radius: 8px; background: #242520; color: var(--text); box-shadow: 0 28px 90px rgba(0, 0, 0, .55); }
.access-dialog::backdrop { background: rgba(12, 13, 11, .82); }
.access-dialog form { padding: 28px; }
.dialog-brand { margin-bottom: 28px; }
.access-dialog h2 { margin: 0 0 10px; font-size: 25px; }
.dialog-copy { margin: 0 0 24px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.access-dialog label:not(.remember-row) { display: block; margin-bottom: 8px; font-size: 12px; color: #d2d1c8; }
.access-dialog input[type="password"] { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; background: #191a17; color: var(--text); }
.remember-row { display: flex; gap: 9px; align-items: center; margin: 14px 0 20px; color: var(--muted); font-size: 12px; }
.remember-row input { accent-color: var(--red); }
.primary-button { width: 100%; min-height: 44px; border-radius: 4px; background: var(--red); color: #fff; font-weight: 650; }
.primary-button:hover { background: var(--red-dark); }
.primary-button:disabled { cursor: wait; opacity: .65; }
.form-error { margin: -6px 0 14px; color: #f29684; font-size: 12px; line-height: 1.5; }
.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; }

@media (max-width: 760px) {
  body { overflow: auto; }
  .app-shell { min-height: 100dvh; grid-template-rows: 64px minmax(0, 1fr); }
  .topbar { padding: 0 14px; }
  .brand-lockup p, .connection span:last-child, .command-button span:last-child { display: none; }
  .connection { min-width: auto; }
  .command-button { width: 38px; padding: 0; justify-content: center; font-size: 18px; }
  .workspace { grid-template-columns: 1fr; }
  .scene-rail { display: grid; grid-template-columns: 96px minmax(0, 1fr); min-height: auto; overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); }
  .scene-image { height: 100%; min-height: 112px; aspect-ratio: auto; border-bottom: 0; border-right: 1px solid var(--line); }
  .scene-summary { padding: 14px 16px; border-bottom: 0; }
  .scene-summary h2 { font-size: 14px; }
  .scene-time { font-size: 11px; }
  .scene-facts { margin-top: 10px; }
  .scene-facts span { margin-bottom: 2px; font-size: 9px; }
  .scene-facts strong { font-size: 12px; }
  .decision, .message-preview { grid-column: 1 / -1; padding: 13px 16px; }
  .message-preview { display: none; }
  .game-stage { min-height: 0; height: calc(100dvh - 177px); }
  .conversation-heading { padding: 15px 16px 12px; }
  .conversation-heading h2 { font-size: 17px; }
  .conversation { padding: 20px 16px 26px; }
  .empty-state { margin-top: 8vh; }
  .turn { margin-bottom: 22px; }
  .composer { margin: 0 12px max(12px, env(safe-area-inset-bottom)); }
  .retry-bar { padding: 9px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .conversation { scroll-behavior: auto; }
  .turn.assistant[data-streaming="true"] .turn-content::after { animation: none; }
}
