* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #09051f;
  --panel: rgba(7, 10, 35, 0.76);
  --panel-strong: rgba(10, 18, 54, 0.92);
  --line: rgba(125, 227, 255, 0.28);
  --line-strong: rgba(255, 255, 255, 0.36);
  --text: #f6fbff;
  --muted: #9eb4d5;
  --cyan: #20d7ff;
  --magenta: #ff3fcf;
  --gold: #ffb52e;
  --danger: #ff4d6d;
  --radius: 8px;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(58, 38, 126, 0.85), transparent 34rem),
    linear-gradient(180deg, #050414 0%, #09051f 54%, #110724 100%);
  color: var(--text);
  font-family: "Segoe UI", Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: 0;
  touch-action: none;
}

button {
  font: inherit;
}

.game-frame {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 320px;
  background:
    linear-gradient(90deg, rgba(255, 63, 207, 0.08), transparent 20%, transparent 80%, rgba(32, 215, 255, 0.08)),
    #08051b;
}

.topbar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 68px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(5, 8, 28, 0.98), rgba(7, 9, 32, 0.78));
  border-bottom: 1px solid var(--line);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.32);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #fff;
  font-size: clamp(16px, 2.2vw, 24px);
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.brand-mark,
.panel-mark {
  width: 26px;
  height: 26px;
  display: inline-block;
  background: conic-gradient(from 45deg, var(--cyan), var(--magenta), var(--gold), var(--cyan));
  clip-path: polygon(50% 0, 100% 86%, 50% 66%, 0 86%);
  filter: drop-shadow(0 0 14px rgba(32, 215, 255, 0.62));
}

.hud {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(9, minmax(58px, 1fr));
  gap: 8px;
  margin: 0;
}

.hud div {
  min-width: 0;
  padding: 7px 9px 8px;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.hud dt {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.hud dd {
  margin: 0;
  min-height: 18px;
  color: #fff;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
  font-weight: 900;
  line-height: 1.05;
}

.bomb-readout {
  border-color: rgba(255, 181, 46, 0.34) !important;
  background: linear-gradient(180deg, rgba(255, 181, 46, 0.14), rgba(255, 63, 207, 0.08)) !important;
}

.bomb-readout dd {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(255, 181, 46, 0.42);
}

.roll-readout dd,
.boss-readout dd,
.meter-readout dd {
  height: 12px;
  min-height: 12px;
  margin-top: 7px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}

.roll-readout span,
.boss-readout span,
.meter-readout span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  box-shadow: 0 0 16px rgba(32, 215, 255, 0.45);
  transform-origin: left center;
}

.boss-readout span {
  background: linear-gradient(90deg, var(--danger), var(--gold));
}

.boss-readout:not([hidden]) {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding-block: 6px;
}

.boss-readout:not([hidden]) dt {
  margin: 0;
  color: #ffd8e1;
}

.boss-readout:not([hidden]) dd {
  margin: 0;
  height: 13px;
}

.meter-readout span {
  background: linear-gradient(90deg, var(--gold), var(--cyan));
}

.buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
}

.icon-button,
.boost-touch,
.roll-touch,
.bomb-touch {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  color: #dff9ff;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 130ms ease, border-color 130ms ease, background 130ms ease;
}

.icon-button:hover,
.boost-touch:hover,
.roll-touch:hover,
.bomb-touch:hover {
  transform: translateY(-1px);
  border-color: rgba(32, 215, 255, 0.72);
  background: rgba(32, 215, 255, 0.14);
}

.icon-button:active,
.boost-touch:active,
.roll-touch:active,
.bomb-touch:active {
  transform: translateY(0);
}

.icon-button svg,
.boost-touch svg,
.roll-touch svg,
.bomb-touch svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mute-slash {
  opacity: 0;
}

[aria-pressed="true"] .sound-wave {
  opacity: 0;
}

[aria-pressed="true"] .mute-slash {
  opacity: 1;
}

