:root {
  color-scheme: dark;
  --page: #060812;
  --panel: #111629;
  --panel-strong: #1b2440;
  --line: rgba(153, 221, 255, 0.22);
  --text: #f7fbff;
  --muted: #9eb2d7;
  --ball: #ffef65;
  --player: #55f0ff;
  --cpu: #ff6fb1;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  background:
    linear-gradient(120deg, rgba(255, 111, 177, 0.1), transparent 34%, rgba(85, 240, 255, 0.09) 68%, transparent),
    linear-gradient(180deg, #050612 0%, #0b1022 48%, #050712 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  overscroll-behavior: none;
}

button {
  border: 0;
  border-radius: 8px;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

button:focus-visible {
  outline: 3px solid rgba(236, 255, 85, 0.72);
  outline-offset: 2px;
}

.app {
  width: min(100vw, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 8px;
}

.top-bar,
.scoreboard,
.status-strip {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  background: rgba(13, 18, 36, 0.9);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(10px);
}

.top-bar {
  min-height: 62px;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
}

.brand {
  min-width: 0;
}

.brand p {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.brand h1 {
  color: var(--text);
  font-size: clamp(21px, 5.8vw, 34px);
  line-height: 0.95;
  letter-spacing: 0;
  white-space: nowrap;
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, 42px);
  gap: 6px;
  flex: 0 0 auto;
}

.actions button {
  min-height: 38px;
  padding: 0 7px;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.actions button[aria-pressed="false"] {
  color: var(--muted);
}

.actions button:disabled {
  cursor: default;
  opacity: 0.48;
}

.scoreboard {
  min-height: 50px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  overflow: hidden;
  border-radius: 8px;
}

.scoreboard div {
  min-width: 0;
  padding: 8px 6px;
  text-align: center;
}

.scoreboard div + div {
  border-left: 1px solid var(--line);
}

.scoreboard span,
.status-strip span,
.overlay-panel p,
.overlay-panel span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.scoreboard strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 23px;
  line-height: 1;
}

.stage-wrap {
  position: relative;
  align-self: center;
  justify-self: center;
  width: min(calc(100vw - 36px), 460px);
  max-height: 100%;
  aspect-ratio: 440 / 780;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: #070b18;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.56), 0 0 44px rgba(85, 240, 255, 0.1);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #070b18;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 6, 16, 0.54);
}

.overlay.is-hidden {
  display: none;
}

.overlay-panel {
  width: min(100%, 315px);
  padding: 18px;
  display: grid;
  gap: 12px;
  justify-items: center;
  text-align: center;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(10, 14, 30, 0.9);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.48), inset 0 0 30px rgba(85, 240, 255, 0.08);
}

.overlay-panel strong {
  color: var(--text);
  font-size: clamp(30px, 10vw, 42px);
  line-height: 0.95;
}

.overlay-panel span {
  min-height: 18px;
  line-height: 1.45;
}

.difficulty {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.difficulty button,
.primary-action {
  min-height: 42px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.difficulty button {
  background: #18203a;
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.difficulty button.is-active {
  background: var(--ball);
  color: #11121b;
  border-color: var(--ball);
}

.primary-action {
  width: 100%;
  background: var(--player);
  color: #07161e;
}

.status-strip {
  min-height: 38px;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  border-radius: 8px;
}

.status-strip span:last-child {
  color: var(--ball);
}

@media (max-height: 760px) {
  .app {
    gap: 7px;
    padding-top: max(7px, env(safe-area-inset-top));
    padding-bottom: max(7px, env(safe-area-inset-bottom));
  }

  .top-bar {
    min-height: 52px;
    padding: 7px 9px;
  }

  .brand p {
    display: none;
  }

  .brand h1 {
    font-size: clamp(20px, 6vw, 28px);
  }

  .actions {
    grid-template-columns: repeat(4, 37px);
    gap: 5px;
  }

  .actions button {
    min-height: 34px;
    font-size: 10px;
  }

  .scoreboard {
    min-height: 46px;
  }

  .scoreboard strong {
    font-size: 21px;
  }

  .status-strip {
    min-height: 32px;
  }
}

@media (max-width: 390px) {
  .top-bar {
    min-height: auto;
    flex-direction: column;
    align-items: stretch;
  }

  .brand h1 {
    white-space: normal;
  }

  .actions {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 560px) and (max-width: 859px) {
  .app {
    width: min(100vw, 760px);
    grid-template-columns: minmax(190px, 230px) minmax(250px, 46vw);
    grid-template-rows: auto auto 1fr;
    align-content: center;
    column-gap: 12px;
  }

  .top-bar,
  .scoreboard,
  .status-strip {
    grid-column: 1;
  }

  .top-bar {
    align-self: end;
    flex-direction: column;
    align-items: stretch;
  }

  .brand h1 {
    font-size: 24px;
  }

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

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

  .scoreboard div:nth-child(3) {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .scoreboard div:nth-child(4) {
    border-top: 1px solid var(--line);
  }

  .stage-wrap {
    grid-column: 2;
    grid-row: 1 / 4;
    width: min(46vw, 52dvh, 360px);
  }

  .status-strip {
    align-self: start;
  }
}

@media (min-width: 860px) {
  .app {
    width: min(100vw, 920px);
    grid-template-columns: minmax(220px, 260px) minmax(360px, 460px);
    grid-template-rows: auto auto 1fr;
    align-content: center;
    column-gap: 16px;
  }

  .top-bar,
  .scoreboard,
  .status-strip {
    grid-column: 1;
  }

  .top-bar {
    align-self: end;
    flex-direction: column;
    align-items: stretch;
  }

  .brand h1 {
    font-size: 32px;
  }

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

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

  .scoreboard div:nth-child(3) {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .scoreboard div:nth-child(4) {
    border-top: 1px solid var(--line);
  }

  .stage-wrap {
    grid-column: 2;
    grid-row: 1 / 4;
    width: min(460px, 48vw, 52dvh);
  }

  .status-strip {
    align-self: start;
  }
}
