:root {
  color-scheme: dark;
  --ink: #090b1b;
  --panel: #11152b;
  --panel-soft: #181d39;
  --paper: #f5f5ff;
  --muted: #a9b0d0;
  --line: rgba(210, 219, 255, 0.18);
  --phase-one: #63e6ff;
  --phase-two: #ff61bd;
  --phase-three: #ffd166;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe 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 10% 8%, rgba(99, 230, 255, 0.15), transparent 28rem),
    radial-gradient(circle at 92% 28%, rgba(255, 97, 189, 0.13), transparent 32rem),
    linear-gradient(150deg, #090b1b 0%, #0d1024 52%, #080914 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: 750 0.68rem/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.12em;
}

.workspace-link { color: var(--paper); text-decoration: none; }
.workspace-link:hover { color: var(--phase-one); }
.topbar-actions { display: flex; align-items: center; gap: 18px; color: var(--muted); }

.text-button {
  min-height: 38px;
  padding: 0 13px;
  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(--phase-one); outline: none; }

.game-layout {
  min-height: calc(100vh - 138px);
  padding: clamp(34px, 6vw, 76px) 0;
  display: grid;
  grid-template-columns: minmax(270px, 0.82fr) minmax(360px, 0.68fr);
  align-items: center;
  gap: clamp(34px, 7vw, 96px);
}

.game-copy { min-width: 0; }

.eyebrow, .overlay-kicker {
  margin: 0;
  color: var(--phase-three);
  font: 800 0.65rem/1.3 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.17em;
}

.game-copy h1 {
  margin: 18px 0 24px;
  font-size: clamp(4rem, 9vw, 7.7rem);
  line-height: 0.79;
  letter-spacing: -0.1em;
  text-shadow: 0 0 45px rgba(99, 230, 255, 0.14);
}

.lead {
  max-width: 32rem;
  margin: 0;
  color: #d9ddf2;
  font-size: clamp(0.95rem, 1.6vw, 1.08rem);
  font-weight: 650;
  line-height: 1.9;
}

.phase-legend { margin-top: 30px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.phase-arrow { color: #697194; font-weight: 900; }

.phase-chip {
  min-height: 34px;
  padding: 5px 9px;
  border: 1px solid currentColor;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: 800 0.58rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.08em;
}

.phase-chip b {
  width: 21px;
  height: 21px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: currentColor;
}

.phase-one { color: var(--phase-one); }
.phase-two { color: var(--phase-two); }
.phase-three { color: var(--phase-three); }

.rule-card {
  max-width: 32rem;
  margin-top: 26px;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: rgba(18, 22, 46, 0.82);
}

.rule-card p {
  min-height: 45px;
  margin: 0;
  padding: 10px 13px;
  display: grid;
  grid-template-columns: 45px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.76rem;
}

.rule-card p + p { border-top: 1px solid var(--line); }
.rule-card b { color: var(--paper); font: 850 0.76rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.rule-card .is-best { color: #fff; background: linear-gradient(90deg, rgba(99, 230, 255, 0.13), rgba(255, 97, 189, 0.12)); }
.rule-card .is-best b { color: var(--phase-three); }

.keyboard-guide, .status-line {
  max-width: 32rem;
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.65;
}

.keyboard-guide { margin: 20px 0 0; }
.status-line { min-height: 2.5em; margin: 9px 0 0; color: #dce1fa; font-weight: 700; }

kbd {
  min-width: 23px;
  min-height: 23px;
  padding: 3px 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-bottom-width: 2px;
  border-radius: 5px;
  display: inline-grid;
  place-items: center;
  color: var(--paper);
  background: rgba(255, 255, 255, 0.07);
  font: 800 0.67rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.battle-panel { width: min(100%, 446px); justify-self: center; }

.battle-readout {
  min-height: 54px;
  margin-bottom: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  display: grid;
  grid-template-columns: 1fr 0.8fr 1fr;
  align-items: center;
  background: rgba(16, 20, 42, 0.9);
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.2);
}

.battle-readout > div { display: grid; grid-template-columns: auto auto; align-items: baseline; justify-content: center; column-gap: 5px; }
.battle-readout span { grid-column: 1 / -1; color: var(--muted); font: 800 0.52rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 0.12em; }
.battle-readout strong { font: 850 1.28rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.battle-readout small { color: var(--muted); font: 750 0.5rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.battle-readout > div:first-child strong { color: var(--phase-two); }
.battle-readout > div:last-child strong { color: var(--phase-one); }

.arena-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 1px solid rgba(214, 223, 255, 0.28);
  border-radius: 24px;
  background: #080a18;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42), 0 0 0 5px rgba(255, 255, 255, 0.025);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#game-canvas:active { cursor: grabbing; }
#game-canvas:focus-visible { outline: 3px solid var(--phase-three); outline-offset: -5px; }

.stage-overlay {
  position: absolute;
  inset: 0;
  z-index: 12;
  padding: 28px;
  display: grid;
  place-items: center;
  background: linear-gradient(rgba(7, 9, 23, 0.45), rgba(7, 9, 23, 0.82));
  backdrop-filter: blur(5px);
}

.stage-overlay[hidden] { display: none; }

.overlay-card {
  width: min(100%, 338px);
  padding: clamp(24px, 7vw, 38px);
  border: 1px solid rgba(222, 227, 255, 0.25);
  border-radius: 22px;
  text-align: center;
  background: rgba(16, 20, 42, 0.94);
  box-shadow: 0 22px 65px rgba(0, 0, 0, 0.38);
}

.overlay-card h2 { margin: 14px 0 16px; font-size: clamp(2.15rem, 8vw, 3.25rem); line-height: 0.96; letter-spacing: -0.07em; }
.overlay-card > p:not(.overlay-kicker):not(.result-time) { margin: 0; color: #cfd4ea; font-size: 0.82rem; line-height: 1.75; }
.overlay-card small { margin-top: 13px; display: block; color: var(--muted); font-size: 0.65rem; line-height: 1.5; }

.primary-button {
  width: 100%;
  min-height: 54px;
  margin-top: 24px;
  border: 0;
  border-radius: 12px;
  color: #080a18;
  background: linear-gradient(105deg, var(--phase-one), #b8f4ff 48%, var(--phase-three));
  box-shadow: 0 12px 30px rgba(99, 230, 255, 0.2);
  font-weight: 900;
  cursor: pointer;
}

.primary-button:hover, .primary-button:focus-visible { transform: translateY(-2px); box-shadow: 0 15px 34px rgba(99, 230, 255, 0.31); outline: none; }

.result-time { margin: 8px 0 14px; }
.result-time strong { color: var(--phase-three); font: 900 clamp(3rem, 12vw, 4.7rem)/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.result-time span { margin-left: 6px; color: var(--muted); font: 800 0.65rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.result-stats { margin-top: 17px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.result-stats span { padding: 9px 6px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); font-size: 0.63rem; }
.result-stats b { margin-left: 4px; color: var(--paper); }

.stage-callout {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: 14px;
  min-height: 30px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: var(--paper);
  background: rgba(9, 11, 27, 0.78);
  font: 800 0.58rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.08em;
  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); }

.control-strip {
  min-height: 50px;
  margin-top: 10px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  background: rgba(16, 20, 42, 0.82);
  font-size: 0.67rem;
  line-height: 1.45;
}

.control-strip p { margin: 0; }
.control-strip p b { color: var(--phase-three); }
.control-strip > span { flex: 0 0 auto; font: 800 0.57rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 0.08em; }
.control-strip > span b { color: var(--paper); }

footer {
  min-height: 72px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #707999;
  font: 700 0.58rem/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(215, 223, 255, 0.28);
  border-radius: 22px;
  color: var(--paper);
  background: #13172e;
  box-shadow: 0 35px 100px rgba(0, 0, 0, 0.58);
}

.help-dialog::backdrop { background: rgba(4, 5, 13, 0.75); backdrop-filter: blur(5px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.dialog-close { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; color: var(--paper); background: transparent; font-size: 1.35rem; cursor: pointer; }
.help-dialog h2 { margin: 18px 0 24px; font-size: clamp(2rem, 7vw, 3.4rem); letter-spacing: -0.06em; }
.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: 32px 1fr; gap: 11px; }
.help-dialog li > span { color: var(--phase-three); font: 850 0.62rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.help-dialog li p, .help-dialog > p { margin: 0; color: #cfd4e8; font-size: 0.78rem; 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: 590px; margin: 0 auto; }
  .game-copy h1 br { display: none; }
  .battle-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: 30px 0 42px; }
  .game-copy h1 { font-size: clamp(3.8rem, 22vw, 5.4rem); }
  .lead br { display: none; }
  .keyboard-guide { display: none; }
  .arena-wrap { border-radius: 18px; }
  .stage-overlay { padding: 18px; }
  .overlay-card { padding: 24px 20px; }
  .control-strip { align-items: flex-start; }
  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; }
}