.playfield {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  background: #060416;
}

.roll-touch,
.boost-touch,
.bomb-touch {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 4;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(4, 12, 35, 0.68);
  border-color: rgba(32, 215, 255, 0.38);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.36), inset 0 0 16px rgba(32, 215, 255, 0.12);
  display: none;
}

.boost-touch {
  right: 88px;
  color: #fff4ce;
  border-color: rgba(255, 181, 46, 0.42);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.36), inset 0 0 16px rgba(255, 181, 46, 0.12);
}

.bomb-touch {
  right: auto;
  left: 18px;
  color: #ffd8f5;
  border-color: rgba(255, 63, 207, 0.48);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.36), inset 0 0 16px rgba(255, 63, 207, 0.16);
}

.toast {
  position: absolute;
  left: 50%;
  top: 20px;
  z-index: 4;
  max-width: min(420px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 10px 14px;
  color: #fff;
  background: rgba(6, 14, 42, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.32);
}

.combo-splash {
  position: absolute;
  left: 50%;
  top: 30%;
  z-index: 4;
  display: grid;
  gap: 2px;
  pointer-events: none;
  text-align: center;
  text-transform: uppercase;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 10px 28px rgba(0, 0, 0, 0.5));
}

.combo-splash[hidden] {
  display: none;
}

.combo-splash strong {
  display: block;
  color: var(--gold);
  font-size: clamp(30px, 4.8vw, 58px);
  font-weight: 950;
  line-height: 0.9;
  text-shadow:
    0 0 4px rgba(255, 255, 255, 0.9),
    0 0 18px rgba(255, 181, 46, 0.7),
    0 6px 0 rgba(6, 8, 24, 0.64);
}

.combo-splash span {
  color: #dffaff;
  font-size: clamp(12px, 1.6vw, 18px);
  font-weight: 950;
  text-shadow: 0 0 14px rgba(32, 215, 255, 0.8);
}

.combo-splash.is-hot strong {
  color: var(--magenta);
  text-shadow:
    0 0 4px rgba(255, 255, 255, 0.9),
    0 0 18px rgba(255, 63, 207, 0.78),
    0 6px 0 rgba(6, 8, 24, 0.64);
}

.combo-splash.is-popping {
  animation: combo-pop 420ms cubic-bezier(0.2, 1.34, 0.28, 1) both;
}

@keyframes combo-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.72) rotate(-4deg);
  }
  56% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.14) rotate(2deg);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
  }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 63, 207, 0.2), transparent 22rem),
    rgba(4, 5, 18, 0.74);
  backdrop-filter: blur(5px);
}

.overlay[hidden] {
  display: none;
}

.overlay-panel {
  width: min(540px, 100%);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  padding: clamp(22px, 4vw, 34px);
  background: linear-gradient(180deg, rgba(14, 20, 62, 0.94), rgba(8, 11, 37, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 34px 80px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.09);
}

.overlay--start .overlay-panel {
  width: min(640px, 100%);
  padding: clamp(18px, 3vw, 24px);
}

.panel-mark {
  width: 46px;
  height: 46px;
  margin-bottom: 12px;
}

.overlay--start .panel-mark {
  width: 38px;
  height: 38px;
  margin-bottom: 8px;
}

.overlay h1 {
  margin: 0;
  color: #fff;
  font-size: clamp(42px, 8vw, 76px);
  font-weight: 950;
  line-height: 0.92;
  text-transform: uppercase;
}

.overlay--start h1 {
  font-size: clamp(36px, 6vw, 58px);
}

.overlay p {
  max-width: 410px;
  margin: 16px auto 22px;
  color: #c4d8f3;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.48;
}

.overlay--start p {
  margin: 10px auto 14px;
}

.start-guide {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 18px;
  text-align: left;
}

.start-guide[hidden] {
  display: none;
}

.guide-block {
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 11px;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: var(--radius);
}

.guide-block h2 {
  margin: 0 0 2px;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
}

.guide-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 22px;
  color: #eefbff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.12;
}

