/* =====================================================================
   立体迷路おにごっこ — 見た目
   レイアウト: 中央 1 カラム。夜の迷路（藍色）に、れんが・コイン・はしごの色を差す。
   文字は大きめ・高コントラスト（弱視の人にも読みやすく）。
   ===================================================================== */
:root {
  color-scheme: dark;
  --bg: #15132b;        /* 夜の迷路 */
  --bg-2: #1d1a3b;
  --panel: #262250;
  --line: #443e80;
  --fg: #f4f1e8;
  --muted: #c3bfdd;
  --gold: #ffc94d;      /* コイン（主役の色） */
  --gold-ink: #1c1632;
  --cyan: #74deeb;      /* はしご・フォーカス */
  --brick: #d0683f;     /* 壊せる壁 */
  --red: #ff7468;       /* 鬼 */
  --green: #5dffa0;     /* ゴール */
  --font-display: "DotGothic16", "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  --radius: 6px;
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

.app {
  max-width: 940px;
  margin: 0 auto;
  padding-block: 20px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 400; line-height: 1.3; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(1.9rem, 6vw, 3rem); letter-spacing: 0.04em; }
h2 { font-size: 1.25rem; color: var(--gold); margin-top: 1.4em; }
h1:focus, h2:focus { outline: none; }
p { margin: 0.5em 0; }
ul { padding-left: 1.3em; margin: 0.5em 0; }
li { margin: 0.25em 0; }
a { color: var(--cyan); }

:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; border-radius: 3px; }

.screen { display: flex; flex-direction: column; gap: 22px; }

/* ---------------- タイトル ---------------- */
.hero {
  position: relative;
  padding: 26px 24px 28px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(21, 19, 43, 0.25), rgba(21, 19, 43, 0.92) 78%),
    repeating-linear-gradient(0deg, transparent 0 22px, rgba(21, 19, 43, 0.9) 22px 26px),
    repeating-linear-gradient(90deg, #a8522f 0 52px, #7c3a22 52px 56px);
  overflow: hidden;
}
.eyebrow { margin: 0 0 6px; font-family: var(--font-display); color: var(--gold); letter-spacing: 0.2em; font-size: 0.95rem; }
.hero h1 { text-shadow: 0 3px 0 #0b0a18; }
.lead { max-width: 38em; margin: 14px 0 0; color: var(--fg); }

.start-panel {
  display: grid; gap: 16px;
  padding: 20px;
  background: var(--panel);
  border-radius: var(--radius);
}
.start-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.start-actions .btn { flex: 1 1 220px; }
.join { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.join .field { flex: 1 1 220px; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-weight: 700; }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field.check label { font-weight: 500; }
.hint, .note { color: var(--muted); font-size: 0.92rem; margin: 2px 0 0; }
.note:empty { display: none; }

input[type="text"], input[type="number"], select {
  width: 100%;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
  min-height: 46px;
}
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--gold); flex: none; }
input[type="range"] { width: 100%; accent-color: var(--gold); min-height: 30px; }
input:disabled, select:disabled { opacity: 0.6; }

