:root {
  color-scheme: dark;
  --ink: #e8edf2;
  --muted: #8ea0b2;
  --panel: rgba(9, 19, 31, 0.94);
  --line: rgba(180, 203, 221, 0.16);
  --amber: #d8a85d;
  --amber-bright: #f1c77d;
  --violet: #9677dc;
  --danger: #ffb4aa;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", Georgia, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(44, 80, 111, 0.22), transparent 36rem),
    #040a11;
}

html { min-height: 100%; }
button, input { font: inherit; }
button { cursor: pointer; }
button, select, input { min-height: 44px; }

.game-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.story-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: .7rem;
}

.story-picker select {
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--ink);
  background: #0a1521;
  padding: 8px 30px 8px 11px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--amber);
  font-family: system-ui, sans-serif;
  font-size: 0.68rem;
  letter-spacing: 0.28em;
}

h1 {
  margin: 0;
  font-weight: 500;
  font-size: clamp(1.65rem, 4vw, 2.6rem);
  letter-spacing: 0.12em;
}

.title-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.version-badge {
  border: 1px solid rgba(216, 168, 93, .32);
  border-radius: 999px;
  color: var(--amber);
  background: rgba(216, 168, 93, .06);
  padding: 3px 8px;
  font-family: system-ui, sans-serif;
  font-size: .68rem;
  letter-spacing: .08em;
}

.ghost-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  padding: 9px 18px;
}

.ghost-button:hover { color: var(--ink); border-color: var(--amber); }

.scene-panel {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 7;
  min-height: 270px;
  border: 1px solid var(--line);
  border-radius: 4px 4px 0 0;
  background: #07101a;
}

.scene-panel img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 240ms ease;
}

body[data-theme="pc98"] .scene-panel img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

body[data-theme="pc98"] h1,
body[data-theme="pc98"] .conversation-panel {
  font-family: "MS Gothic", "Yu Gothic UI", monospace;
}

.scene-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(3, 8, 14, 0.78), transparent 45%);
  pointer-events: none;
}

.status-strip {
  position: absolute;
  inset: auto 18px 14px;
  display: flex;
  justify-content: space-between;
  color: rgba(255,255,255,.66);
  font-family: system-ui, sans-serif;
  font-size: 0.65rem;
  letter-spacing: 0.18em;
}

.play-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  min-height: 430px;
  border: 1px solid var(--line);
  border-top: 0;
  background: var(--panel);
}

.conversation-panel {
  min-width: 0;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.log {
  min-height: 170px;
  max-height: 340px;
  overflow-y: auto;
  padding-right: 8px;
}

.message {
  max-width: 88%;
  margin: 0 0 18px;
  line-height: 1.85;
}

.message::before {
  display: block;
  margin-bottom: 3px;
  color: var(--amber);
  font-family: system-ui, sans-serif;
  font-size: 0.62rem;
  letter-spacing: .18em;
}

.message.narrator::before { content: "NARRATOR"; }
.message.player {
  margin-left: auto;
  color: #c8d4df;
  text-align: right;
}
.message.player::before { content: "YOU"; color: var(--violet); }

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
  padding-top: 12px;
}

.choices[hidden] {
  display: none;
}

.talk-targets {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.talk-targets[hidden] {
  display: none;
}

.talk-target-button {
  border: 1px solid rgba(150, 119, 220, .42);
  border-radius: 999px;
  color: #d2c5f7;
  background: rgba(150, 119, 220, .08);
  padding: 7px 13px;
  font-family: system-ui, sans-serif;
  font-size: .78rem;
}

.talk-target-button[aria-pressed="true"] {
  border-color: rgba(241, 199, 125, .8);
  color: #1b1308;
  background: var(--amber);
}

.choice-helper {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.choice-helper span {
  color: #617080;
  font-family: system-ui, sans-serif;
  font-size: .68rem;
}

.choice-toggle,
.hint-button {
  border: 0;
  border-bottom: 1px solid rgba(216, 168, 93, .5);
  color: var(--amber);
  background: transparent;
  padding: 5px 2px;
  font-size: .82rem;
}

.choice-toggle:hover,
.hint-button:hover {
  color: var(--amber-bright);
  border-color: var(--amber-bright);
}

.hint-button {
  border: 1px solid rgba(150, 119, 220, .45);
  border-radius: 2px;
  color: #c5b4f2;
  padding: 7px 14px;
  background: rgba(150, 119, 220, .08);
}

.choice-button {
  border: 1px solid rgba(216, 168, 93, .38);
  border-radius: 2px;
  color: var(--amber-bright);
  background: rgba(216, 168, 93, .06);
  padding: 9px 13px;
}

.choice-button:hover { background: rgba(216, 168, 93, .16); }

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .18);
}

