:root {
  color-scheme: light;
  --bg: #f7fafb;
  --panel: rgba(255, 255, 255, 0.76);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --panel-soft: rgba(255, 255, 255, 0.58);
  --line: rgba(34, 83, 95, 0.16);
  --line-hot: rgba(34, 83, 95, 0.34);
  --text: #17242b;
  --muted: #66757c;
  --accent: #2f6f7b;
  --accent-strong: #164f5d;
  --accent-soft: rgba(47, 111, 123, 0.08);
  --cyan: var(--accent);
  --gold: var(--accent);
  --pink: var(--accent);
  --green: var(--accent);
  --danger: #9d4f58;
  --body-bg: #fbfdff;
  --shell-bg: rgba(255, 255, 255, 0.9);
  --reader-bg: rgba(255, 255, 255, 0.86);
  --digit-bg: rgba(255, 255, 255, 0.94);
  --digit-border: rgba(47, 111, 123, 0.24);
  --digit-color: var(--accent-strong);
  --digit-shadow: none;
  --digit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.74);
  --hud-bg: rgba(255, 255, 255, 0.66);
  --message-bg: rgba(255, 255, 255, 0.7);
  --message-border: rgba(34, 83, 95, 0.14);
  --card-bg: rgba(255, 255, 255, 0.9);
  --logo-filter: none;
  --logo-blend: normal;
  --button-bg: rgba(255, 255, 255, 0.9);
  --modal-bg: rgba(255, 255, 255, 0.96);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: "Noto Sans JP", system-ui, sans-serif;
  background: var(--body-bg);
  overflow-x: hidden;
}

body[data-mode="cpu"] #scoreDisplay,
body[data-mode="cpu"] #waveDisplay,
body[data-mode="cpu"] #lifeDisplay,
body[data-mode="cpu"] #rankingWrapper,
body[data-mode="cpu"] #resultScorePanel,
body[data-mode="cpu"] #localHighScore_result,
body[data-mode="cpu"] #resultRankingContainer2,
body:not([data-mode="cpu"]) #scoreDisplayPlayer,
body:not([data-mode="cpu"]) #scoreDisplayCPU,
body:not([data-mode="cpu"]) #battleResult,
body:not([data-mode="cpu"]) .cpu-ranking-note,
body:not([data-mode="cpu"]) .cpu-level-panel,
body:not([data-mode="endless"]) #waveDisplay,
body:not([data-mode="endless"]) #lifeDisplay {
  display: none !important;
}

body[data-mode="cpu"] .cpu-ranking-note {
  display: block;
}

button,
a {
  font: inherit;
}

.arena {
  position: relative;
  width: min(1180px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0 40px;
}

.ambient-lines,
.scan-grid,
#fxLayer {
  pointer-events: none;
}

.ambient-lines,
.scan-grid {
  position: fixed;
  inset: 0;
}

.ambient-lines {
  display: none;
}

.scan-grid {
  background-image:
    linear-gradient(rgba(34, 83, 95, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 83, 95, 0.028) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(circle at center, black, transparent 78%);
}

#fxLayer {
  position: static;
  width: 0;
  height: 0;
  overflow: visible;
}

.game-shell {
  position: relative;
  z-index: 1;
  min-height: calc(100vh - 92px);
  padding: clamp(18px, 3vw, 34px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--shell-bg);
  box-shadow: 0 18px 44px rgba(31, 83, 103, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px) saturate(1.16);
  overflow: hidden;
}

.game-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: inherit;
  pointer-events: none;
}

.game-hero {
  display: flex;
  justify-content: center;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.game-playing .game-hero {
  display: none;
}

.game-logo {
  width: min(420px, 88vw);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  filter: var(--logo-filter);
  mix-blend-mode: var(--logo-blend);
}

.eyebrow,
.status-chip {
  margin: 0;
  color: var(--gold);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: clamp(1rem, 2vw, 1.35rem);
  letter-spacing: 0;
}

h1 {
  margin: 4px 0 8px;
  font-size: clamp(2.2rem, 6vw, 4.9rem);
  line-height: 0.92;
  letter-spacing: 0;
  word-break: keep-all;
  text-shadow: none;
}

.tagline {
  max-width: 36em;
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 2vw, 1.18rem);
}

.topbar,
.hud,
#rankingWrapper,
#resultDisplay {
  display: flex;
  gap: 16px;
}

.topbar {
  align-items: center;
  justify-content: center;
  margin: 14px 0 18px;
  min-height: 28px;
}

