:root {
  color-scheme: dark;
  --page: #08080f;
  --page-2: #120a32;
  --panel: rgba(15, 13, 44, 0.84);
  --panel-2: rgba(38, 23, 86, 0.86);
  --ink: #fff7ff;
  --muted: #cfc5ff;
  --line: rgba(203, 181, 255, 0.24);
  --accent: #a78bfa;
  --gold: #ffd84a;
  --cyan: #4cc9ff;
  --green: #92e348;
  --red: #ff624f;
  --radius: 8px;
  --app-height: 100dvh;
  --frame-aspect: 1672 / 941;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

html {
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 14% 24%, rgba(122, 84, 255, 0.34), transparent 30%),
    radial-gradient(circle at 88% 18%, rgba(43, 159, 255, 0.22), transparent 28%),
    radial-gradient(circle at 50% 92%, rgba(255, 213, 74, 0.08), transparent 30%),
    linear-gradient(135deg, var(--page), var(--page-2) 54%, #080a24);
  color: var(--ink);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(167, 139, 250, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(76, 201, 255, 0.045) 1px, transparent 1px);
  background-size: 54px 54px;
  mask-image: radial-gradient(circle at 50% 45%, black, transparent 76%);
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  width: min(100vw, 1720px);
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  margin: 0 auto;
  display: grid;
  place-items: center;
  padding: 0;
}

.topbar {
  position: absolute;
  top: clamp(8px, 1.1vw, 16px);
  left: clamp(8px, 1.1vw, 16px);
  right: clamp(8px, 1.1vw, 16px);
  z-index: 3;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(170px, 300px) minmax(420px, 640px) max-content;
  align-items: stretch;
  justify-content: space-between;
  gap: clamp(6px, 0.7vw, 10px);
  pointer-events: none;
}

.brand,
.readouts,
.controls {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.09), transparent 42%),
    linear-gradient(135deg, rgba(167, 139, 250, 0.16), rgba(76, 201, 255, 0.05)),
    var(--panel);
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.36),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    inset 0 -14px 22px rgba(0, 0, 0, 0.24);
  pointer-events: auto;
}

.brand::after,
.readouts::after,
.controls::after {
  content: "";
  position: absolute;
  inset: 6px;
  pointer-events: none;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: calc(var(--radius) - 2px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(48px, 6.2vh, 64px);
  gap: clamp(8px, 0.9vw, 12px);
  padding: 0 clamp(10px, 1.2vw, 16px);
  overflow: hidden;
  color: #fff4ff;
  font-size: clamp(20px, 1.85vw, 30px);
  font-weight: 900;
  line-height: 1;
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.35),
    0 0 24px rgba(167, 139, 250, 0.52);
}

