:root {
  --bg: #04060a;
  --panel: rgba(8, 14, 22, .86);
  --border: rgba(255, 255, 255, .14);
  --ink: #e7fbff;
  --muted: #7d97a8;
  --accent: #5ad1ff;
  --gold: #ffd166;
  --danger: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; color: var(--ink); background: rgba(255, 255, 255, .08); border: 1px solid var(--border); border-radius: 8px; }
button:hover { border-color: var(--accent); }
.hidden { display: none !important; }
a { color: var(--muted); }
a:hover { color: var(--ink); }

#title-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.title-card {
  width: min(560px, 100%);
  padding: clamp(22px, 5vw, 44px);
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel);
  text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .5);
}
.brand-mark { color: var(--gold); letter-spacing: .3em; font-size: .72rem; font-weight: 700; }
#title-screen h1 { margin: 8px 0 4px; font-size: clamp(1.8rem, 6vw, 2.8rem); letter-spacing: .06em; }
.tagline { margin: 0 0 20px; color: var(--muted); font-size: .88rem; }
#start-btn { min-height: 54px; width: min(320px, 100%); font-size: 1.05rem; font-weight: 700; border-color: var(--accent); background: rgba(90, 209, 255, .14); }
#open-ranking-btn { min-height: 44px; width: min(320px, 100%); margin-top: 10px; }
.high-score-line { margin: 14px 0 6px; color: var(--muted); font-size: .82rem; }
#title-highscore { color: var(--gold); font-variant-numeric: tabular-nums; }
.controls-help { margin: 18px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.6; text-align: left; }
.trivia { margin: 12px 0 0; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 10px; color: var(--muted); font-size: .76rem; text-align: left; }
.title-footer { margin-top: 20px; }
#home-link { display: inline-block; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; text-decoration: none; font-size: .78rem; }

#game-screen {
  min-height: 100dvh;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 14px;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.side-panel {
  display: none;
  width: 240px;
  flex: 0 0 auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  font-size: .8rem;
  color: var(--muted);
  overflow-y: auto;
}
.side-panel h2 { margin: 0 0 10px; font-size: .95rem; color: var(--ink); }
.ranking-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ranking-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .05);
  text-align: left;
}
.ranking-row:hover { border-color: var(--accent); }
.ranking-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.ranking-wave { color: var(--muted); flex: 0 0 auto; }
.ranking-score { color: var(--gold); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.ranking-empty { color: var(--muted); padding: 6px 8px; }
.ranking-modal-card { width: min(480px, 100%); max-height: 80dvh; overflow-y: auto; }

#stage {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
#canvas-wrap {
  position: relative;
  /* Deriving width from a flat share of viewport height (rather than
     subtracting a fixed px budget for chrome/HUD/touch-bar) avoids the
     canvas collapsing to near-zero when that budget assumption doesn't
     hold for a given window/viewport (reported as "the game doesn't
     render" — the canvas was there, just sized down to a few px). */
  width: min(100%, calc(68dvh * 3 / 4));
  min-width: 220px;
  max-width: 480px;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  touch-action: none;
}
#game-canvas { display: block; width: 100%; height: 100%; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

#pause-btn, #mute-btn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  z-index: 40;
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
}
#fullscreen-btn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  z-index: 40;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  background: rgba(20,24,32,.55);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 15px;
  line-height: 30px;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
}
#pause-btn { right: max(10px, env(safe-area-inset-right)); }
#mute-btn { right: calc(max(10px, env(safe-area-inset-right)) + 54px); font-size: 1.1rem; }
#replay-stop-btn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 40;
  min-height: 44px;
  border-radius: 10px;
  border-color: var(--danger);
  color: var(--danger);
}

#touch-bar {
  width: 100%;
  max-width: 480px;
  height: 15vh;
  min-height: 90px;
  max-height: 140px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(90deg, rgba(90, 209, 255, .1), rgba(255, 255, 255, .03) 50%, rgba(90, 209, 255, .1));
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
}
#touch-bar::before, #touch-bar::after {
  content: "◀";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 1.4rem;
  pointer-events: none;
}
#touch-bar::before { left: 20px; }
#touch-bar::after { content: "▶"; right: 20px; }

@media (hover: hover) and (pointer: fine) {
  #touch-bar { display: none; }
}
@media (min-width: 900px) {
  /* Reserve predictable, modest columns for the supplementary panels and
     give every remaining pixel to the playfield.  The old flex layout let
     the stage shrink to canvas-wrap's 220px minimum because its percentage
     width had no definite flex basis. */
  #game-screen {
    display: grid;
    grid-template-columns: minmax(180px, 240px) minmax(0, 1fr) minmax(180px, 240px);
    gap: clamp(12px, 1.5vw, 24px);
  }
  .side-panel { display: block; width: auto; }
  #stage { width: 100%; }
  /* A mouse-driven desktop has no touch bar to budget for.  Limit the canvas
     by whichever dimension is exhausted first, so it fills the screen while
     retaining the original 3:4 game area. */
  #canvas-wrap {
    width: min(100%, calc((100dvh - 20px) * 3 / 4));
    min-width: 0;
    max-width: none;
  }
}
@media (orientation: landscape) and (max-height: 520px) {
  /* short landscape phones: stacking canvas above the touch bar would
     force page scroll, so put the bar beside the canvas instead */
  #game-screen { padding-top: 6px; padding-bottom: 6px; }
  #stage { flex-direction: row; align-items: stretch; gap: 8px; }
  #canvas-wrap { width: auto; height: 100%; max-width: none; }
  #touch-bar { width: 110px; max-width: 110px; height: auto; min-height: 0; max-height: none; }
  #touch-bar::before, #touch-bar::after { font-size: 1.1rem; }
}

.game-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 4, 8, .82);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}
.overlay-card {
  width: min(420px, 100%);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  text-align: center;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .5);
}
.overlay-card h2 { margin: 0 0 12px; }
#final-highnote { color: var(--gold); font-weight: 700; margin-top: 6px; }
.overlay-actions { margin-top: 20px; display: grid; gap: 10px; }
.overlay-actions button { min-height: 48px; }
.overlay-actions button:disabled { opacity: .5; cursor: not-allowed; }
#resume-btn { border-color: var(--accent); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.ranking-submit-form { margin-top: 16px; display: grid; gap: 8px; }
.ranking-submit-form input {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  color: var(--ink);
  font: inherit;
  text-align: center;
}
.ranking-submit-form button { min-height: 44px; border-color: var(--gold); }
#ranking-submit-status { min-height: 18px; margin: 0; color: var(--muted); font-size: .78rem; }
.secondary-btn { background: rgba(255, 255, 255, .05); }

.tutorial-list { margin: 0; padding-left: 1.2em; text-align: left; color: var(--muted); font-size: .88rem; line-height: 1.7; }
.tutorial-list li strong { color: var(--ink); }
#tutorial-start-btn { border-color: var(--accent); background: rgba(90, 209, 255, .14); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* little-bit: focus-visible(2026-08-29追加)
   キーボード操作でいまどこにいるかが見えないアプリが24中20あった
   (サイト品質棚卸し B-5)。:where() で詳細度0にしてあるので、
   個別に focus スタイルを持つ要素はそちらが勝つ。
   色はサイト共通のアクセント(#e8825a)。明るい地でも暗い地でも見える。 */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid #e8825a;
  outline-offset: 2px;
}