.mode-actions,
.menu-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 180px));
  justify-content: center;
  align-items: stretch;
  gap: 10px;
  margin: 0 auto;
}

.mode-actions {
  width: min(100%, 640px);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.game-playing .mode-actions {
  display: none;
}

.game-playing .toggle-stack {
  display: none;
}

.toggle-stack {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.sound-toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
}

.switch input[type="checkbox"] {
  appearance: none;
  position: relative;
  width: 32px;
  height: 18px;
  margin: 0;
  border: 1px solid rgba(34, 83, 95, 0.2);
  border-radius: 999px;
  background: rgba(225, 240, 245, 0.9);
  cursor: pointer;
  transition: background 0.24s, box-shadow 0.24s;
}

.switch input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(31, 83, 103, 0.16);
  transition: transform 0.24s;
}

.switch input[type="checkbox"]:checked {
  background: var(--cyan);
  box-shadow: 0 0 0 2px rgba(47, 111, 123, 0.08);
}

.switch input[type="checkbox"]:checked::before { transform: translateX(14px); }

.action-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 180px));
  justify-content: center;
  gap: 10px;
  margin: 6px 0 18px;
}

.cpu-shell .action-row {
  grid-template-columns: repeat(auto-fit, minmax(180px, 180px));
}

.option-panel {
  position: relative;
  display: grid;
  width: min(100%, 360px);
  gap: 13px;
  margin: 24px auto 16px;
  padding: 10px 12px;
  border: 1px solid rgba(34, 83, 95, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.option-title {
  margin: 0;
  color: var(--muted);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  text-align: center;
}

.voice-options {
  display: grid;
  grid-template-columns: auto repeat(2, minmax(0, 1fr));
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.voice-options legend {
  display: contents;
  color: var(--cyan);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: 0.92rem;
  font-weight: 900;
  letter-spacing: 0;
}

.voice-choice {
  position: relative;
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  color: var(--text);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1;
}

.voice-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.voice-choice span {
  display: flex;
  width: 100%;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(34, 83, 95, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  transition: border-color 0.14s, background 0.14s, color 0.14s, transform 0.14s;
}

.voice-choice:hover span {
  border-color: rgba(34, 83, 95, 0.24);
  background: rgba(255, 255, 255, 0.94);
  transform: translateY(-1px);
}

.voice-choice input:checked + span {
  border-color: rgba(34, 83, 95, 0.22);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

body.game-playing .option-panel {
  display: none;
}

#startButton,
#cpuButton,
#endlessButton,
#hiscoreButton,
#quitButton,
#restartButton,
#postButton,
#resultTopButton,
#rankingButton,
#howToButton,
#nextWaveButton {
  min-width: 168px;
  padding: 13px 22px;
  border: 1px solid rgba(34, 83, 95, 0.18);
  border-radius: 6px;
  color: var(--text);
  background: var(--button-bg);
  box-shadow: 0 1px 3px rgba(31, 83, 103, 0.04);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  transition: transform 0.14s, border-color 0.14s, background 0.14s;
}

#cpuButton.active,
#endlessButton.active,
#hiscoreButton.active {
  color: #ffffff;
  border-color: rgba(34, 83, 95, 0.26);
  background: var(--accent);
  font-weight: 900;
}

#startButton {
  color: #ffffff;
  background: var(--accent);
  border-color: rgba(34, 83, 95, 0.26);
  font-weight: 900;
}

.mode-actions #hiscoreButton,
.mode-actions #cpuButton,
.mode-actions #endlessButton {
  min-width: 0;
  padding: 10px 12px;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.mode-actions #hiscoreButton.active,
.mode-actions #cpuButton.active,
.mode-actions #endlessButton.active {
  color: var(--accent-strong);
  border-color: rgba(34, 83, 95, 0.12);
  background: var(--accent-soft);
}

#restartButton,
#quitButton,
#postButton,
#nextWaveButton { display: none; }

#quitButton,
#nextWaveButton {
  grid-column: 1 / -1;
  justify-self: center;
  width: 180px;
}

#nextWaveButton:disabled {
  opacity: 0.58;
  cursor: wait;
  transform: none;
}

body.game-playing[data-mode="endless"].awaiting-next-wave #nextWaveButton {
  position: static;
  z-index: 1;
  width: min(100%, 230px);
  border-color: rgba(34, 83, 95, 0.18);
  background: rgba(255, 255, 255, 0.82);
  color: var(--cyan);
  transform: none;
}

