:root {
  --night: #061722;
  --deep-water: #0a2634;
  --water: #16475a;
  --mist: #d7f1ef;
  --slime: #91e5c6;
  --slime-deep: #3ca995;
  --score: #ffd692;
  --danger: #ff8a78;
  font-family: "Yu Gothic UI", "Hiragino Sans", Meiryo, system-ui, sans-serif;
  color: #edf9f7;
  background: var(--night);
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; background: var(--night); }
body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 13% 12%, rgba(76, 157, 164, 0.15), transparent 28rem),
    linear-gradient(180deg, #061722 0%, #091f2b 55%, #061722 100%);
}
button, a, canvas { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
[hidden] { display: none !important; }

.page-shell {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding-bottom: 42px;
}
.topbar {
  min-height: 66px;
  border-bottom: 1px solid rgba(215, 241, 239, 0.14);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: rgba(215, 241, 239, 0.62);
  font: 750 0.63rem/1 ui-monospace, Consolas, monospace;
  letter-spacing: 0.14em;
}
.topbar p { margin: 0; }
.back-link {
  min-height: 44px;
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.back-link:hover, .back-link:focus-visible { color: var(--slime); }
.game-shell { padding-top: clamp(28px, 5vw, 58px); }
.game-heading {
  margin-bottom: 24px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
}
.eyebrow {
  margin: 0 0 8px;
  color: rgba(145, 229, 198, 0.72);
  font: 750 0.59rem/1.4 ui-monospace, Consolas, monospace;
  letter-spacing: 0.17em;
}
h1 {
  margin: 0;
  font-size: clamp(3.2rem, 8vw, 6.8rem);
  line-height: 0.92;
  letter-spacing: -0.08em;
  font-weight: 850;
}
.game-subtitle {
  margin: 13px 0 0;
  color: rgba(215, 241, 239, 0.62);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.meters {
  width: min(650px, 62vw);
  display: grid;
  grid-template-columns: 1.16fr 1.08fr 1.18fr 1.15fr 0.92fr;
  align-items: stretch;
  gap: 8px;
}
.stat-card, .charge-card {
  min-width: 0;
  min-height: 78px;
  padding: 13px 14px;
  border: 1px solid rgba(215, 241, 239, 0.15);
  background: rgba(7, 28, 39, 0.68);
  display: grid;
  align-content: space-between;
  gap: 6px;
}
.charge-card {
  --charge-ui: var(--slime);
  transition: border-color 0.16s ease, background 0.16s ease;
}
.charge-card[data-charge="1"] {
  --charge-ui: #76d8ee;
  border-color: rgba(118, 216, 238, 0.4);
  background: rgba(71, 157, 183, 0.09);
}
.charge-card[data-charge="2"] {
  --charge-ui: #b8adff;
  border-color: rgba(184, 173, 255, 0.44);
  background: rgba(123, 104, 210, 0.1);
}
.charge-card[data-charge="3"] {
  --charge-ui: var(--score);
  border-color: rgba(255, 214, 146, 0.56);
  background: rgba(255, 214, 146, 0.11);
}
.stat-card > span:first-child, .charge-card > span:first-child {
  color: rgba(215, 241, 239, 0.55);
  font: 700 0.58rem/1 ui-monospace, Consolas, monospace;
  letter-spacing: 0.12em;
}
.charge-card > span:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
}
.charge-card > span:first-child b {
  color: var(--charge-ui);
  font: inherit;
  letter-spacing: 0;
  white-space: nowrap;
}
.stat-card > span:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
}
.stat-card > span:first-child b {
  color: rgba(215, 241, 239, 0.76);
  font: inherit;
  letter-spacing: 0;
  white-space: nowrap;
}
.stat-card > span:first-child b.is-stopped {
  color: var(--score);
}
.stat-card strong {
  white-space: nowrap;
  font: 800 0.91rem/1 ui-monospace, Consolas, monospace;
}
.score-card strong, .chain-card strong { color: var(--score); }
.chain-card {
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}
.chain-card.is-active {
  border-color: rgba(255, 214, 146, 0.56);
  background: rgba(255, 214, 146, 0.08);
  box-shadow: inset 0 -2px 0 rgba(255, 214, 146, 0.36);
}
.chain-card.is-urgent {
  border-color: rgba(255, 138, 120, 0.58);
}
.combo-track {
  height: 3px;
  overflow: hidden;
  background: rgba(255, 214, 146, 0.12);
}
.combo-track i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--score);
  transition: width 0.05s linear, background 0.14s ease;
}
.chain-card.is-urgent .combo-track i { background: var(--danger); }
.meter-track { height: 3px; overflow: hidden; background: rgba(215, 241, 239, 0.12); }
.meter-track i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--slime);
  transition: width 0.18s ease;
}
.noise-meter .meter-track i { background: var(--danger); }
.charge-pips { display: flex; gap: 6px; }
.charge-pips i {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(145, 229, 198, 0.38);
  border: 1px solid color-mix(in srgb, var(--charge-ui) 46%, transparent);
  border-radius: 50%;
  transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}
