/* ============================================================
   水の記憶 スタイル（前作「徳一の旅」の初期ドラクエ風を流用。
   アクセント色を金→水色に変更）
   ============================================================ */
* { box-sizing: border-box; }

body {
  background: #000;
  color: #fff;
  font-family: 'DotGothic16', 'Hiragino Kaku Gothic ProN', 'Meiryo', monospace;
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 10px 0;
}

#frame {
  width: 512px;
  max-width: 100vw;
  padding: 0 4px;
}

/* ---- HUD ---- */
#hud {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 10px;
  border: 3px solid #fff;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 4px;
}

#hint {
  font-size: 12px;
  color: #8fd3ff;
  padding: 0 4px 6px;
  min-height: 18px;
}

/* HUDの音楽・図鑑ボタンは小さく */
#btn-bgm, #btn-zukan {
  font-size: 12px;
  padding: 0 8px;
  border-width: 2px;
}

/* ---- ゲーム画面 ---- */
#wrap { position: relative; }

canvas {
  width: 100%;
  display: block;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 2px solid #333;
}

/* ---- メッセージウィンドウ ---- */
#msgwin {
  position: absolute;
  left: 2%;
  right: 2%;
  bottom: 2%;
  background: rgba(0, 4, 12, 0.92);
  border: 4px double #fff;
  border-radius: 8px;
  padding: 10px 24px 16px 14px;
  min-height: 112px;
  font-size: 15px;
  line-height: 1.7;
}

#msgtext { white-space: pre-wrap; }

.choice {
  padding: 1px 4px 1px 24px;
  position: relative;
  cursor: pointer;
}
.choice.sel { color: #8fd3ff; }
.choice.sel::before {
  content: '▶';
  position: absolute;
  left: 4px;
}
.choice:hover { color: #8fd3ff; }

#msg-arrow {
  position: absolute;
  right: 10px;
  bottom: 4px;
  animation: blink 0.9s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---- 章タイトルカード ---- */
#chapter-card {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
}
#chapter-card p {
  font-size: 22px;
  letter-spacing: 4px;
  color: #cde9ff;
  animation: card-fade 1.2s ease-out;
}
@keyframes card-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---- タイトル・エンディング ---- */
#title-screen, #ending {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 16px;
  z-index: 5;
}

#title-screen h1 {
  font-size: 34px;
  margin: 0;
  letter-spacing: 6px;
}
#title-screen .sub { margin: 0 0 10px; color: #8fd3ff; }
/* ボタンは折り返して並べる（条件つき表示のものが増減しても枠に収まるように） */
#title-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
#title-screen .help { font-size: 12px; color: #aaa; line-height: 1.8; margin: 8px 0 0; }
#title-screen .credit { font-size: 11px; color: #777; line-height: 1.7; margin: 0; }
.links { font-size: 12px; margin: 10px 0 0; }
.links a { color: #8fd3ff; margin: 0 8px; }

/* 画面枠（canvas と同じ高さ）に本文・ボタン・リンクを収める。
   ボタンは横並びにして高さを稼ぎ、余った高さは本文に使わせる */
#ending { gap: 8px; padding: 12px; }
#ending h2 { margin: 0; color: #8fd3ff; font-size: 17px; }
#ending-text {
  font-size: 13px;
  line-height: 1.75;
  max-width: 460px;
  flex: 1;             /* 余白は本文に回す（読める行数を最大にする） */
  overflow-y: auto;    /* それでも入りきらないときは枠内でスクロール */
  min-height: 0;
}
#ending-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
}
#ending-buttons button.dq { font-size: 13px; padding: 4px 10px; }   /* 4つが1行に収まる幅 */
#ending-text .stats { font-size: 12px; color: #8fd3ff; margin: 6px 0 10px; }
#ending-text .rankmsg { font-size: 12px; color: #bbb; }
#ending-text .rank-high { color: #8fd3ff; }
#ending-text .rank-legend {
  color: #8fd3ff;
  text-shadow: 0 0 8px rgba(143, 211, 255, 0.9);
  animation: legend-glow 1.6s ease-in-out infinite alternate;
}
@keyframes legend-glow {
  from { text-shadow: 0 0 4px rgba(143, 211, 255, 0.5); }
  to   { text-shadow: 0 0 12px rgba(143, 211, 255, 1); }
}