body.game-playing[data-mode="endless"].awaiting-next-wave #nextWaveButton:hover {
  border-color: rgba(34, 83, 95, 0.26);
  background: rgba(255, 255, 255, 0.94);
  color: var(--accent-strong);
  transform: translateY(-1px);
}

body.game-playing[data-mode="endless"].awaiting-next-wave #nextWaveButton:disabled {
  transform: none;
}

body.game-playing[data-mode="endless"].awaiting-next-wave #nextWaveButton[data-ready="true"]::before {
  content: none;
}

body.game-playing[data-mode="endless"].awaiting-next-wave .grid {
  align-content: center;
  align-items: center;
  justify-content: center;
}

.next-wave-panel {
  display: flex;
  width: 100%;
  min-height: 240px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: var(--cyan);
  text-align: center;
}

.next-wave-ready {
  color: var(--cyan);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  visibility: hidden;
}

.next-wave-panel.is-ready .next-wave-ready {
  visibility: visible;
}

#startButton:hover,
#cpuButton:hover,
#endlessButton:hover,
#hiscoreButton:hover,
#quitButton:hover,
#restartButton:hover,
#postButton:hover,
#resultTopButton:hover,
#rankingButton:hover,
#howToButton:hover,
#nextWaveButton:hover {
  transform: translateY(-1px);
  border-color: var(--line-hot);
  background: rgba(255, 255, 255, 0.96);
}

#startButton:hover {
  color: #ffffff;
  border-color: rgba(34, 83, 95, 0.28);
  background: var(--accent-strong);
}

.mode-actions #hiscoreButton:hover,
.mode-actions #cpuButton:hover,
.mode-actions #endlessButton:hover,
.mode-actions #hiscoreButton.active:hover,
.mode-actions #cpuButton.active:hover,
.mode-actions #endlessButton.active:hover {
  transform: none;
  color: var(--accent-strong);
  border-color: rgba(34, 83, 95, 0.14);
  background: var(--accent-soft);
}

.card:hover {
  transform: translateY(-2px) !important;
  border-color: var(--line-hot);
  background: rgba(255, 255, 255, 0.96);
}

.reader-panel {
  --reader-stage-height: clamp(104px, 13vw, 150px);
  --reader-hud-height: 46px;
  --reader-message-height: 38px;
  margin: 16px 0 22px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--reader-bg);
  min-height: calc(var(--reader-stage-height) + var(--reader-hud-height) + var(--reader-message-height) + 32px);
}

.reader-panel.is-hidden {
  display: none;
}

.countdown-display {
  display: none;
  height: var(--reader-stage-height);
  margin: 4px 0 18px;
  align-items: center;
  justify-content: center;
  color: var(--digit-color);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: clamp(5.8rem, 14vw, 9.5rem);
  line-height: 1;
  letter-spacing: 0;
  text-shadow: var(--digit-shadow);
}

.countdown-display.active {
  display: flex;
  animation: countdownPop 0.72s ease both;
}

#reading {
  display: none;
  justify-content: center;
  align-items: center;
  gap: 0.5em;
  height: var(--reader-stage-height);
  margin: 4px 0 18px;
  text-align: center;
}

.digit {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 clamp(74px, 10vw, 112px);
  width: clamp(74px, 10vw, 112px);
  height: clamp(74px, 10vw, 112px);
  margin: 0;
  border: 1px solid var(--digit-border);
  border-radius: 8px;
  background: var(--digit-bg);
  overflow: hidden;
  text-align: center;
  box-shadow: var(--digit-box-shadow);
  contain: layout paint;
}

.digit .num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--digit-color);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: clamp(4rem, 10vw, 7rem);
  line-height: 1;
  padding-top: 0.12em;
  text-shadow: var(--digit-shadow);
  transform: translateY(100%);
  opacity: 0;
  transition: transform 0.34s cubic-bezier(.2,.9,.1,1), opacity 0.34s;
}

.hud {
  width: min(100%, 760px);
  margin: 0 auto;
  min-height: var(--reader-hud-height);
  align-items: stretch;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

#scoreDisplay,
#scoreDisplayPlayer,
#scoreDisplayCPU,
#waveDisplay,
#lifeDisplay,
#timeDisplay {
  min-width: 150px;
  padding: 10px 14px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: center;
  font-weight: 900;
}

