/* iPhone 縦持ち専用。#ui の中は論理サイズ（幅 390px）で組み、canvas に合わせて丸ごと拡大縮小される */
:root {
  --bg: #1a1a2e;
  --panel: rgba(15, 15, 30, 0.96);
  --accent: #6c8cff;
  --gold: #ffcc00;
  --text: #ffffff;
  --muted: #b8c2ee;
}

[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: var(--bg); overflow: hidden;
  overscroll-behavior: none;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
body { position: fixed; inset: 0; }
#game { width: 100%; height: 100%; height: 100dvh; touch-action: none; }
canvas { display: block; image-rendering: pixelated; }

#ui {
  position: fixed; left: 0; top: 0; transform-origin: 0 0;
  pointer-events: none; color: var(--text);
}
#ui button { font-family: inherit; touch-action: manipulation; cursor: pointer; }

.primary-btn {
  display: block; width: 240px; margin: 28px auto 0; padding: 16px 0;
  border: none; border-radius: 999px; background: var(--gold); color: var(--bg);
  font-size: 19px; font-weight: bold; letter-spacing: 0.1em;
  box-shadow: 0 6px 0 #b38f00;
}
.primary-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #b38f00; }
.close-btn {
  display: block; width: 100%; margin-top: 14px; padding: 12px 0;
  background: var(--accent); color: #fff; border: none; border-radius: 10px; font-size: 15px;
}

/* オープニング／ルール説明 */
.screen {
  position: absolute; inset: 0; box-sizing: border-box; padding: 40px 28px;
  display: flex; flex-direction: column; justify-content: center;
  background: radial-gradient(120% 70% at 50% 30%, #2e3a78 0%, #1a1a2e 70%);
  pointer-events: auto; text-align: center;
}
.eyebrow { margin: 0; color: var(--muted); font-size: 13px; letter-spacing: 0.15em; }
.title-main { margin: 14px 0 0; font-size: 46px; letter-spacing: 0.06em; color: var(--gold); }
.title-sub { margin: 4px 0 0; font-size: 26px; font-weight: bold; letter-spacing: 0.3em; }
.lead { margin: 36px 0 0; font-size: 15px; line-height: 1.8; color: var(--muted); white-space: pre-line; }
.note { margin: 28px 0 0; font-size: 11px; color: #7f89b8; }
.credits {
  position: absolute; left: 0; right: 0; bottom: 14px; margin: 0;
  font-size: 9px; line-height: 1.5; color: #5c6594; letter-spacing: 0.02em;
}
.screen-heading { margin: 0 0 18px; font-size: 24px; color: var(--gold); letter-spacing: 0.2em; }
.rule-block {
  text-align: left; background: rgba(0, 0, 0, 0.3); border-radius: 12px;
  padding: 14px 16px; margin-top: 14px;
}
.rule-block h3 { margin: 0 0 8px; font-size: 13px; color: var(--accent); letter-spacing: 0.1em; }
.rule-block p { margin: 0; font-size: 15px; line-height: 1.7; white-space: pre-line; }
.rule-row { display: flex; align-items: center; gap: 14px; }
.rule-row + .rule-row { margin-top: 12px; }
.rule-row p { flex: 1; }
.icon-dpad { position: relative; flex: none; width: 48px; height: 48px; }
.icon-dpad i { position: absolute; width: 16px; height: 16px; background: #59639a; border-radius: 3px; }
.icon-dpad i:nth-child(1) { left: 16px; top: 0; }
.icon-dpad i:nth-child(2) { left: 16px; bottom: 0; }
.icon-dpad i:nth-child(3) { left: 0; top: 16px; }
.icon-dpad i:nth-child(4) { right: 0; top: 16px; }
.icon-action {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  background: var(--gold); color: var(--bg); font-size: 14px; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
}

/* 上の帯：集めたヒント */
#hud {
  position: absolute; left: 0; right: 0; top: 0; height: 60px; box-sizing: border-box;
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
  background: rgba(10, 12, 28, 0.94); border-bottom: 1px solid #2c3566; font-size: 13px;
}
.hud-label { color: var(--muted); }
#hint-list { display: flex; gap: 6px; }
.hint-slot {
  width: 30px; height: 30px; line-height: 30px; text-align: center; border-radius: 6px;
  background: rgba(255, 255, 255, 0.15); font-weight: bold; font-size: 16px;
}
.hint-slot.filled { background: var(--gold); color: var(--bg); }

/* 下の帯：十字ボタンと「話す／調べる」ボタン */
#controls {
  position: absolute; left: 0; right: 0; bottom: 0; height: 184px;
  background: #141830; border-top: 1px solid #2c3566; pointer-events: auto; touch-action: none;
}
#dpad { position: absolute; left: 24px; top: 17px; width: 150px; height: 150px; touch-action: none; }
#dpad .arm, #dpad .hub { position: absolute; width: 50px; height: 50px; background: #3a4272; }
#dpad .arm { border-radius: 8px; }
#dpad .arm::after {
  content: ""; position: absolute; left: 50%; top: 50%; border: 9px solid transparent;
}
#dpad .up { left: 50px; top: 0; }
#dpad .down { left: 50px; bottom: 0; }
#dpad .left { left: 0; top: 50px; }
#dpad .right { right: 0; top: 50px; }
#dpad .hub { left: 50px; top: 50px; background: #2e355c; }
#dpad .up::after { border-bottom-color: #c9d1ff; transform: translate(-50%, -75%); }
#dpad .down::after { border-top-color: #c9d1ff; transform: translate(-50%, -25%); }
#dpad .left::after { border-right-color: #c9d1ff; transform: translate(-75%, -50%); }
#dpad .right::after { border-left-color: #c9d1ff; transform: translate(-25%, -50%); }
#dpad .arm.active { background: var(--accent); }