.guide-row em {
  min-width: 0;
  color: #d3e7fb;
  font-style: normal;
}

.guide-row kbd {
  min-width: 48px;
  padding: 4px 6px;
  color: #04111a;
  background: linear-gradient(135deg, #dffaff, var(--cyan));
  border-radius: 6px;
  font: inherit;
  font-size: 11px;
  font-weight: 950;
  text-align: center;
  white-space: nowrap;
}

.guide-dot {
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
  border-radius: 50%;
  box-shadow: 0 0 14px currentColor;
}

.guide-dot--ring {
  color: var(--gold);
  border: 3px solid var(--gold);
}

.guide-dot--boost {
  color: var(--cyan);
  background: var(--cyan);
  clip-path: polygon(50% 0, 100% 100%, 50% 74%, 0 100%);
}

.guide-dot--bomb {
  color: var(--magenta);
  background: var(--magenta);
  clip-path: polygon(50% 0, 100% 42%, 68% 100%, 32% 100%, 0 42%);
}

.guide-dot--lock {
  color: #fff;
  border: 2px solid #fff;
  background: rgba(255, 181, 46, 0.34);
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 22px;
}

.record-grid[hidden] {
  display: none;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 20px;
}

.result-stats[hidden] {
  display: none;
}

.result-stats span {
  min-width: 0;
  padding: 10px 8px;
  background: rgba(32, 215, 255, 0.08);
  border: 1px solid rgba(32, 215, 255, 0.22);
  border-radius: var(--radius);
}

.result-stats strong {
  display: block;
  color: #fff;
  font-size: clamp(18px, 5vw, 34px);
  font-weight: 950;
  line-height: 1;
}

.result-stats em {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
  font-weight: 850;
  text-transform: uppercase;
}

.record-grid span {
  min-width: 0;
  padding: 10px 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
}

.record-grid strong {
  display: block;
  color: #fff;
  font-size: clamp(16px, 4vw, 26px);
  font-weight: 950;
  line-height: 1;
}

.record-grid em {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
  font-weight: 850;
  text-transform: uppercase;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-width: 132px;
  min-height: 44px;
  padding: 12px 22px;
  color: #04111a;
  background: linear-gradient(135deg, var(--cyan), #7efff0);
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 14px 32px rgba(32, 215, 255, 0.28);
  cursor: pointer;
  font-size: 14px;
  font-weight: 950;
  text-transform: uppercase;
  transition: transform 130ms ease, box-shadow 130ms ease;
}

.secondary-button {
  color: #f6fbff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: none;
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(0);
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 8px;
  }

  .brand {
    font-size: 16px;
  }

  .brand-mark {
    width: 22px;
    height: 22px;
  }

  .hud {
    grid-template-columns: repeat(5, minmax(52px, 1fr));
    order: 3;
  }

  .hud div {
    padding: 6px;
  }

  .hud dt {
    font-size: 9px;
  }

  .hud dd {
    font-size: 14px;
  }

  .buttons {
    justify-self: end;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .overlay-panel {
    padding: 22px 16px;
  }

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

  .result-stats {
    grid-template-columns: 1fr;
  }

  .start-guide {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .guide-block {
    gap: 6px;
    padding: 10px;
  }

  .overlay--start h1 {
    font-size: clamp(32px, 10vw, 46px);
  }
}

@media (pointer: coarse), (max-width: 820px) {
  .roll-touch,
  .boost-touch,
  .bomb-touch {
    display: inline-grid;
  }
}

@media (max-height: 560px) {
  .topbar {
    min-height: 54px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .overlay p,
  .record-grid,
  .start-guide {
    margin-bottom: 12px;
  }

  .overlay h1 {
    font-size: clamp(34px, 8vw, 52px);
  }

  .guide-row {
    min-height: 20px;
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