#scoreDisplay { color: var(--green); }
#scoreDisplayPlayer { color: var(--green); }
#scoreDisplayCPU { color: var(--pink); }
#waveDisplay { color: var(--gold); }
#lifeDisplay { color: var(--pink); }
#timeDisplay {
  flex: 1 1 100%;
  width: 100%;
  min-width: min(100%, 420px);
  max-width: 760px;
  color: var(--cyan);
  background:
    linear-gradient(90deg, rgba(47, 111, 123, 0.18) var(--time-progress, 100%), transparent 0),
    var(--hud-bg);
}

#timeDisplay.danger { color: var(--danger); animation: pulseDanger 0.65s infinite; }

#timeDisplay.danger {
  background:
    linear-gradient(90deg, rgba(157, 79, 88, 0.2) var(--time-progress, 100%), transparent 0),
    var(--hud-bg);
}

#lifeDisplay {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

body.game-playing[data-mode="endless"] #lifeDisplay {
  display: inline-flex !important;
}

body.game-playing[data-mode="endless"] #waveDisplay,
body.game-playing[data-mode="endless"] #lifeDisplay,
body.game-playing[data-mode="endless"] #scoreDisplay {
  display: inline-flex !important;
  height: 38px;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.life-label {
  margin-right: 10px;
  font-size: 0.78em;
  color: var(--muted);
}

.life-hearts {
  display: inline-flex;
  gap: 4px;
  color: var(--accent);
  font-size: 1.1em;
  line-height: 1;
}

.life-heart.is-empty {
  color: rgba(47, 111, 123, 0.36);
}

#comboDisplay {
  position: fixed;
  left: 50%;
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 12px));
  z-index: 60;
  width: min(calc(100vw - 32px), 560px);
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--pink);
  text-align: center;
  overflow: visible;
  pointer-events: none;
  transform: translateX(-50%);
}

#comboDisplay span {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: none;
  font-weight: 900;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  transform-origin: center;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

#comboDisplay span.active {
  opacity: 1;
  transform: translateY(0) scale(1);
}

#message {
  display: flex;
  width: min(100%, 520px);
  min-height: var(--reader-message-height);
  margin: 14px auto 0;
  padding: 8px 14px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--message-border);
  border-radius: 6px;
  background: var(--message-bg);
  text-align: center;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

#message:empty {
  visibility: hidden;
}

#message.msg-ready { color: var(--cyan); }
#message.msg-round { color: var(--cyan); }
#message.msg-success { color: var(--green); }
#message.msg-warning { color: var(--danger); }
#message.msg-finish { color: var(--gold); }

#message .msg-main {
  margin-right: 0;
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: 1.15rem;
  letter-spacing: 0;
}

#message .msg-main + .msg-sub {
  margin-left: 0.7em;
}

#message .msg-sub {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin: 22px 0;
}

#karuta {
  position: relative;
}

.cpu-level-panel {
  display: flex;
  width: min(100%, 520px);
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 12px auto 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.cpu-level-panel label {
  color: var(--gold);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: 1.25rem;
  letter-spacing: 0;
}

#cpuLevel {
  min-width: min(100%, 280px);
  padding: 10px 12px;
  border: 1px solid var(--message-border);
  border-radius: 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.86);
  font: inherit;
  font-weight: 800;
}

.cpu-cursor {
  display: none;
  position: absolute;
  z-index: 6;
  width: 34px;
  height: 34px;
  border: 2px solid rgba(47, 111, 123, 0.7);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: top 0.22s ease-out, left 0.22s ease-out;
  background:
    linear-gradient(var(--accent), var(--accent)) center / 2px 12px no-repeat,
    linear-gradient(90deg, var(--accent), var(--accent)) center / 12px 2px no-repeat,
    rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 0 4px rgba(47, 111, 123, 0.06);
  backdrop-filter: blur(1px);
}

.cpu-cursor::after {
  content: "CPU";
  position: absolute;
  top: -20px;
  left: 50%;
  padding: 2px 5px;
  border: 1px solid rgba(47, 111, 123, 0.22);
  border-radius: 4px;
  color: var(--gold);
  background: rgba(255, 255, 255, 0.88);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: 0.78rem;
  line-height: 1;
  letter-spacing: 0;
  transform: translateX(-50%);
}

.cpu-cursor.pulse {
  animation: cpuPulse 0.5s ease-out 1;
}

.battle-summary {
  text-align: center;
}

.battle-summary h3 {
  margin: 0 0 12px;
  color: var(--gold);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: clamp(2.3rem, 7vw, 4rem);
  line-height: 1;
  letter-spacing: 0;
}