#action-area {
  position: absolute; right: 24px; top: 0; bottom: 0; width: 140px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
#action-btn {
  width: 108px; height: 108px; border-radius: 50%; border: none;
  background: var(--gold); color: var(--bg); font-size: 24px; font-weight: bold;
  box-shadow: 0 6px 0 #b38f00;
}
#action-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #b38f00; }
#action-target { margin-top: 12px; min-height: 16px; font-size: 12px; color: var(--muted); }
#action-hint {
  margin: 0; width: 108px; height: 108px; border-radius: 50%; box-sizing: border-box;
  border: 2px dashed #3a4272; color: #7f89b8; font-size: 11px; line-height: 1.5;
  display: flex; align-items: center; justify-content: center; text-align: center;
}

/* 会話パネル（ヒント欄の下から画面の下まで。上半分に写真、下に話） */
.panel {
  position: absolute; left: 0; right: 0; top: 60px; bottom: 0;
  background: #0f1024; pointer-events: auto;
  display: none; flex-direction: column;
}
.panel.show { display: flex; }
.dlg-photo {
  position: relative; flex: none; height: 48%; max-height: 400px; overflow: hidden;
  display: flex; align-items: center; justify-content: center; background: #2e355c;
}
.dlg-photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; }
#dlg-portrait-initial { font-size: 120px; font-weight: bold; color: rgba(255, 255, 255, 0.9); text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); }
.dlg-nameplate {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 36px 18px 12px;
  background: linear-gradient(transparent, rgba(8, 9, 22, 0.92));
}
.panel .name { font-weight: bold; font-size: 22px; letter-spacing: 0.04em; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6); }
.dlg-content { flex: 1; overflow-y: auto; padding: 14px 18px 4px; -webkit-overflow-scrolling: touch; }
.dlg-topic-title { color: var(--gold); font-weight: bold; font-size: 14px; margin-bottom: 6px; }
.panel .body { font-size: 15px; line-height: 1.7; white-space: pre-wrap; }
.panel .hint-tag {
  display: inline-block; margin-top: 12px; padding: 6px 14px;
  background: var(--gold); color: var(--bg); font-weight: bold; border-radius: 8px; font-size: 15px;
}
.panel .hint-tag.new { animation: hint-pop 0.6s ease-out; }
@keyframes hint-pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
.dlg-topics { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.topic-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 13px 14px; border-radius: 10px; text-align: left;
  background: #242b52; border: 1px solid #3d4680; color: #fff; font-size: 15px;
}
.topic-btn::after { content: "›"; font-size: 20px; color: var(--muted); }
.topic-btn:active { background: #313a6b; }
.topic-btn.read { background: #1a1f3d; color: var(--muted); }
.topic-btn .read-mark { margin-left: auto; font-size: 11px; color: #8fd19e; white-space: nowrap; }
.dlg-actions { flex: none; display: flex; flex-direction: column; gap: 8px; padding: 8px 18px 14px; }
.dlg-back {
  width: 100%; padding: 15px 0; border: none; border-radius: 12px;
  background: var(--gold); color: var(--bg); font-size: 17px; font-weight: bold; box-shadow: 0 4px 0 #b38f00;
}
.dlg-back:active { transform: translateY(3px); box-shadow: 0 1px 0 #b38f00; }
.dlg-actions .close-btn { margin-top: 0; }
.panel.reading .dlg-actions .close-btn { background: transparent; border: 1px solid #3d4680; color: var(--muted); }
/* 縦が短い画面：写真を小さめにし、話を読んでいるときは2つのボタンを横に並べる */
.compact .dlg-photo { height: 38%; }
.compact .dlg-content { padding-top: 10px; }
.compact .panel.reading .dlg-actions { flex-direction: row; }
.compact .panel.reading .dlg-back { flex: 2; }
.compact .panel.reading .dlg-actions .close-btn { flex: 1; }

/* ゲートの暗証番号入力 */
#keypad {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 310px; box-sizing: border-box; padding: 20px;
  background: rgba(15, 15, 30, 0.97); border: 2px solid var(--gold); border-radius: 14px;
  text-align: center; pointer-events: auto; display: none;
}
#keypad.show { display: block; }
#keypad .display { font-size: 28px; letter-spacing: 6px; margin: 12px 0; min-height: 34px; }
#keypad .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
#keypad .grid button {
  padding: 14px 0; font-size: 22px; border-radius: 10px; border: none; background: #333; color: #fff;
}
#keypad .grid button:active { background: #555; }
#keypad .grid button.action { background: var(--accent); font-size: 18px; }
#keypad .msg { margin-top: 10px; font-size: 13px; color: #ff8888; min-height: 18px; }

/* エンディング */
#ending {
  position: absolute; inset: 0; box-sizing: border-box; padding: 32px 26px;
  background: rgba(10, 10, 20, 0.97); display: none;
  flex-direction: column; align-items: center; justify-content: center;
  pointer-events: auto; text-align: center;
}
#ending.show { display: flex; }
#ending h2 { color: var(--gold); font-size: 28px; margin: 0 0 20px; }
#ending p { margin: 0; font-size: 15px; line-height: 1.8; white-space: pre-line; }
