:root {
  --bg: #1d2230;
  --panel: #f3efe4;
  --ink: #2a2420;
  --line: #2a2420;
  --accent: #2a8a8a;
  --accent-ink: #ffffff;
  --muted: #7a7266;
  --btn: #fffdf7;
  --btn-hover: #e6f1ef;
  --done: #9aa59f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "DotGothic16", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }

#app { max-width: 1240px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px; color: #e9e4d6;
}
#place { font-size: 15px; letter-spacing: .05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbtns { display: flex; gap: 6px; flex-shrink: 0; }
.topbtns button {
  background: transparent; border: 2px solid #e9e4d6; color: #e9e4d6;
  padding: 3px 10px; font-size: 13px;
}
.topbtns button:hover { background: rgba(255,255,255,.12); }

/* スマホ：縦に積む */
#game {
  display: grid; gap: 10px; padding: 0 16px 16px;
  grid-template-columns: 1fr;
  grid-template-areas: "stage" "msg" "cmds";
}
#stage { grid-area: stage; position: relative; border: 3px solid #0d1018; background: #000; line-height: 0; }
#screen { width: 100%; aspect-ratio: 16 / 9; display: block; }
#screen.meiji { filter: sepia(.32) saturate(.72) brightness(.97); }
#screen.taisho { filter: sepia(.22) saturate(.85); }

#msg {
  grid-area: msg; position: relative;
  background: var(--panel); border: 3px solid var(--line);
  box-shadow: inset 0 0 0 3px #d8d1bf;
  padding: 12px 16px 22px; min-height: 128px; cursor: pointer; outline: none;
}
#speaker { font-size: 14px; color: var(--accent); min-height: 1.2em; margin-bottom: 4px; }
#speaker.meiji { color: #7a5838; }
#text { font-size: 18px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
#next { position: absolute; right: 14px; bottom: 6px; font-size: 13px; color: var(--muted); animation: blink 1s steps(2) infinite; visibility: hidden; }
#msg.waiting #next { visibility: visible; }
@keyframes blink { 50% { opacity: 0; } }

#cmds {
  grid-area: cmds; display: grid; gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start;
}
#cmds button {
  background: var(--btn); border: 3px solid var(--line);
  padding: 10px 8px; font-size: 16px; text-align: center; min-height: 48px;
  box-shadow: 3px 3px 0 rgba(0,0,0,.35);
}
#cmds button:hover, #cmds button:focus-visible { background: var(--btn-hover); outline: none; }
#cmds button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(0,0,0,.35); }
#cmds button.main { background: var(--accent); color: var(--accent-ink); }
#cmds button.back { background: #ddd6c6; }
#cmds button.done::after { content: " ✓"; color: var(--accent); }
#cmds button.wide { grid-column: 1 / -1; }
#cmds .label { grid-column: 1 / -1; color: #e9e4d6; font-size: 14px; padding: 2px 2px 0; }

/* PC：左に画面、右にコマンド、下にメッセージ */
@media (min-width: 900px) {
  #game {
    grid-template-columns: minmax(0, 3fr) minmax(220px, 1fr);
    grid-template-areas: "stage cmds" "msg msg";
    gap: 12px;
  }
  #cmds { grid-template-columns: 1fr; }
  #text { font-size: 20px; }
  #msg { min-height: 140px; }
}

/* オーバーレイ */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(13, 16, 24, .82);
}
.hidden { display: none !important; }
#title { background: radial-gradient(ellipse at 50% 40%, #33405a 0%, #1d2230 70%); }
.titlebox { text-align: center; color: #f3efe4; }
.titlebox .sub { color: #9fd6d0; letter-spacing: .2em; font-size: 14px; }
.titlebox h1 { font-weight: normal; font-size: clamp(32px, 8vw, 54px); line-height: 1.25; margin: 14px 0 26px; text-shadow: 3px 3px 0 #0d1018; }
.titlebtns { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.titlebtns button {
  width: 220px; padding: 12px; font-size: 18px; background: var(--btn); color: var(--ink); border: 3px solid #0d1018;
  box-shadow: 4px 4px 0 #0d1018;
}
.titlebtns button:hover { background: var(--btn-hover); }
.titlebtns button:disabled { opacity: .4; cursor: default; }
.titlebox .note { font-size: 12px; color: #b9b3a5; margin-top: 18px; }

.dlg, .paper {
  background: var(--panel); border: 3px solid var(--line); box-shadow: 6px 6px 0 #0d1018;
  padding: 20px; width: min(520px, 100%);
}
.dlg p { margin: 0 0 12px; font-size: 18px; }
.dlg input { width: 100%; font: inherit; font-size: 20px; padding: 8px 10px; border: 3px solid var(--line); background: #fff; }
.dlg button, .paper button {
  margin-top: 14px; width: 100%; padding: 10px; font-size: 17px;
  background: var(--accent); color: #fff; border: 3px solid var(--line);
}
.paper { max-height: 90vh; overflow: auto; background: #f7f1df; }
.paper h2 { font-weight: normal; font-size: 20px; margin: 0 0 12px; border-bottom: 2px dashed #b5a98d; padding-bottom: 8px; }
#docBody { font-size: 17px; line-height: 1.8; }
#docBody .row { display: flex; gap: 10px; padding: 4px 0; border-bottom: 1px dotted #cfc4a8; }
#docBody .row .k { flex: 0 0 auto; min-width: 9em; color: #6b5d45; }
#docBody .row .v.blank { color: #b0a588; }
#docBody .row .v.new { color: #b2402e; }
#docBody .ok::before { content: "✓ "; color: var(--accent); }
#docBody .ng::before { content: "・ "; color: #b0a588; }
#docBody .ledger { font-size: 18px; line-height: 2; padding: 6px 4px; }
#docBody p { margin: 6px 0; }
#doc.ledger .paper { background: #efe3c2; }
