:root {
  --bg: #000;
  --line: #fff;
  --text: #fff;
  --muted: #b8b8b8;
  --gold: #ffd75e;
  --ng: #ff8080;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  font-family: "DotGothic16", "Hiragino Kaku Gothic ProN", monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh; /* モバイルのアドレスバー分を除いた高さ */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  image-rendering: pixelated;
  -webkit-tap-highlight-color: transparent;
}

/* タップ時のダブルタップズームを無効化(連打しやすく) */
.btn,
.dialogue,
.answer-form input[type="text"] {
  touch-action: manipulation;
}

#app {
  width: 100%;
  max-width: 480px;
}

/* 画面の切り替え */
.screen {
  display: none;
  text-align: center;
  animation: fadein 0.3s steps(4);
}

.screen.active {
  display: block;
}

@keyframes fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ドラクエ風ウィンドウ:白の二重枠 */
.window {
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 0 0 3px var(--bg), inset 0 0 0 5px var(--line);
  padding: 24px 20px;
}

.title {
  font-size: 2rem;
  line-height: 1.5;
  letter-spacing: 0.1em;
  margin-bottom: 24px;
  text-shadow: 3px 3px 0 #444;
}

.message {
  line-height: 2;
}

/* タイトル画面 */
#screen-title .window,
#screen-clear .window {
  margin-bottom: 24px;
}

/* 導入シーン:王様 */
.sprite {
  position: relative;
  margin: 0 auto 16px;
}

.sprite .dot-px {
  position: absolute;
  top: 0;
  left: 0;
  background: transparent;
}

.speaker {
  text-align: left;
  color: var(--gold);
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.dialogue {
  text-align: left;
  min-height: 130px;
  cursor: pointer;
  position: relative;
  margin-bottom: 20px;
  user-select: none;
}

.dialogue .message {
  line-height: 2.1;
}

/* セリフ送りの ▼(最後のセリフでは消す) */
.dialogue::after {
  content: "▼";
  position: absolute;
  right: 14px;
  bottom: 8px;
  font-size: 0.8rem;
  animation: blink 1s steps(2) infinite;
}

.dialogue.done::after {
  display: none;
}

/* ステージヘッダー */
.stage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.label-window {
  display: inline-block;
  padding: 8px 14px;
  font-size: 0.95rem;
  color: var(--gold);
  white-space: nowrap;
}

.progress-dots {
  display: flex;
  gap: 8px;
}

/* 進捗:■=クリア済み(金) / 点滅=いま / □=未挑戦 */
.progress-dots .dot {
  width: 12px;
  height: 12px;
  border: 2px solid var(--line);
  background: transparent;
}

.progress-dots .dot.done {
  background: var(--gold);
  border-color: var(--gold);
}

.progress-dots .dot.current {
  background: var(--line);
  animation: blink 1s steps(2) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* 問題エリア */
.puzzle-area {
  margin-bottom: 20px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  position: relative;
}

/* ウィンドウ右下の ▼ カーソル */
.puzzle-area::after {
  content: "▼";
  position: absolute;
  right: 14px;
  bottom: 8px;
  font-size: 0.8rem;
  animation: blink 1s steps(2) infinite;
}

.placeholder {
  color: var(--muted);
  line-height: 1.8;
}

.quiz-text {
  line-height: 1.9;
  margin-bottom: 4px;
}

/* 穴埋めマス目(文字数が多い場合はマスが縮んで1行に収まる) */
.masked-word {
  display: grid;
  grid-template-columns: repeat(var(--len), minmax(0, 38px));
  gap: 5px;
  justify-content: center;
  width: 100%;
}

.tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.8rem, 4vw, 1.15rem);
  border: 2px solid var(--line);
}

.tile.revealed {
  background: var(--line);
  color: var(--bg);
}

.tile.hidden-char {
  border-style: dashed;
  color: var(--muted);
}

.tile.hidden-char::before {
  content: "?";
  opacity: 0.5;
}

/* クリア画面:宝箱と宝 */
.chest-scene {
  position: relative;
  height: 200px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  margin-bottom: 20px;
}

.chest-scene .sprite {
  margin: 0;
}

#gift-sprite {
  position: absolute;
  bottom: 30px;
  opacity: 0;
}

#gift-sprite.pop {
  animation: pop-out 0.9s steps(8) forwards;
}

@keyframes pop-out {
  from { opacity: 0; transform: translateY(0) scale(0.5); }
  to   { opacity: 1; transform: translateY(-100px) scale(1); }
}

.spark {
  position: absolute;
  left: 50%;
  bottom: 40px;
  transform: translate(var(--sx), var(--sy));
  color: var(--gold);
  font-size: 1.1rem;
  opacity: 0;
}

.opened .spark {
  opacity: 1;
  animation: blink 0.9s steps(2) infinite;
}

.opened .spark:nth-of-type(2) { animation-delay: 0.3s; }
.opened .spark:nth-of-type(3) { animation-delay: 0.5s; }
.opened .spark:nth-of-type(4) { animation-delay: 0.7s; }

#clear-window {
  animation: fadein 0.5s steps(4);
}

/* 古書:流れてくる文章 */
.book-scroll {
  width: 100%;
  max-height: 220px;
  overflow-y: auto;
  text-align: center;
  scrollbar-width: none;
}

.book-scroll::-webkit-scrollbar {
  display: none;
}

.book-line {
  line-height: 2;
  animation: fadein 0.9s steps(4);
}

/* 隠し文字:ほんのり金色がかった色(目立ち具合はここで調整) */
.secret {
  color: #ead9a0;
}

/* 解答フォーム */
.answer-form input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 12px;
  border: 2px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  text-align: center;
}

.answer-form input[type="text"]:focus {
  outline: none;
  border-color: var(--gold);
}

.answer-form input[type="text"]::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.feedback {
  min-height: 1.8em;
  margin-bottom: 8px;
}

.feedback.ng { color: var(--ng); }

/* コマンド風ボタン */
.btn {
  display: inline-block;
  padding: 12px 28px;
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 0 0 3px var(--bg), inset 0 0 0 5px var(--line);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
}

.btn:hover,
.btn:focus-visible {
  color: var(--gold);
  outline: none;
}

.btn:active {
  transform: translateY(2px);
}

.btn-sub {
  color: var(--muted);
}

/* スマホ(狭い画面)向けの調整 */
@media (max-width: 420px) {
  body {
    padding: 12px;
  }

  .title {
    font-size: 1.6rem;
  }

  .window {
    padding: 20px 14px;
  }

  .puzzle-area {
    min-height: 120px;
  }

  .dialogue {
    min-height: 150px; /* セリフ送りで高さがガタつかないよう少し余裕を持たせる */
  }

  .btn {
    padding: 11px 20px;
    font-size: 0.95rem;
  }

  .label-window {
    padding: 7px 10px;
    font-size: 0.85rem;
  }
}