.charge-pips i.is-filled {
  background: var(--charge-ui);
  box-shadow: 0 0 15px rgba(145, 229, 198, 0.45);
  box-shadow: 0 0 15px color-mix(in srgb, var(--charge-ui) 48%, transparent);
  transform: scale(1.08);
}

.game-board {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(215, 241, 239, 0.18);
  background: var(--deep-water);
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.32);
  isolation: isolate;
}
.game-board::after {
  content: "";
  position: absolute;
  inset: 12px;
  z-index: 2;
  border: 1px solid rgba(215, 241, 239, 0.08);
  pointer-events: none;
}
#game-canvas {
  width: 100%;
  aspect-ratio: 10 / 7;
  display: block;
  touch-action: none;
  cursor: grab;
  outline: none;
}
#game-canvas.is-absorbing { cursor: grabbing; }
#game-canvas:focus-visible { box-shadow: inset 0 0 0 3px rgba(145, 229, 198, 0.78); }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  padding: 24px;
  background: rgba(3, 16, 25, 0.56);
  backdrop-filter: blur(7px);
  display: grid;
  place-items: center;
}
.overlay-card {
  width: min(510px, 100%);
  padding: clamp(26px, 5vw, 48px);
  border: 1px solid rgba(215, 241, 239, 0.26);
  background:
    linear-gradient(135deg, rgba(145, 229, 198, 0.08), transparent 48%),
    rgba(5, 25, 36, 0.94);
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
}
.overlay-kicker {
  margin: 0 0 14px;
  color: var(--slime);
  font: 750 0.58rem/1.4 ui-monospace, Consolas, monospace;
  letter-spacing: 0.18em;
}
.overlay-card h2 {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 3.25rem);
  line-height: 1.18;
  letter-spacing: -0.055em;
}
.overlay-card > p:not(.overlay-kicker):not(.result-score) {
  margin: 19px 0 0;
  color: rgba(237, 249, 247, 0.72);
  font-size: 0.88rem;
  line-height: 1.85;
}
.how-to-steps {
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  gap: 7px;
  list-style: none;
  text-align: left;
}
.how-to-steps li {
  min-height: 45px;
  padding: 7px 10px;
  border: 1px solid rgba(215, 241, 239, 0.13);
  background: rgba(215, 241, 239, 0.035);
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 9px;
  color: rgba(215, 241, 239, 0.6);
  font-size: 0.67rem;
  line-height: 1.35;
}
.how-to-steps b {
  width: 26px;
  height: 26px;
  border: 1px solid rgba(145, 229, 198, 0.48);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--slime);
  font: 800 0.68rem/1 ui-monospace, Consolas, monospace;
}
.how-to-steps span,
.how-to-steps strong { display: block; }
.how-to-steps strong {
  margin-bottom: 1px;
  color: rgba(237, 249, 247, 0.92);
  font-size: 0.78rem;
}
.overlay-card .opening-tip {
  margin-top: 12px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 214, 146, 0.28);
  background: rgba(255, 214, 146, 0.07);
  color: rgba(237, 249, 247, 0.84);
  font-size: 0.72rem;
  line-height: 1.55;
}
.opening-tip strong {
  display: block;
  margin-bottom: 2px;
  color: var(--score);
  font: 800 0.56rem/1.4 ui-monospace, Consolas, monospace;
  letter-spacing: 0.12em;
}
.overlay-card small {
  display: block;
  margin-top: 14px;
  color: rgba(215, 241, 239, 0.46);
  font: 650 0.56rem/1.4 ui-monospace, Consolas, monospace;
  letter-spacing: 0.08em;
}
.primary-button {
  min-width: 210px;
  min-height: 50px;
  margin-top: 26px;
  padding: 0 24px;
  border: 0;
  background: var(--slime);
  color: #071c26;
  font-weight: 850;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.primary-button:hover, .primary-button:focus-visible {
  transform: translate(-3px, -3px);
  box-shadow: 7px 7px 0 rgba(255, 214, 146, 0.62);
  outline: none;
}
.result-card { border-color: rgba(255, 214, 146, 0.34); }
.result-score {
  margin: 0 0 10px;
  color: var(--score);
  font: 850 clamp(2.6rem, 8vw, 5.4rem)/1 ui-monospace, Consolas, monospace;
  letter-spacing: -0.08em;
}

.game-footer {
  min-height: 74px;
  padding: 18px 4px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}
.game-status, .control-hint {
  margin: 0;
  color: rgba(215, 241, 239, 0.62);
  font-size: 0.74rem;
  line-height: 1.7;
}
.game-status {
  max-width: 540px;
  color: rgba(237, 249, 247, 0.82);
  font-weight: 650;
}
.control-hint { text-align: right; font-family: ui-monospace, Consolas, monospace; }
.control-hint span { color: var(--slime); }

@media (max-width: 980px) {
  .game-heading { align-items: stretch; flex-direction: column; gap: 20px; }
  .meters { width: 100%; }
}

@media (max-width: 760px) {
  .page-shell { width: min(100% - 24px, 1120px); padding-bottom: 24px; }
  .topbar { min-height: 56px; }
  .game-shell { padding-top: 24px; }
  h1 { font-size: clamp(3.6rem, 18vw, 5.4rem); }
  .meters { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .score-card, .best-card, .chain-card { grid-column: span 2; }
  .noise-meter, .charge-card { grid-column: span 3; }
  .stat-card, .charge-card { min-height: 64px; padding: 10px 11px; }
  .charge-pips { gap: 4px; }
  .charge-pips i { width: 14px; height: 14px; }
  .overlay { padding: 12px; }
  .overlay-card { padding: 22px 18px; }
  .overlay-card > p:not(.overlay-kicker):not(.result-score) {
    margin-top: 14px;
    font-size: 0.78rem;
    line-height: 1.65;
  }
  .overlay-card .opening-tip { margin-top: 9px; padding: 7px 9px; }
  .how-to-steps { margin-top: 12px; gap: 5px; }
  .how-to-steps li { min-height: 40px; padding: 5px 8px; }
  .primary-button { min-height: 46px; margin-top: 19px; }
  .game-footer { flex-direction: column; gap: 8px; }
  .control-hint { text-align: left; }
}

@media (max-width: 430px) {
  .topbar p { font-size: 0.55rem; }
  .game-subtitle { margin-top: 9px; }
  .meters { gap: 5px; }
  .stat-card strong { font-size: 0.76rem; }
  .game-board::after { inset: 7px; }
  .overlay { padding: 4px; }
  .overlay-card { padding: 7px 10px; }
  .overlay-kicker { margin-bottom: 3px; font-size: 0.42rem; }
  .overlay-card h2 { font-size: 1.08rem; line-height: 1.03; }
  .overlay-card > p:not(.overlay-kicker):not(.result-score) {
    margin-top: 4px;
    font-size: 0.61rem;
    line-height: 1.3;
  }
  .overlay-card .opening-tip {
    margin-top: 4px;
    padding: 3px 5px;
    font-size: 0.5rem;
    line-height: 1.2;
  }
  .how-to-steps { margin-top: 4px; gap: 2px; }
  .how-to-steps li {
    min-height: 25px;
    padding: 2px 5px;
    grid-template-columns: 19px 1fr;
    gap: 5px;
    font-size: 0.48rem;
    line-height: 1.1;
  }
  .how-to-steps b { width: 18px; height: 18px; font-size: 0.52rem; }
  .how-to-steps strong { font-size: 0.56rem; }
  .opening-tip strong { display: inline; margin: 0 0.55em 0 0; font-size: 0.43rem; }
  .primary-button { min-width: 180px; min-height: 38px; margin-top: 6px; }
  .overlay-card small { margin-top: 3px; font-size: 0.42rem; }
  .result-score { margin-bottom: 5px; font-size: 2.5rem; }
}

@media (max-width: 350px) {
  #intro-panel .overlay-kicker,
  #intro-panel small { display: none; }
  .overlay-card h2 { font-size: 0.98rem; }
  .primary-button { min-height: 36px; margin-top: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
