* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: #030409;
  color: #d8e4f0;
  font-family: "DotGothic16", "Consolas", "Meiryo", monospace;
  height: 100%;
}
#wrap {
  display: flex;
  gap: 16px;
  padding: 16px;
  justify-content: center;
  align-items: flex-start;
}
#stage {
  position: relative;
  flex: 0 0 auto;
  width: min(calc(100vw - 32px), calc((100vh - 32px) * 1.625));
}
#game {
  display: block;
  width: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 2px solid #2a3550;
  background: #000;
  cursor: none;
}
#ui {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  background: rgba(2, 4, 10, 0.85);
  text-align: center;
  overflow: auto;
}
#overlay.hidden { display: none; }
#overlay .panel {
  max-width: 640px;
  margin: auto;
  padding: 24px 32px;
  border: 3px solid #3a4f7a;
  background: #0a0f1c;
  box-shadow: 6px 6px 0 #000;
}
#overlay h2 { margin: 0 0 12px; font-size: 32px; letter-spacing: 4px; color: #7cc4ff; font-weight: normal; }
#overlay h2.fail { color: #ff5a5a; }
#overlay h2.win { color: #6dffb0; font-family: "Orbitron", sans-serif; font-weight: 900; letter-spacing: 3px; text-shadow: -2px 0 #ff2a8a, 2px 0 #2af0ff; }
#overlay p { line-height: 1.8; margin: 8px 0; text-align: left; }
#overlay .center { text-align: center; }
#overlay .hint { color: #ffd166; }
#overlay button {
  margin-top: 16px;
  padding: 10px 28px;
  font: inherit;
  font-size: 18px;
  color: #050a14;
  background: #7cc4ff;
  border: none;
  box-shadow: 4px 4px 0 #1d3b63;
  cursor: pointer;
  letter-spacing: 2px;
}
#overlay button:hover { background: #a8daff; }
#overlay button:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #1d3b63; }
#overlay table { margin: 10px auto; border-collapse: collapse; }
#overlay td { padding: 3px 14px; text-align: left; }
#overlay .letter p { line-height: 1.9; }
#overlay .key { font-weight: normal; color: #6dffb0; }
#overlay .pink { color: #ff4aa8; }
#overlay .brief-keys { margin-top: 14px; padding-top: 10px; border-top: 1px dashed #3a4f7a; text-align: left; }
#overlay .brief-keys table { margin: 4px 0 0; font-size: 14px; }
#overlay .brief-keys td { padding: 2px 10px 2px 0; color: #9fc3e8; }
#overlay .brief-keys td:first-child { color: #d8e4f0; white-space: nowrap; }
#overlay .rank { font-size: 52px; color: #ffd166; margin: 6px 0; }
#overlay a.sub { color: #6a87b0; font-size: 13px; }
#overlay a.sub:hover { color: #9fc3e8; }

/* オープニングのストーリー表示 */
#overlay.story { background: transparent; cursor: pointer; }
#overlay.story .storybox {
  position: relative;
  margin: auto 3% 3%;
  width: 94%;
  min-height: 6.4em;
  padding: 10px 18px 22px;
  background: rgba(4, 6, 12, 0.88);
  border: 3px solid #3a4f7a;
  box-shadow: 6px 6px 0 #000;
  text-align: left;
  font-size: clamp(12px, 1.3vw, 17px);
  line-height: 1.7;
  white-space: pre-wrap;
}
#overlay.story .storynext {
  position: absolute;
  right: 14px;
  bottom: 6px;
  color: #7cc4ff;
  font-size: 12px;
  animation: blink 1s steps(2) infinite;
}
#overlay.story .skip {
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 4px 12px;
  font: inherit;
  font-size: 13px;
  color: #9fc3e8;
  background: rgba(4, 6, 12, 0.7);
  border: 1px solid #3a4f7a;
  cursor: pointer;
}
@keyframes blink { 50% { opacity: 0; } }

/* 横の地図・ステータスは出さない(体力・武器は画面内、地図は M で開く) */
#hud {
  display: none;
  width: 290px;
  flex: 0 0 290px;
  padding: 14px 16px;
  border: 2px solid #2a3550;
  background: #070b16;
  font-size: 13px;
}
#hud h1 { margin: 0 0 10px; font-size: 22px; letter-spacing: 3px; color: #7cc4ff; font-weight: normal; }
#hud h1 span { color: #ff5a8a; }
#plan {
  display: block;
  width: 258px;
  height: 170px;
  margin-top: 4px;
  border: 2px solid #c8c4b8;
  cursor: pointer;
}
#where { margin-top: 4px; color: #9fc3e8; }
.label { color: #6a87b0; font-size: 11px; letter-spacing: 1px; }
.dim { color: #46597a; letter-spacing: 0; }
.sec { margin: 10px 0; }
.row { display: flex; justify-content: space-between; margin: 5px 0; }
#obj { margin-top: 4px; color: #ffd166; }
#hp { color: #ff3a6a; letter-spacing: 2px; }
#weapon { color: #6dffb0; }
#cands, #log { list-style: none; padding: 0; margin: 4px 0 0; }
#cands li { padding: 1px 0; }
#cands .checked { color: #5a6a80; text-decoration: line-through; }
#cands .found { color: #ffd166; }
#log { min-height: 100px; }
#log li { padding: 2px 0; color: #9fc3e8; border-bottom: 1px dotted #172a45; }
#log li.warn { color: #ff7a7a; }
#log li.good { color: #6dffb0; }
#log li.info { color: #ffd166; }
.keys div { margin: 2px 0; color: #9fc3e8; }
.keys b { color: #d8e4f0; display: inline-block; min-width: 128px; font-weight: normal; }

#overlay .btns button { margin: 16px 6px 0; }
#overlay button:disabled, #overlay button:disabled:hover { background: #24304a; color: #56637a; box-shadow: none; cursor: not-allowed; transform: none; }

/* スマホ・タブレット:横持ちの画面いっぱいに映す */
body.touch { overflow: hidden; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.touch #wrap { padding: 0; height: 100vh; height: 100dvh; align-items: center; }
body.touch #stage { width: 100vw; }
body.touch #game { border: none; touch-action: none; }
body.touch #overlay .panel { padding: 14px 18px; }
body.touch #overlay p { line-height: 1.6; }
#rotate { display: none; }
@media (orientation: portrait) {
  body.touch #rotate {
    display: flex; position: fixed; inset: 0; z-index: 10;
    align-items: center; justify-content: center; text-align: center;
    background: #030409; color: #ffd166; font-size: 20px; line-height: 1.8;
  }
}
