:root {
  color-scheme: dark;
  --ink: #0e211c;
  --deep: #173029;
  --panel: #1d3a32;
  --paper: #fff9eb;
  --cream: #f4e5c5;
  --muted: #b9c9bf;
  --line: rgba(240, 234, 207, 0.18);
  --bell: #ffd45f;
  --bell-deep: #d98f2d;
  --mint: #77d8ad;
  --mint-deep: #2d8569;
  --coral: #ff7e72;
  --blue: #7fc8d9;
  font-family: Inter, ui-rounded, "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  color: var(--paper);
  background: var(--ink);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--ink); }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 212, 95, 0.14), transparent 29rem),
    radial-gradient(circle at 92% 32%, rgba(119, 216, 173, 0.12), transparent 34rem),
    linear-gradient(145deg, #0e211c 0%, #173029 52%, #0b1b17 100%);
}

button, canvas { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.page-shell { width: min(1180px, calc(100% - 36px)); margin: 0 auto; }

.topbar {
  min-height: 66px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  font: 800 0.66rem/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.13em;
}

.workspace-link { color: var(--paper); text-decoration: none; }
.workspace-link:hover, .workspace-link:focus-visible { color: var(--bell); outline: none; }
.topbar-actions { display: flex; align-items: center; gap: 18px; color: var(--muted); }

.text-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--paper);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.text-button:hover, .text-button:focus-visible {
  border-color: var(--bell);
  color: var(--bell);
  outline: none;
}

.game-layout {
  min-height: calc(100vh - 138px);
  padding: clamp(34px, 6vw, 72px) 0;
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 0.68fr);
  align-items: center;
  gap: clamp(36px, 7vw, 92px);
}

.game-copy { min-width: 0; }

.eyebrow, .overlay-kicker {
  margin: 0;
  color: var(--bell);
  font: 900 0.64rem/1.35 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.17em;
}

.game-copy h1 {
  margin: 18px 0 24px;
  font-size: clamp(4rem, 8.2vw, 7.3rem);
  line-height: 0.86;
  letter-spacing: -0.095em;
  text-shadow: 0 9px 36px rgba(0, 0, 0, 0.25);
}

.lead {
  max-width: 34rem;
  margin: 0;
  color: #e1ebe3;
  font-size: clamp(0.94rem, 1.55vw, 1.07rem);
  font-weight: 650;
  line-height: 1.9;
}

.score-legend {
  margin-top: 26px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend-chip {
  min-height: 37px;
  padding: 6px 10px 6px 7px;
  border: 1px solid currentColor;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: 800 0.66rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.04em;
}

.legend-chip i {
  width: 23px;
  height: 23px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: currentColor;
  font-style: normal;
  font-weight: 950;
}

.legend-chip b { margin-left: 2px; color: var(--paper); }
.food-chip { color: var(--mint); }
.group-chip { color: var(--bell); }
.hazard-chip { color: var(--coral); }
.time-chip { color: var(--blue); }

.rhythm-card {
  max-width: 34rem;
  margin-top: 26px;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: rgba(21, 48, 40, 0.72);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.14);
}

.rhythm-card > div {
  min-height: 56px;
  padding: 10px 13px;
  display: grid;
  grid-template-columns: 34px minmax(100px, 0.8fr) 1.2fr;
  align-items: center;
  gap: 9px;
}