/* ---- 記憶のかけら（図鑑）・ドールンの手帳・章えらび ---- */
#zukan, #techo, #chapsel {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.96);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
  z-index: 5;
}
#zukan h2, #techo h2, #chapsel h2 { margin: 0; color: #8fd3ff; font-size: 18px; }
#zukan-body, #techo-body, #chapsel-body {
  flex: 1;
  min-height: 0;       /* これがないと中身が縮まず「とじる」ボタンに重なる */
  overflow-y: auto;
  width: 100%;
  max-width: 460px;
  font-size: 13px;
  line-height: 1.7;
}
#zukan-body h3 {
  color: #8fd3ff;
  font-size: 14px;
  margin: 10px 0 4px;
  border-bottom: 1px solid #555;
}
#zukan-body .entry { margin: 0 0 8px; }
#zukan-body .entry .desc { color: #bbb; font-size: 12px; white-space: pre-wrap; }
#zukan-body .locked { color: #666; }
#btn-zukan-close, #btn-techo-close, #btn-chapsel-close { font-size: 13px; padding: 4px 20px; }

/* 章えらび（クリア後に開放。1行1章） */
#chapsel {
  background: #000;   /* タイトル画面の上に出るので透かさない */
  z-index: 6;
  gap: 4px;
}
#chapsel .note { margin: 0; font-size: 11px; color: #888; line-height: 1.5; text-align: center; }
#chapsel-body .chap {
  padding: 3px 4px 3px 24px;    /* 左は .choice の▶カーソル分 */
  border-bottom: 1px solid #333;
  line-height: 1.4;
}
#chapsel-body .chap b { font-size: 14px; }
#chapsel-body .chap .meta { display: block; color: #888; font-size: 11px; }
#chapsel-body .chap.sel .meta { color: #7ab6da; }

/* 手帳の資料カード */
#techo-body .land {
  border: 1px solid #446;
  border-radius: 6px;
  padding: 6px 10px;
  margin: 0 0 6px;
}
#techo-body .land b { color: #cde9ff; }
#techo-body .land.asaka { border-color: #8fd3ff; }
#techo-body .land .row { color: #bbb; font-size: 12px; }

button.dq {
  background: #000;
  color: #fff;
  border: 3px solid #fff;
  border-radius: 6px;
  font-family: inherit;
  font-size: 16px;
  padding: 6px 24px;
  cursor: pointer;
}
button.dq:hover { background: #333; }
button.dq:active { background: #555; }

/* ---- タッチパッド（タッチ端末のみ表示。前作から移植） ---- */
#pad {
  display: none;
  justify-content: space-between;
  align-items: center;        /* 十字キーが3段のプラス形状のため、中央揃えでＡボタンと高さを合わせる */
  margin-top: 72px;           /* 上ボタンがゲーム画面に近いと誤タップで文章送りするため間隔を広げる */
  padding: 0 10px;
  user-select: none;
  -webkit-user-select: none;
}

@media (pointer: coarse) {
  #pad { display: flex; }
}

#dpad {
  display: grid;
  grid-template-areas:
    '. up .'
    'left . right'
    '. down .';
  gap: 4px;
}
#dpad button { width: 52px; height: 52px; font-size: 18px; padding: 0; }
#dpad button[data-d='up'] { grid-area: up; }
#dpad button[data-d='left'] { grid-area: left; }
#dpad button[data-d='down'] { grid-area: down; }
#dpad button[data-d='right'] { grid-area: right; }

#btn-a {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: 20px;
  padding: 0;                /* .dq の左右パディングを打ち消す（Ａの中心ずれ対策） */
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  margin-right: 26px;        /* 右端に寄りすぎるため十字キーのボタン半個分左にずらす */
}

/* ---- 狭い画面（スマホ）---- */
/* 画面枠の高さは幅に比例する（canvas 512×384）。幅が狭いとタイトル画面の
   中身が枠からはみ出して HUD に重なるため、余白と文字を詰める */
@media (max-width: 480px) {
  #title-screen { gap: 8px; padding: 8px; }
  #title-screen h1 { font-size: 26px; letter-spacing: 4px; }
  #title-screen .sub { font-size: 13px; margin-bottom: 4px; }
  #title-screen .help { font-size: 11px; line-height: 1.6; margin-top: 4px; }
  #title-screen .credit { font-size: 10px; line-height: 1.5; }
  #title-screen button.dq { font-size: 14px; padding: 4px 18px; }
  #title-buttons { gap: 8px; }

  #ending { gap: 4px; padding: 8px; }
  #ending h2 { font-size: 14px; }
  #ending-text { font-size: 12px; line-height: 1.5; }
  #ending-text .stats { font-size: 11px; margin: 3px 0 4px; }
  #ending-text .rankmsg { font-size: 11px; }
  #ending-buttons { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }   /* 4つを2×2に */
  #ending-buttons button.dq { font-size: 12px; padding: 3px 10px; }   /* 3つが1行に収まる幅 */
  #ending .links { font-size: 10px; margin-top: 2px; }

  #chapsel { padding: 8px; }
  #chapsel h2 { font-size: 15px; }
  #chapsel .note { font-size: 10px; }
  #chapsel-body .chap b { font-size: 13px; }
}

.hidden { display: none !important; }