.input-row input {
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  padding: 14px;
}

.input-row input::placeholder { color: #617080; }

.input-row button, .error-box button {
  border: 0;
  color: #1b1308;
  background: var(--amber);
  padding: 0 20px;
  font-weight: 700;
}

.input-row button:hover, .error-box button:hover { background: var(--amber-bright); }

.notebook {
  border-left: 1px solid var(--line);
  padding: 24px 20px;
  background: rgba(4, 11, 18, .55);
}

.notebook h2 {
  margin: 0 0 12px;
  color: var(--amber);
  font-family: system-ui, sans-serif;
  font-size: .68rem;
  letter-spacing: .2em;
  text-transform: uppercase;
}

.notebook-section + .notebook-section {
  margin-top: 30px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.notebook ul {
  margin: 0;
  padding-left: 1.15rem;
  color: #b9c5cf;
  line-height: 1.8;
  font-size: .9rem;
}

.empty { color: #5f6d79; list-style: none; margin-left: -1.15rem; }

.ai-note {
  margin: 32px 0 0;
  color: #687887;
  font-family: system-ui, sans-serif;
  font-size: .68rem;
  line-height: 1.6;
}

.error-box {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin: 0 0 16px;
  border: 1px solid rgba(255, 180, 170, .3);
  color: var(--danger);
  background: rgba(114, 36, 31, .18);
  padding: 10px 12px;
  font-family: system-ui, sans-serif;
  font-size: .82rem;
}

.error-box[hidden] { display: none; }
.error-box button { padding: 7px 12px; white-space: nowrap; }
.is-loading { opacity: .55; pointer-events: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

@media (max-width: 1024px) {
  body {
    height: 100dvh;
    overflow: hidden;
  }

  .game-shell {
    width: min(100% - 20px, 1000px);
    height: 100dvh;
    padding: 10px 0 12px;
    display: flex;
    flex-direction: column;
  }

  .topbar {
    flex: 0 0 auto;
    align-items: center;
    gap: 14px;
    margin-bottom: 8px;
  }

  .topbar-actions { gap: 8px; }
  .eyebrow { display: none; }
  h1 { font-size: clamp(1.25rem, 3vw, 1.9rem); }
  .version-badge { font-size: .62rem; padding: 2px 7px; }
  .story-picker select { padding-block: 6px; }
  .ghost-button { padding: 7px 14px; }

  .scene-panel {
    flex: 0 0 clamp(140px, 25dvh, 210px);
    min-height: 0;
    aspect-ratio: auto;
  }

  .status-strip {
    inset: auto 12px 9px;
    font-size: .58rem;
  }

  .play-grid {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) 220px;
    overflow: hidden;
  }

  .conversation-panel {
    min-height: 0;
    padding: 14px;
  }

  .log {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }

  .message {
    margin-bottom: 10px;
    line-height: 1.65;
  }

  .choice-helper {
    flex: 0 0 auto;
    margin-top: 10px;
    padding-top: 10px;
    gap: 9px;
  }

  .choice-helper span { display: none; }

  .choices {
    flex: 0 0 auto;
    max-height: 86px;
    overflow-y: auto;
    margin-bottom: 10px;
    padding-top: 8px;
  }

  .choice-button {
    padding: 7px 10px;
    min-height: 38px;
  }

  .talk-targets {
    max-height: 78px;
    overflow-y: auto;
    margin-bottom: 8px;
  }

  .talk-target-button {
    min-height: 38px;
    padding: 6px 11px;
  }

  .input-row {
    flex: 0 0 auto;
  }

  .input-row input {
    padding: 10px 12px;
  }

  .input-row button,
  .error-box button {
    padding-inline: 16px;
  }

  .notebook {
    min-height: 0;
    overflow-y: auto;
    padding: 14px 12px;
  }

  .notebook-section + .notebook-section {
    margin-top: 18px;
    padding-top: 16px;
  }

  .notebook ul {
    line-height: 1.55;
    font-size: .82rem;
  }

  .ai-note { display: none; }
}

@media (max-width: 1180px) and (orientation: landscape) and (max-height: 850px) {
  body {
    height: 100dvh;
    overflow: hidden;
  }

  button, select, input { min-height: 38px; }

  .game-shell {
    width: min(100% - 12px, 1168px);
    height: 100dvh;
    padding: 6px 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(176px, 22vw, 236px);
    grid-template-rows: auto clamp(220px, 42dvh, 330px) minmax(0, 1fr);
    column-gap: 0;
  }

  .topbar {
    grid-column: 1 / -1;
    grid-row: 1;
    align-items: center;
    gap: 10px;
    margin-bottom: 5px;
  }

  .topbar-actions { gap: 6px; }
  .story-picker { font-size: .62rem; }
  .story-picker select { padding: 4px 22px 4px 8px; }
  .ghost-button { padding: 5px 11px; }
  .eyebrow { display: none; }
  h1 { font-size: clamp(1.05rem, 2.2vw, 1.45rem); letter-spacing: .08em; }
  .version-badge { font-size: .58rem; padding: 1px 6px; }

  .scene-panel {
    grid-column: 1;
    grid-row: 2;
    height: 100%;
    min-height: 0;
    aspect-ratio: auto;
    border-radius: 4px 0 0 0;
    background: #030811;
  }

  .scene-panel img {
    object-fit: contain;
  }

  .status-strip {
    inset: auto 10px 7px;
    font-size: .54rem;
  }

  .play-grid {
    display: contents;
  }

  .conversation-panel {
    grid-column: 1;
    grid-row: 3;
    min-height: 0;
    padding: 9px 10px;
    display: grid;
    grid-template-rows: minmax(5.8em, 7.2em) auto auto auto auto;
    overflow: hidden;
    border: 1px solid var(--line);
    border-top: 0;
    border-right: 0;
    background: var(--panel);
  }

  .log {
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    padding-right: 6px;
  }

  .message {
    margin-bottom: 7px;
    line-height: 1.5;
    font-size: .9rem;
  }

  .message::before {
    margin-bottom: 1px;
    font-size: .54rem;
  }

  .error-box {
    margin-bottom: 6px;
    padding: 7px 9px;
    font-size: .76rem;
  }

  .choice-helper {
    margin-top: 6px;
    padding-top: 6px;
    gap: 8px;
  }

  .choice-helper span { display: none; }
  .hint-button { padding: 5px 10px; }
  .choice-toggle { padding: 4px 1px; }

  .choices {
    max-height: 46px;
    overflow-y: auto;
    gap: 6px;
    margin-bottom: 6px;
    padding-top: 6px;
  }

  .choice-button {
    min-height: 34px;
    padding: 5px 9px;
    font-size: .82rem;
  }

  .talk-targets {
    max-height: 40px;
    overflow-y: auto;
    gap: 6px;
    margin-bottom: 6px;
  }

  .talk-target-button {
    min-height: 32px;
    padding: 4px 10px;
    font-size: .74rem;
  }

  .input-row {
    grid-template-columns: 1fr auto;
  }

  .input-row input {
    padding: 7px 10px;
    font-size: .92rem;
  }

  .input-row button,
  .error-box button {
    padding-inline: 13px;
  }

  .notebook {
    grid-column: 2;
    grid-row: 2 / 4;
    min-height: 0;
    overflow-y: auto;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-left: 1px solid var(--line);
    background: rgba(4, 11, 18, .62);
  }

  .notebook h2 {
    margin-bottom: 6px;
    font-size: .58rem;
  }

  .notebook-section + .notebook-section {
    margin-top: 10px;
    padding-top: 9px;
  }

  .notebook ul {
    line-height: 1.42;
    font-size: .76rem;
  }

  .ai-note { display: none; }
}

@media (max-width: 820px) and (min-width: 700px) {
  .game-shell { width: min(100% - 16px, 790px); }
  .topbar { align-items: flex-start; }
  .topbar-actions { flex-direction: column; align-items: stretch; }
  .story-picker { justify-content: space-between; }
  .scene-panel { flex-basis: clamp(120px, 20dvh, 180px); }
  .play-grid { grid-template-columns: minmax(0, 1fr) 185px; }
  .notebook { border-left: 1px solid var(--line); border-top: 0; display: block; }
  .notebook-section + .notebook-section { border-top: 1px solid var(--line); }
  .input-row { grid-template-columns: 1fr auto; }
}

@media (max-width: 699px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .game-shell { width: min(100% - 18px, 680px); padding-top: 16px; }
  .scene-panel { aspect-ratio: 4 / 3; min-height: 0; }
  .play-grid { grid-template-columns: 1fr; }
  .notebook { border-left: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
  .notebook-section + .notebook-section { margin: 0; padding: 0; border: 0; }
  .ai-note { grid-column: 1 / -1; margin-top: 0; }
  .conversation-panel { padding: 18px 15px; }
  .log { max-height: 340px; }
  .input-row { grid-template-columns: 1fr; }
  .input-row button { padding: 12px; }
}

@media (max-width: 600px) {
  .topbar { align-items: flex-start; }
  .topbar-actions { flex-direction: column; align-items: stretch; }
  .story-picker { flex-direction: column; align-items: stretch; gap: 3px; }
  .choice-helper { flex-wrap: wrap; }
  .choice-helper span { width: 100%; }
}
