:root {
  --ink: #fff7e8;
  --muted: rgba(255, 240, 215, 0.72);
  --panel: rgba(12, 14, 44, 0.86);
  --line: rgba(255, 220, 160, 0.28);
  --gold: #ffcf6a;
  --red: #ff4f6d;
  --box-left: 0px;
  --box-w: 360px;
  --sans: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #070a24;
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body { position: fixed; inset: 0; }

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 12px), max(var(--box-w), 420px));
  display: flex;
  gap: 6px;
  align-items: stretch;
  pointer-events: none;
}

.hud-stat {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 5px 10px;
  border-radius: 12px;
  background: rgba(10, 12, 40, 0.66);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.hud-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.hud-value {
  font-size: clamp(19px, 6vw, 24px);
  font-weight: 900;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-score { flex: 1 1 auto; }

.hud-sub {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--muted);
  white-space: nowrap;
}

.hud-sub b { margin-left: 4px; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: 0; }

.hud-next {
  flex: 0 0 auto;
  align-items: center;
  gap: 2px;
  padding: 4px 12px;
}

.hud-next img { width: 36px; height: 36px; display: block; }

.hud-pause {
  pointer-events: auto;
  flex: 0 0 48px;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(10, 12, 40, 0.66);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.hud-pause svg { width: 22px; height: 22px; fill: currentColor; }
.hud-pause-label { display: none; }
.layout-landscape .hud-pause { display: flex; gap: 6px; align-items: center; justify-content: center; font: 700 14px var(--sans); }
.layout-landscape .hud-pause-label { display: inline; }

.layout-landscape .hud {
  top: 50%;
  left: calc(var(--box-left) / 2);
  transform: translate(-50%, -50%);
  width: min(220px, calc(var(--box-left) - 20px));
  flex-direction: column;
  gap: 8px;
}

.layout-landscape .hud-stat { flex: 0 0 auto; padding: 8px 14px; }
.layout-landscape .hud-value { font-size: 28px; }
.layout-landscape .hud-sub { font-size: 13px; }
.layout-landscape .hud-next { flex-direction: row; justify-content: space-between; padding: 8px 14px; }
.layout-landscape .hud-next img { width: 52px; height: 52px; }
.layout-landscape .hud-pause { flex: 0 0 48px; }

@media (max-height: 420px) {
  .layout-landscape .hud { gap: 5px; }
  .layout-landscape .hud-stat { padding: 4px 10px; }
  .layout-landscape .hud-value { font-size: 20px; }
  .layout-landscape .hud-sub { font-size: 11px; }
  .layout-landscape .hud-next img { width: 36px; height: 36px; }
  .layout-landscape .hud-pause { min-height: 44px; flex-basis: 44px; }
}

/* ---------- 画面 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) calc(env(safe-area-inset-right, 0px) + 12px) calc(env(safe-area-inset-bottom, 0px) + 12px) calc(env(safe-area-inset-left, 0px) + 12px);
  background: rgba(4, 5, 20, 0.45);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.overlay-title { background: linear-gradient(180deg, rgba(4, 5, 20, 0.15), rgba(4, 5, 20, 0.55)); }

.card {
  width: min(100%, 440px);
  padding: 22px 22px 18px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  user-select: text;
  -webkit-user-select: text;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--muted);
}

h2 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 900;
}

.logo {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.logo-main {
  font-family: var(--serif);
  font-weight: 900;
  font-size: clamp(30px, 11vw, 58px);
  letter-spacing: 0.04em;
  white-space: nowrap;
  background: linear-gradient(180deg, #fff6cf 0%, #ffd36a 45%, #ff8a3c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 #6e1b10) drop-shadow(0 0 18px rgba(255, 140, 60, 0.45));
}

.logo-en {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.42em;
  color: var(--gold);
}

.tagline { margin: 2px 0 0; font-weight: 700; font-size: 15px; }

.guide {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.guide-text { margin: 0; font-size: 14px; line-height: 1.7; text-align: left; }

.guide-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 14px 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 207, 106, 0.12);
  color: var(--ink);
  font: 700 13px var(--sans);
  cursor: pointer;
}

.guide-btn svg { width: 20px; height: 20px; fill: currentColor; stroke: currentColor; }
.guide-btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.guide.is-speaking .guide-btn { background: rgba(255, 207, 106, 0.32); }
.guide.is-speaking .guide-btn .wave { animation: wave 0.8s ease-in-out infinite alternate; }
.guide.is-speaking .guide-text { color: #fff3c4; }

@keyframes wave { from { opacity: 0.25; } to { opacity: 1; } }

.controls {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12.5px;
  color: var(--muted);
  text-align: left;
  display: grid;
  gap: 4px;
}

.controls b {
  display: inline-block;
  min-width: 3.6em;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  font-size: 11px;
  text-align: center;
}

.btn {
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: 800 16px var(--sans);
  cursor: pointer;
}

.btn:hover, .toggle:hover, .guide-btn:hover, .hud-pause:hover { filter: brightness(1.15); }

.btn-primary {
  min-height: 56px;
  font-size: 20px;
  letter-spacing: 0.12em;
  border: none;
  color: #3a1200;
  background: linear-gradient(180deg, #ffe08a, #ffad3c);
  box-shadow: 0 6px 0 #a24f0b, 0 10px 24px rgba(255, 140, 40, 0.35);
}

.btn-primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #a24f0b; }

.title-best { margin: 0; font-size: 13px; color: var(--muted); }
.title-best b { color: var(--ink); font-size: 16px; font-variant-numeric: tabular-nums; }

.toggles { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.toggle {
  flex: 1 1 0;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font: 700 13px var(--sans);
  cursor: pointer;
}

.toggle b { margin-left: 4px; color: #ff9aa8; }
.toggle[aria-pressed="true"] { color: var(--ink); background: rgba(120, 220, 140, 0.14); }
.toggle[aria-pressed="true"] b { color: #8dffb0; }

.back-link {
  align-self: center;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.back-link:hover { color: var(--ink); text-decoration: underline; }

:focus-visible { outline: 3px solid #8fd3ff; outline-offset: 2px; }

.result-score { margin: 0; line-height: 1; }
.result-score b { font-size: 54px; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--gold); }
.result-score small { margin-left: 4px; font-size: 16px; color: var(--muted); }

.result-record {
  margin: 0 auto;
  padding: 4px 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff4f6d, #ffb03c);
  color: #fff;
  font-weight: 900;
  animation: pulse 0.9s ease-in-out infinite alternate;
}

@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.08); } }

.result-stats {
  margin: 4px 0;
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.result-stats div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
}

.result-stats dt { color: var(--muted); }
.result-stats dd { margin: 0; display: flex; align-items: center; gap: 6px; font-weight: 800; }
.result-stats img { width: 36px; height: 36px; }

.overlay-rotate { z-index: 5; background: rgba(4, 5, 20, 0.82); }
.rotate-card { width: min(100%, 420px); align-items: center; }
.rotate-card h2 { font-size: 22px; }
.rotate-text { margin: 0; font-size: 14px; line-height: 1.6; color: var(--muted); }
.rotate-icon { width: 76px; height: 76px; }
.rotate-phone { fill: none; stroke: var(--gold); stroke-width: 4; transform-origin: 48px 48px; animation: tilt 2.4s ease-in-out infinite; }
.rotate-screen { fill: rgba(255, 207, 106, 0.25); stroke: none; }
.rotate-arrow { fill: none; stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0.8; }
@keyframes tilt { 0%, 30% { transform: rotate(-90deg); } 55%, 100% { transform: rotate(0deg); } }
@media (max-height: 420px) { .rotate-icon { width: 52px; height: 52px; } .rotate-card { gap: 6px; } }

.noscript { position: fixed; inset: auto 0 40% 0; text-align: center; }

@media (max-height: 560px) {
  .card { gap: 7px; padding: 14px 16px 12px; }
  .logo-main { font-size: 36px; }
  .guide { padding: 8px 12px; }
  .guide-text { font-size: 13px; line-height: 1.55; }
  .btn-primary { min-height: 48px; }
  h2 { font-size: 24px; }
  .result-score b { font-size: 40px; }
}

.title-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

@media (max-height: 700px) {
  .logo-main { font-size: clamp(30px, 10vw, 46px); }
  .tagline { font-size: 14px; }
  .guide-text { font-size: 13px; line-height: 1.6; }
  .controls { font-size: 12px; }
}

@media (max-height: 560px) and (min-width: 640px) {
  .title-card { width: min(100%, 780px); flex-direction: row; align-items: stretch; gap: 18px; }
  .title-col { flex: 1 1 0; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  .result-record, .guide.is-speaking .guide-btn .wave, .rotate-phone { animation: none; }
}