.brand span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-gem {
  width: clamp(30px, 3.2vw, 42px);
  aspect-ratio: 1;
  flex: 0 0 auto;
  clip-path: polygon(50% 0, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
  background:
    radial-gradient(circle at 44% 30%, rgba(255, 255, 255, 0.92), transparent 16%),
    linear-gradient(145deg, #ffeb7a, #a78bfa 55%, #4cc9ff);
  box-shadow:
    0 0 22px rgba(167, 139, 250, 0.72),
    inset 0 0 0 4px rgba(255, 255, 255, 0.22),
    inset 0 -9px 14px rgba(0, 0, 0, 0.24);
}

.readouts {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.readouts > div {
  position: relative;
  min-width: 0;
  display: grid;
  align-content: center;
  padding: clamp(7px, 0.75vw, 10px) clamp(8px, 0.9vw, 14px) clamp(9px, 0.9vw, 12px);
  border-left: 1px solid rgba(203, 181, 255, 0.2);
}

.readouts > div:first-child {
  border-left: 0;
}

.readouts > div::before {
  content: "";
  position: absolute;
  left: clamp(10px, 1.25vw, 20px);
  right: clamp(10px, 1.25vw, 20px);
  bottom: 8px;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.readouts > div.is-pulsing dd {
  animation: readoutPulse 280ms ease-out;
}

dt {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: clamp(9px, 0.82vw, 12px);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

dd {
  margin: 0;
  overflow: hidden;
  color: var(--gold);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(17px, 1.65vw, 25px);
  font-weight: 950;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.32);
}

.readouts > div:nth-child(2) dd {
  color: #ffffff;
}

.readouts > div:nth-child(3) dd {
  color: var(--cyan);
}

.readouts > div:nth-child(4) dd {
  color: #d9c5ff;
}

.readout-sub {
  display: none;
  min-width: 0;
  margin-top: 4px;
  overflow: hidden;
  color: rgba(255, 247, 255, 0.72);
  font-size: clamp(8px, 0.72vw, 10px);
  font-weight: 850;
  line-height: 1.1;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: clamp(6px, 0.65vw, 9px);
}

.icon-button,
.play-button,
.secondary-button {
  border: 0;
  color: #fff7ff;
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 255, 255, 0.26), transparent 34%),
    linear-gradient(180deg, #7c3aed, #44208f 64%, #221052);
  cursor: pointer;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.18),
    inset 0 -9px 14px rgba(0, 0, 0, 0.28),
    0 8px 18px rgba(0, 0, 0, 0.28);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.icon-button {
  width: clamp(42px, 4.2vw, 54px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
}

.icon-button svg {
  width: 62%;
  height: 62%;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button .mute-slash {
  opacity: 0;
}

.icon-button.is-muted .sound-wave {
  opacity: 0;
}

.icon-button.is-muted .mute-slash {
  opacity: 1;
}

.icon-button:hover,
.play-button:hover,
.secondary-button:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.icon-button:focus-visible,
.play-button:focus-visible,
.secondary-button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 4px;
}

.board-shell {
  position: relative;
  min-height: 0;
  width: min(100%, calc(100dvh * 1672 / 941));
  height: auto;
  max-height: 100%;
  aspect-ratio: var(--frame-aspect);
  justify-self: center;
  align-self: center;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 0;
  border: 0;
  background: #07051b;
  box-shadow: none;
}

.board-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    inset 0 -34px 72px rgba(0, 0, 0, 0.24);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.coach-tip {
  position: absolute;
  display: none;
  right: 16px;
  bottom: 14px;
  z-index: 2;
  width: min(430px, calc(100% - 32px));
  min-height: 40px;
  display: none;
  align-items: center;
  padding: 10px 13px;
  border: 1px solid rgba(255, 216, 74, 0.45);
  border-radius: var(--radius);
  color: rgba(255, 247, 255, 0.9);
  background:
    linear-gradient(90deg, rgba(255, 216, 74, 0.12), transparent 55%),
    rgba(5, 4, 18, 0.72);
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  font-size: clamp(12px, 1.15vw, 15px);
  font-weight: 850;
  line-height: 1.25;
  pointer-events: none;
}

.state-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: clamp(14px, 2vw, 28px);
  overflow: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 50% 38%, rgba(167, 139, 250, 0.18), transparent 48%),
    rgba(3, 2, 12, 0.68);
  backdrop-filter: blur(4px);
}

.state-overlay[hidden] {
  display: none;
}

.state-panel {
  width: min(720px, calc(100% - 34px));
  max-height: 100%;
  display: grid;
  gap: 14px;
  padding: clamp(22px, 3.2vw, 38px);
  overflow: auto;
  text-align: center;
  border: 1px solid rgba(203, 181, 255, 0.44);
  border-radius: var(--radius);
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 0%, rgba(167, 139, 250, 0.28), transparent 46%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 34%),
    linear-gradient(180deg, rgba(27, 18, 68, 0.96), rgba(8, 6, 28, 0.98));
  box-shadow:
    0 22px 58px rgba(0, 0, 0, 0.46),
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    inset 0 -18px 34px rgba(0, 0, 0, 0.26);
}

.state-panel h1 {
  margin: 0;
  color: #fff3ff;
  font-size: clamp(46px, 7vw, 78px);
  line-height: 0.92;
  letter-spacing: 0;
  text-shadow:
    0 4px 0 rgba(0, 0, 0, 0.35),
    0 0 28px rgba(167, 139, 250, 0.38);
}

.state-panel p {
  max-width: 560px;
  margin: 0 auto;
  color: rgba(255, 247, 255, 0.78);
  font-size: clamp(15px, 2vw, 20px);
  font-weight: 750;
  line-height: 1.38;
}

.best-stats,
.result-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.result-stats:empty {
  display: none;
}

.best-stats span,
.result-stat {
  min-width: 0;
  padding: 10px 9px;
  border: 1px solid rgba(203, 181, 255, 0.26);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 56%),
    rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.best-stats strong,
.best-stats em,
.result-stat strong,
.result-stat em {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.best-stats strong,
.result-stat strong {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.best-stats em,
.result-stat em {
  margin-top: 4px;
  color: #fff7ff;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(15px, 2vw, 22px);
  font-style: normal;
  font-weight: 950;
}

.result-stat.is-primary {
  grid-column: span 2;
  border-color: rgba(255, 216, 74, 0.62);
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 216, 74, 0.2), transparent 62%),
    rgba(0, 0, 0, 0.28);
}

.result-stat.is-primary em {
  color: var(--gold);
  font-size: clamp(28px, 4vw, 46px);
}

.result-stat.is-record {
  border-color: rgba(146, 227, 72, 0.66);
}

.how-to {
  display: grid;
  gap: 5px;
  padding: 13px 14px;
  border: 1px solid rgba(76, 201, 255, 0.26);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(76, 201, 255, 0.08), transparent),
    rgba(0, 0, 0, 0.2);
  color: rgba(255, 247, 255, 0.8);
  text-align: left;
}