.btn {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font: inherit; font-weight: 700;
  color: var(--fg);
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 20px;
  min-height: 50px;
  cursor: pointer;
}
.btn small { font-weight: 500; font-size: 0.82rem; opacity: 0.85; }
.btn:hover { border-color: var(--cyan); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
.btn.primary:hover { background: #ffd978; border-color: #ffd978; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 42px; padding: 6px 12px; font-size: 0.92rem; font-weight: 500; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; }

.fold { border: 2px solid var(--line); border-radius: var(--radius); background: var(--bg-2); }
.fold > summary {
  cursor: pointer; padding: 12px 16px; font-weight: 700; list-style-position: inside;
}
.fold[open] > summary { border-bottom: 2px solid var(--line); }
.fold-body { padding: 4px 16px 18px; }
.fold-body > h2:first-child { margin-top: 0.8em; }
fieldset { border: 2px solid var(--line); border-radius: var(--radius); padding: 14px 16px 18px; margin: 0; min-width: 0; }
fieldset.fold-body { border: 0; }
legend { font-family: var(--font-display); color: var(--gold); padding: 0 8px; font-size: 1.1rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px 20px; padding-top: 10px; }
form { display: flex; flex-direction: column; gap: 18px; margin: 0; }
form.join { flex-direction: row; }

.keys { width: 100%; border-collapse: collapse; margin: 10px 0; }
.keys caption, .ranking caption { text-align: left; color: var(--muted); padding-bottom: 6px; }
.keys th, .keys td, .ranking th, .ranking td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.keys tbody th { white-space: nowrap; color: var(--gold); font-family: var(--font-display); font-weight: 400; }
.demo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }

/* ---------------- ロビー ---------------- */
.room-box { padding: 16px 20px; background: var(--panel); border-radius: var(--radius); }
.room-code { font-size: 1.1rem; margin: 0; }
.room-code strong { font-family: var(--font-display); font-size: 2rem; letter-spacing: 0.25em; color: var(--gold); margin-left: 10px; }
.room-box h2 { margin-top: 0.6em; font-size: 1.05rem; }
#member-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
#member-list li { padding: 4px 12px; border: 2px solid var(--line); border-radius: 999px; background: var(--bg); margin: 0; }
#member-list li.is-off { opacity: 0.55; }

/* ---------------- ゲーム ---------------- */
.game {
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 10;
  max-height: 72vh;
  background: #0b0a18;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.game:focus { outline: 3px solid var(--cyan); outline-offset: 2px; }
.view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.minimap {
  position: absolute; right: 10px; bottom: 10px;
  width: clamp(96px, 22%, 190px); aspect-ratio: 1;
  border: 2px solid var(--line); border-radius: 4px;
}
.game.use-map .view { display: none; }
.game.use-map .minimap { inset: 0; width: 100%; height: 100%; aspect-ratio: auto; border: 0; }

.hud { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; }
.chip {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 2px 10px;
  background: rgba(21, 19, 43, 0.85);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 0.95rem;
}
.chip i { font-style: normal; color: var(--muted); font-size: 0.8rem; }
.chip b { font-family: var(--font-display); font-weight: 400; font-size: 1.15rem; font-variant-numeric: tabular-nums; color: var(--gold); }
.chip.role { font-family: var(--font-display); color: var(--cyan); border-color: var(--cyan); }
.chip.role.is-oni { color: var(--red); border-color: var(--red); }
.chip.oni b { color: var(--red); letter-spacing: 0.1em; }
#hud-time.is-low { color: var(--red); }

.banner {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%);
  margin: 0; padding: 6px 22px;
  font-family: var(--font-display); font-size: clamp(1.4rem, 5vw, 2.6rem);
  color: var(--gold); background: rgba(11, 10, 24, 0.78); border-radius: var(--radius);
  text-align: center; pointer-events: none; white-space: nowrap; max-width: 94%; overflow: hidden; text-overflow: ellipsis;
}
.msg-log {
  position: absolute; left: 10px; bottom: 10px;
  width: min(70%, 520px);
  display: flex; flex-direction: column; gap: 3px;
  pointer-events: none;
}
.msg-log p {
  margin: 0; padding: 3px 10px;
  background: rgba(11, 10, 24, 0.8);
  border-left: 3px solid var(--line);
  font-size: 0.9rem; line-height: 1.45;
  color: var(--muted);
}
.msg-log p:last-child { color: var(--fg); border-left-color: var(--gold); }
.focus-hint {
  position: absolute; inset: 0; margin: 0;
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px;
  background: rgba(11, 10, 24, 0.72); color: var(--fg); font-weight: 700;
}
.game:focus .focus-hint, .game:focus-within .focus-hint { display: none; }
.keys-brief { color: var(--muted); font-size: 0.9rem; margin: 0; }

.pad { display: none; gap: 14px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.pad.is-on { display: flex; }
@media (pointer: coarse) { .pad { display: flex; } .keys-brief { display: none; } }
.pad button {
  font: inherit; font-weight: 700; color: var(--fg); background: var(--panel);
  border: 2px solid var(--line); border-radius: var(--radius); min-height: 52px; min-width: 52px; padding: 4px 10px;
  touch-action: manipulation;
}
.pad button.bomb { background: var(--brick); border-color: var(--brick); }
.pad-move { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(2, 56px); gap: 6px; }
.pad-move button:nth-child(1) { grid-column: 2; grid-row: 1; }
.pad-move button:nth-child(2) { grid-column: 1; grid-row: 2; }
.pad-move button:nth-child(3) { grid-column: 2; grid-row: 2; }
.pad-move button:nth-child(4) { grid-column: 3; grid-row: 2; }
.pad-act { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; flex: 1 1 260px; }
.pad-act button { font-size: 0.85rem; font-weight: 500; }

/* ---------------- 結果 ---------------- */
.outcome { font-family: var(--font-display); font-size: clamp(1.4rem, 4.5vw, 2.1rem); color: var(--gold); margin: 0; }
.ranking { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ranking td:first-child { font-family: var(--font-display); color: var(--gold); white-space: nowrap; }
.ranking tr.is-me td { background: rgba(255, 201, 77, 0.12); }

/* ---------------- メニュー ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(11, 10, 24, 0.8);
}
.dialog {
  width: min(420px, 100%);
  display: flex; flex-direction: column; gap: 12px;
  padding: 22px;
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: var(--radius);
}
.dialog h2 { margin: 0; }

.credits { margin-top: 34px; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line); padding-top: 12px; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  .hero { padding: 18px 16px 20px; }
  .game { aspect-ratio: 4 / 5; }
  .chip { font-size: 0.8rem; padding: 1px 6px; }
  .chip b { font-size: 1rem; }
  .msg-log { width: calc(100% - 20px); bottom: auto; top: 104px; }
  .msg-log p:not(:last-child) { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn { transition: border-color 0.12s, background-color 0.12s; }
}