.result-scoreline {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 0 0 14px;
}

.result-scoreline span {
  min-width: 150px;
  padding: 10px 14px;
  border: 1px solid var(--message-border);
  border-radius: 6px;
  background: var(--hud-bg);
  font-weight: 900;
}

.speech {
  margin: 12px auto 0;
  padding: 13px 16px;
  border: 1px solid var(--message-border);
  border-radius: 8px;
  background: var(--message-bg);
  color: var(--text);
  line-height: 1.7;
}

.speech .by {
  display: block;
  margin-bottom: 4px;
  color: var(--cyan);
  font-weight: 900;
}

.speech.win,
.speech.lose,
.speech.draw { border-color: var(--message-border); }

.cpu-hit-flash .game-shell {
  animation: cpuHitFlash 0.42s ease;
}

.card {
  flex: 0 0 160px;
  width: 160px;
  position: relative;
  min-width: 0;
  min-height: 104px;
  padding: 14px;
  border: 1px solid rgba(34, 83, 95, 0.16);
  border-radius: 8px;
  color: var(--text);
  background: var(--card-bg);
  box-shadow: 0 1px 3px rgba(31, 83, 103, 0.04);
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transform: none !important;
  transition: border-color 0.14s, opacity 0.18s, background 0.14s;
  will-change: auto;
}

#rankingWrapper,
#resultDisplay {
  margin: 24px 0 0;
  align-items: flex-start;
  flex-wrap: wrap;
}

#rankingWrapper > *,
#resultDisplay > * {
  flex: 1;
  min-width: min(100%, 220px);
  padding: 16px;
  border: 1px solid rgba(34, 83, 95, 0.14);
  border-radius: 8px;
  background: var(--panel-strong);
}

#resultDisplay { display: none; }

.result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 18px 0 0;
}

.result-actions #postButton,
.result-actions #resultTopButton {
  min-width: min(100%, 220px);
}

.resultheading {
  margin: 0 0 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  color: var(--gold);
  font-size: 1rem;
}

ol,
ul { padding-left: 1.4em; }

.highscore-entry {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}

.highscore-score { min-width: 86px; text-align: right; }

.rank-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 8px 0 12px;
}

.rank-tabs .tab-btn {
  padding: 7px 12px;
  border: 1px solid rgba(34, 83, 95, 0.14);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.68);
  cursor: pointer;
}

.rank-tabs .tab-btn.active {
  color: #ffffff;
  border-color: rgba(34, 83, 95, 0.26);
  background: var(--gold);
}

.result-score-summary {
  text-align: center;
}

.result-score-summary .score-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: 1.25rem;
  letter-spacing: 0;
}

.result-score-summary .score-value {
  margin: 0;
  color: var(--gold);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: clamp(2.5rem, 7vw, 4.4rem);
  line-height: 1;
  letter-spacing: 0;
}

.result-score-summary .score-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 800;
}

#highScoreEntryPanel {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

#highScoreEntryPanel[hidden] {
  display: none;
}

#highScoreEntryPanel.is-checking {
  border-top-color: rgba(47, 111, 123, 0.16);
}

.highscore-form {
  display: grid;
  gap: 10px;
}

#highScoreEntryPanel.is-checking .highscore-form {
  gap: 0;
}

#highScoreEntryPanel.is-checking .highscore-form label,
#highScoreEntryPanel.is-checking .name-submit-row {
  display: none;
}

.highscore-form label {
  color: var(--cyan);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: 1.1rem;
  letter-spacing: 0;
}

.name-submit-row {
  display: flex;
  gap: 8px;
}

#highScoreName {
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--message-border);
  border-radius: 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.86);
  font: inherit;
  font-weight: 900;
}

#highScoreSubmit {
  flex: 0 0 auto;
  padding: 11px 14px;
  border: 1px solid rgba(34, 83, 95, 0.26);
  border-radius: 6px;
  color: #ffffff;
  background: var(--gold);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

#highScoreSubmit:disabled {
  opacity: 0.55;
  cursor: wait;
}

#highScoreEntryStatus {
  min-height: 1.4em;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

#highScoreEntryPanel.is-checking #highScoreEntryStatus {
  color: var(--cyan);
}