.rhythm-card > div + div { border-top: 1px solid var(--line); }
.rhythm-card b { color: var(--bell); font: 900 0.62rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.rhythm-card span { color: var(--paper); font-size: 0.76rem; font-weight: 850; }
.rhythm-card small { color: var(--muted); font-size: 0.67rem; line-height: 1.45; }

.keyboard-guide, .status-line {
  max-width: 34rem;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.65;
}

.keyboard-guide { margin: 19px 0 0; }
.status-line { min-height: 2.5em; margin: 9px 0 0; color: #e4ede7; font-weight: 750; }

kbd {
  min-width: 24px;
  min-height: 24px;
  margin: 0 1px;
  padding: 3px 6px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-bottom-width: 2px;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  color: var(--paper);
  background: rgba(255, 255, 255, 0.07);
  font: 800 0.64rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.play-panel { width: min(100%, 446px); justify-self: center; }

.game-readout {
  min-height: 56px;
  margin-bottom: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  background: rgba(20, 46, 38, 0.9);
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.2);
}

.game-readout > div {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  justify-content: center;
  column-gap: 5px;
}

.game-readout > div + div { border-left: 1px solid var(--line); }
.game-readout span { grid-column: 1 / -1; color: var(--muted); font: 850 0.52rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 0.13em; }
.game-readout strong { color: var(--mint); font: 900 1.18rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.game-readout small { color: var(--muted); font: 750 0.5rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.game-readout .time-readout strong { color: var(--bell); }
.game-readout .team-readout strong { color: var(--blue); transition: color 0.16s ease, transform 0.16s ease; }
.game-readout .team-readout strong.is-active { color: var(--bell); transform: scale(1.15); }

.arena-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 1px solid rgba(246, 236, 205, 0.36);
  border-radius: 25px;
  background: #ecd9b5;
  box-shadow: 0 30px 82px rgba(0, 0, 0, 0.38), 0 0 0 5px rgba(255, 255, 255, 0.025);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

#game-canvas:focus-visible { outline: 3px solid var(--bell); outline-offset: -6px; }

.stage-overlay {
  position: absolute;
  inset: 0;
  z-index: 12;
  padding: 25px;
  display: grid;
  place-items: center;
  background: linear-gradient(rgba(14, 33, 28, 0.48), rgba(14, 33, 28, 0.88));
  backdrop-filter: blur(5px);
}

.stage-overlay[hidden] { display: none; }

.overlay-card {
  width: min(100%, 344px);
  padding: clamp(24px, 7vw, 38px);
  border: 1px solid rgba(255, 246, 219, 0.24);
  border-radius: 24px;
  text-align: center;
  background: rgba(22, 52, 43, 0.96);
  box-shadow: 0 24px 68px rgba(0, 0, 0, 0.34);
}

.overlay-card h2 {
  margin: 13px 0 16px;
  font-size: clamp(2.15rem, 8vw, 3.25rem);
  line-height: 0.98;
  letter-spacing: -0.07em;
}

.overlay-card > p:not(.overlay-kicker):not(.result-score) { margin: 0; color: #d9e6dd; font-size: 0.81rem; line-height: 1.75; }
.overlay-card small { margin-top: 13px; display: block; color: var(--muted); font-size: 0.64rem; line-height: 1.5; }

.bell-mark {
  position: relative;
  width: 70px;
  height: 64px;
  margin: 20px auto 6px;
  border: 3px solid #6f4b22;
  border-radius: 38px 38px 16px 16px;
  background: linear-gradient(135deg, #fff0a6, var(--bell) 48%, #e79a35);
  box-shadow: inset 7px 5px 0 rgba(255, 255, 255, 0.32), 0 12px 24px rgba(0, 0, 0, 0.25);
  clip-path: polygon(22% 8%, 78% 8%, 88% 73%, 100% 88%, 0 88%, 12% 73%);
}

.bell-mark::before { position: absolute; left: 28px; top: -14px; width: 15px; height: 20px; border: 3px solid #6f4b22; border-radius: 50% 50% 0 0; background: var(--bell); content: ""; }
.bell-mark span { position: absolute; left: 29px; bottom: 0; width: 15px; height: 15px; border: 3px solid #6f4b22; border-radius: 50%; background: #f0a235; }

.primary-button {
  width: 100%;
  min-height: 56px;
  margin-top: 24px;
  border: 0;
  border-radius: 13px;
  color: #10231d;
  background: linear-gradient(105deg, var(--bell), #ffe9a2 48%, var(--mint));
  box-shadow: 0 12px 30px rgba(255, 212, 95, 0.18);
  font-weight: 950;
  cursor: pointer;
}

.primary-button:hover, .primary-button:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 15px 36px rgba(255, 212, 95, 0.28);
  outline: none;
}

.result-score { margin: 8px 0 15px; }
.result-score strong { color: var(--bell); font: 950 clamp(3.4rem, 13vw, 5rem)/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.result-score span { margin-left: 6px; color: var(--muted); font: 850 0.64rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.result-stats { margin: 0 0 16px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.result-stats span { padding: 9px 4px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); font-size: 0.59rem; }
.result-stats b { margin-left: 3px; color: var(--paper); }

.stage-callout {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: 14px;
  min-height: 31px;
  padding: 8px 13px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  color: var(--paper);
  background: rgba(14, 33, 28, 0.84);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  font: 850 0.59rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.07em;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.stage-callout.is-visible { opacity: 1; transform: translate(-50%, 0); }

.ready-strip {
  min-height: 59px;
  margin-top: 10px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  display: grid;
  grid-template-columns: auto minmax(90px, 1fr);
  align-items: center;
  gap: 5px 13px;
  background: rgba(20, 46, 38, 0.88);
}

.ready-copy { grid-row: 1 / 3; min-width: 66px; display: grid; gap: 3px; }
.ready-copy span { color: var(--muted); font: 850 0.5rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 0.14em; }
.ready-copy b { color: var(--bell); font: 950 0.76rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 0.09em; }
.ready-track { height: 8px; overflow: hidden; border-radius: 999px; background: rgba(255, 255, 255, 0.09); }
.ready-track i { width: 100%; height: 100%; display: block; border-radius: inherit; background: linear-gradient(90deg, var(--mint-deep), var(--bell)); transform-origin: left center; transform: scaleX(1); }
.ready-strip p { margin: 0; color: var(--muted); font-size: 0.61rem; line-height: 1.3; }

footer {
  min-height: 72px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #789187;
  font: 750 0.57rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.11em;
}

.help-dialog {
  width: min(620px, calc(100% - 28px));
  max-height: min(780px, calc(100vh - 28px));
  padding: clamp(22px, 5vw, 38px);
  border: 1px solid rgba(255, 246, 219, 0.26);
  border-radius: 23px;
  color: var(--paper);
  background: #17372e;
  box-shadow: 0 35px 100px rgba(0, 0, 0, 0.58);
}

.help-dialog::backdrop { background: rgba(5, 15, 12, 0.76); backdrop-filter: blur(5px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.dialog-close { width: 43px; height: 43px; border: 1px solid var(--line); border-radius: 50%; color: var(--paper); background: transparent; font-size: 1.35rem; cursor: pointer; }
.dialog-close:hover, .dialog-close:focus-visible { border-color: var(--bell); color: var(--bell); outline: none; }
.help-dialog h2 { margin: 18px 0 24px; font-size: clamp(2rem, 7vw, 3.35rem); letter-spacing: -0.065em; }
.help-dialog ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 9px; }
.help-dialog li { padding: 12px; border: 1px solid var(--line); border-radius: 12px; display: grid; grid-template-columns: 34px 1fr; gap: 11px; }
.help-dialog li > span { color: var(--bell); font: 900 0.62rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.help-dialog li p, .help-dialog > p { margin: 0; color: #d7e4dc; font-size: 0.77rem; line-height: 1.7; }
.help-dialog > p { margin-top: 17px; }

@media (max-width: 900px) {
  .game-layout { grid-template-columns: 1fr; gap: 34px; }
  .game-copy { max-width: 610px; margin: 0 auto; }
  .play-panel { width: min(100%, 430px); }
}

@media (max-width: 520px) {
  .page-shell { width: min(100% - 22px, 1180px); }
  .topbar { min-height: 58px; }
  .topbar-actions { gap: 10px; }
  .game-layout { padding: 29px 0 42px; }
  .game-copy h1 { font-size: clamp(3.55rem, 19vw, 5.1rem); }
  .lead br { display: none; }
  .rhythm-card > div { grid-template-columns: 30px 1fr; }
  .rhythm-card small { grid-column: 2; }
  .keyboard-guide { display: none; }
  .arena-wrap { border-radius: 19px; }
  .stage-overlay { padding: 17px; }
  .overlay-card { padding: 24px 20px; }
  footer { padding: 18px 0; align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