.how-to strong {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.how-to span {
  font-size: clamp(13px, 1.45vw, 16px);
  font-weight: 740;
  line-height: 1.36;
}

.menu-actions {
  display: grid;
  grid-template-columns: minmax(160px, 1.2fr) repeat(2, minmax(130px, 0.9fr));
  gap: 10px;
}

.play-button,
.secondary-button {
  min-width: 0;
  min-height: 50px;
  padding: 0 18px;
  border-radius: var(--radius);
  font-size: clamp(15px, 1.65vw, 20px);
  font-weight: 900;
}

.play-button {
  color: #22140b;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.44), transparent 42%),
    linear-gradient(180deg, #ffe36b, #f5ae2c 66%, #b95f11);
}

.secondary-button {
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.18), transparent 42%),
    linear-gradient(180deg, #3c257f, #221052);
}

@keyframes readoutPulse {
  0% {
    transform: translateY(0) scale(1);
  }
  45% {
    transform: translateY(-2px) scale(1.08);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 920px) {
  .game-shell {
    padding: 0;
  }

  .topbar {
    grid-template-columns: minmax(150px, 0.75fr) minmax(0, 1.5fr) auto;
  }

  .readouts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .readouts > div:nth-child(3) {
    border-left: 0;
  }

  .brand {
    font-size: clamp(24px, 5vw, 36px);
  }
}

@media (max-width: 700px) {
  .game-shell {
    padding: 0;
    gap: 0;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand controls"
      "readouts readouts";
  }

  .brand {
    grid-area: brand;
    min-height: 58px;
    justify-content: flex-start;
    gap: 9px;
    padding-inline: 10px;
  }

  .readouts {
    grid-area: readouts;
  }

  .controls {
    grid-area: controls;
  }

  .board-shell {
    width: 100%;
    height: 100%;
    align-self: stretch;
    aspect-ratio: auto;
  }

  canvas {
    width: auto;
    min-width: 100%;
    height: 100%;
    max-width: none;
  }

  .coach-tip {
    right: 10px;
    bottom: 10px;
    width: calc(100% - 20px);
  }

  .state-overlay {
    padding: 10px;
  }

  .state-panel {
    width: min(420px, calc(100% - 12px));
    max-height: calc(100% - 12px);
    padding: 18px;
  }

  .state-panel h1 {
    font-size: clamp(38px, 12vw, 58px);
  }

  .best-stats,
  .result-stats,
  .menu-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .play-button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 430px) {
  .readouts > div {
    padding: 8px 9px 12px;
  }

  dt {
    font-size: 10px;
  }

  dd {
    font-size: 19px;
  }

  .readout-sub {
    font-size: 8px;
  }

  .state-panel {
    width: min(360px, calc(100% - 18px));
    padding: 18px;
  }

  .brand-gem {
    width: 34px;
  }

  .brand {
    min-height: 54px;
  }

  .best-stats,
  .result-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .result-stat.is-primary {
    grid-column: 1 / -1;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .game-shell {
    padding: 0;
    gap: 0;
  }

  .brand {
    font-size: clamp(22px, 3.4vw, 34px);
  }

  .brand-gem {
    width: 36px;
  }

  .readouts > div {
    padding: 7px 9px 11px;
  }

  .readout-sub {
    margin-top: 3px;
  }

  .icon-button {
    width: clamp(42px, 6.5vh, 56px);
  }

  .coach-tip {
    display: none;
  }

  .state-panel {
    width: min(660px, calc(100% - 20px));
    gap: 8px;
    padding: 14px;
  }

  .state-panel h1 {
    font-size: clamp(34px, 8vh, 50px);
  }

  .state-panel p,
  .how-to span {
    font-size: 13px;
  }

  .best-stats span,
  .result-stat {
    padding: 7px;
  }

  .menu-actions {
    gap: 7px;
  }

  .play-button,
  .secondary-button {
    min-height: 42px;
    font-size: 14px;
  }
}