.credits {
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.credits a {
  color: var(--cyan);
  font-weight: 800;
  text-decoration: none;
}

.credits a:hover {
  color: var(--gold);
}

.modal-note {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.game-modal {
  width: min(980px, calc(100vw - 24px));
  max-height: min(820px, calc(100vh - 24px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  box-shadow: 0 20px 52px rgba(31, 83, 103, 0.18);
}

.game-modal::backdrop {
  background: rgba(232, 244, 248, 0.68);
  backdrop-filter: blur(10px);
}

.modal-frame {
  max-height: inherit;
  overflow: auto;
  padding: clamp(16px, 3vw, 26px);
  background: var(--modal-bg);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  color: var(--gold);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: 2rem;
  letter-spacing: 0;
}

.modal-close {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(34, 83, 95, 0.18);
  border-radius: 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  font-size: 1.4rem;
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.rules-grid section {
  padding: 16px;
  border: 1px solid rgba(34, 83, 95, 0.14);
  border-radius: 8px;
  background: var(--panel-soft);
}

.rules-grid h3 {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 1rem;
}

.rules-grid p { margin: 0; color: var(--muted); }

.shake {
  border-color: rgba(157, 79, 88, 0.72);
  box-shadow: 0 0 0 1px rgba(157, 79, 88, 0.12), 0 0 10px rgba(157, 79, 88, 0.12);
}

.correct {
  border-color: rgba(47, 111, 123, 0.5);
  background: rgba(239, 247, 249, 0.96);
  box-shadow: 0 0 0 1px rgba(47, 111, 123, 0.12), 0 0 18px rgba(47, 111, 123, 0.1);
  opacity: 0;
}
.hit-flash .game-shell { animation: hitFlash 0.42s ease; }
.miss-flash .game-shell { animation: missFlash 0.36s ease; }
.finish-flash .game-shell { animation: finishFlash 0.9s ease; }

.spark,
.pop-text {
  position: fixed;
  z-index: 40;
  pointer-events: none;
}

.spark {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
  animation: sparkFly 0.72s ease-out forwards;
}

.pop-text {
  color: var(--gold);
  font-family: "Bebas Neue", "Noto Sans JP", sans-serif;
  font-size: 1.9rem;
  text-shadow: none;
  animation: popText 0.9s ease-out forwards;
}

@keyframes pulseDanger {
  50% { box-shadow: 0 0 10px rgba(157, 79, 88, 0.18); }
}

@keyframes hitFlash {
  50% { box-shadow: 0 14px 42px rgba(47, 111, 123, 0.1), inset 0 0 22px rgba(47, 111, 123, 0.06); }
}

@keyframes missFlash {
  50% { box-shadow: 0 14px 42px rgba(157, 79, 88, 0.1), inset 0 0 22px rgba(157, 79, 88, 0.06); }
}

@keyframes finishFlash {
  35% { box-shadow: 0 14px 46px rgba(47, 111, 123, 0.1), inset 0 0 24px rgba(47, 111, 123, 0.06); }
}

@keyframes sparkFly {
  to {
    transform: translate(var(--tx), var(--ty)) scale(0);
    opacity: 0;
  }
}

@keyframes popText {
  to {
    transform: translateY(-42px) scale(1.18);
    opacity: 0;
  }
}

@keyframes countdownPop {
  0% { transform: scale(0.82); opacity: 0; }
  35% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.96); opacity: 0.86; }
}

@keyframes cpuPulse {
  0% { box-shadow: 0 0 0 0 rgba(47, 111, 123, 0.24); }
  100% { box-shadow: 0 0 0 16px rgba(47, 111, 123, 0); }
}

@keyframes cpuHitFlash {
  50% { box-shadow: 0 14px 42px rgba(47, 111, 123, 0.1), inset 0 0 22px rgba(47, 111, 123, 0.06); }
}

@media (max-width: 760px) {
  .arena {
    width: min(100% - 14px, 1180px);
    padding-top: 7px;
  }

  .game-shell { padding: 14px; }

  .game-hero {
    gap: 10px;
  }

  .game-logo { max-width: 290px; }

  .topbar,
  #rankingWrapper,
  #resultDisplay {
    flex-direction: column;
  }

  .grid {
    display: flex;
    justify-content: center;
    gap: 10px;
  }

  .card {
    flex-basis: calc(50% - 5px);
    width: calc(50% - 5px);
    min-height: 76px;
    padding: 10px;
    font-size: 0.86rem;
  }

  #startButton,
  #cpuButton,
  #endlessButton,
  #hiscoreButton,
  #quitButton,
  #restartButton,
  #postButton,
  #resultTopButton,
  #rankingButton,
  #howToButton,
  #nextWaveButton {
    width: 100%;
    min-width: 0;
  }

  #rankingWrapper > *,
  #resultDisplay > * {
    width: 100%;
    flex: none;
  }

  .result-actions {
    width: 100%;
    flex-direction: column;
  }

  .reader-panel { padding: 12px; }
  .hud { gap: 8px; }

  #scoreDisplay,
  #scoreDisplayPlayer,
  #scoreDisplayCPU,
  #waveDisplay,
  #lifeDisplay {
    min-width: calc(50% - 8px);
    padding: 8px 10px;
    font-size: 0.9rem;
  }

  #timeDisplay {
    width: 100%;
    min-width: 0;
    max-width: none;
    padding: 8px 10px;
    font-size: 0.9rem;
  }

  #comboDisplay {
    bottom: max(12px, calc(env(safe-area-inset-bottom) + 10px));
    width: min(calc(100vw - 24px), 520px);
  }

  #comboDisplay span {
    padding: 9px 14px;
    font-size: 0.86rem;
  }

  .menu-actions,
  .mode-actions,
  .action-row,
  .cpu-shell .action-row {
    width: 100%;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .cpu-level-panel {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .cpu-level-panel label {
    text-align: center;
  }

  #cpuLevel {
    width: 100%;
  }

  .toggle-stack {
    top: 10px;
    right: 10px;
    width: auto;
    justify-content: flex-end;
  }

  #quitButton,
  #nextWaveButton {
    width: 100%;
  }

  #message {
    padding-inline: 10px;
  }

  #message .msg-main {
    font-size: 1rem;
  }

  #message .msg-sub {
    font-size: 0.74rem;
  }

  .rules-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .arena {
    display: flex;
    width: 100dvw;
    max-width: 420px;
    height: min(100dvh, calc(100dvw * 16 / 9));
    min-height: 0;
    margin: 0 auto;
    padding: 0;
    flex-direction: column;
  }

  .game-shell {
    display: flex;
    height: auto;
    min-height: 0;
    padding: 6px;
    flex: 1 1 auto;
    flex-direction: column;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
    overflow: hidden;
  }

  .game-shell::before {
    display: none;
  }

  #karuta {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
  }

  .game-logo {
    max-width: min(228px, 74vw);
  }

  .game-hero {
    padding-bottom: 10px;
  }

  .topbar {
    gap: 8px;
    margin: 10px 0;
  }

  .game-playing .topbar {
    display: flex;
    height: 0;
    min-height: 0;
    margin: 0;
  }

  .game-playing .status-chip {
    display: none;
  }

  .toggle-stack {
    top: 6px;
    right: 6px;
  }

  .status-chip {
    width: 100%;
    text-align: center;
    font-size: 0.95rem;
  }

  .mode-actions,
  .action-row,
  .cpu-shell .action-row {
    gap: 6px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
  }

  .action-row {
    margin: 4px 0 10px;
  }

  .option-panel {
    width: min(100%, 300px);
    gap: 10px;
    margin: 16px auto 8px;
    padding: 8px;
  }

  .option-title {
    font-size: 0.86rem;
  }

  .voice-options {
    gap: 5px;
  }

  .voice-options legend {
    font-size: 0.75rem;
  }

  .voice-choice {
    min-height: 28px;
    font-size: 0.66rem;
  }

  .voice-choice span {
    min-height: 28px;
  }

  body.game-playing .action-row {
    margin: 4px 0 6px;
  }

  #startButton,
  #cpuButton,
  #endlessButton,
  #hiscoreButton,
  #quitButton,
  #restartButton,
  #postButton,
  #resultTopButton,
  #rankingButton,
  #howToButton,
  #nextWaveButton {
    min-width: 0;
    padding: 9px 6px;
    font-size: 0.72rem;
    line-height: 1.15;
  }

  #quitButton,
  #nextWaveButton {
    width: min(100%, 180px);
  }

  body.game-playing #quitButton,
  body.game-playing #nextWaveButton {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  body.game-playing[data-mode="endless"].awaiting-next-wave #nextWaveButton {
    width: min(100%, 190px);
  }

  .next-wave-panel {
    min-height: 100%;
    gap: 8px;
  }

  .next-wave-ready {
    font-size: 1.22rem;
  }

  .cpu-level-panel {
    margin: 8px auto 0;
    padding: 8px;
  }

  .cpu-level-panel label {
    font-size: 1rem;
  }

  .reader-panel {
    --reader-stage-height: clamp(66px, 16vw, 84px);
    --reader-hud-height: 30px;
    --reader-message-height: 28px;
    margin: 6px 0 4px;
    padding: 8px;
    min-height: calc(var(--reader-stage-height) + var(--reader-hud-height) + var(--reader-message-height) + 20px);
  }

  body.game-playing .reader-panel {
    --reader-stage-height: clamp(58px, 12dvh, 66px);
    margin: 4px 0 3px;
    padding: 7px;
  }

  .countdown-display,
  #reading {
    margin: 0 0 8px;
  }

  .countdown-display {
    font-size: clamp(4.2rem, 22vw, 6rem);
  }

  #reading {
    gap: 0.32em;
  }

  .digit {
    flex-basis: clamp(54px, 17vw, 68px);
    width: clamp(54px, 17vw, 68px);
    height: clamp(54px, 17vw, 68px);
  }

  .digit .num {
    font-size: clamp(3.2rem, 15vw, 4.4rem);
  }

  .hud {
    gap: 3px;
    min-height: 0;
  }

  #scoreDisplay,
  #scoreDisplayPlayer,
  #scoreDisplayCPU,
  #waveDisplay,
  #lifeDisplay {
    flex: 1 1 0;
    min-width: 0;
    height: 30px;
    min-height: 30px;
    padding: 5px 3px;
    font-size: 0.66rem;
    line-height: 1.2;
    white-space: nowrap;
  }

  body.game-playing[data-mode="endless"] #waveDisplay,
  body.game-playing[data-mode="endless"] #lifeDisplay,
  body.game-playing[data-mode="endless"] #scoreDisplay {
    flex: 1 1 0;
    min-width: 0;
    height: 30px;
  }

  body.game-playing[data-mode="endless"] .life-label {
    margin-right: 5px;
  }

  body.game-playing[data-mode="endless"] .life-hearts {
    gap: 2px;
    font-size: 1em;
  }

  #timeDisplay {
    width: 100%;
    min-width: 0;
    min-height: 30px;
    padding: 5px 6px;
    font-size: 0.7rem;
    line-height: 1.2;
  }

  #comboDisplay {
    bottom: max(8px, calc(env(safe-area-inset-bottom) + 6px));
  }

  #comboDisplay span {
    padding: 7px 10px;
    font-size: 0.72rem;
  }

  #message {
    width: 100%;
    min-height: var(--reader-message-height);
    margin-top: 7px;
    padding: 4px 6px;
    font-size: 0.72rem;
  }

  #message .msg-main {
    font-size: 0.9rem;
  }

  #message .msg-sub {
    font-size: 0.66rem;
  }

  .grid {
    flex: 1;
    min-height: 0;
    gap: 6px;
    margin: 4px 0 4px;
    align-content: flex-start;
    overflow: hidden;
  }

  .card {
    flex-basis: calc((100% - 12px) / 3);
    width: calc((100% - 12px) / 3);
    min-height: auto;
    aspect-ratio: 160 / 104;
    padding: 6px 5px;
    border-radius: 6px;
    font-size: 0.65rem;
    line-height: 1.22;
  }

  body.game-playing .grid {
    gap: 5px;
    margin: 3px 0;
  }

  body.game-playing .card {
    --mobile-card-size: max(62px, min(calc((100% - 10px) / 3), calc(38.46dvh - 112px)));
    flex-basis: var(--mobile-card-size);
    width: var(--mobile-card-size);
  }

  .credits {
    display: block;
    flex: 0 0 auto;
    margin: auto 6px 4px;
    font-size: 0.52rem;
    line-height: 1.25;
  }

  .credits p {
    margin: 1px 0;
  }

  body.game-playing .credits {
    display: none;
  }
}

@media (max-width: 380px) {
  .card {
    min-height: 48px;
    font-size: 0.65rem;
  }

  #scoreDisplay,
  #scoreDisplayPlayer,
  #scoreDisplayCPU,
  #waveDisplay,
  #lifeDisplay,
  #timeDisplay {
    font-size: 0.58rem;
  }

  body.game-playing[data-mode="endless"] #waveDisplay,
  body.game-playing[data-mode="endless"] #lifeDisplay,
  body.game-playing[data-mode="endless"] #scoreDisplay {
    padding-inline: 2px;
  }

  body.game-playing[data-mode="endless"] .life-label {
    margin-right: 3px;
  }

  body.game-playing[data-mode="endless"] .life-hearts {
    gap: 1px;
  }
}
