:root {
  color-scheme: dark;
  --cell-size: 30px;
  --board-width: calc(var(--cell-size) * 10);
  --board-height: calc(var(--cell-size) * 20);
  --bg: #10131d;
  --panel: #181d2b;
  --panel-2: #20273a;
  --text: #f5f7fb;
  --muted: #9ea8bd;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #5dd3ff;
  --danger: #ff6174;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  background:
    radial-gradient(circle at top left, rgba(93, 211, 255, 0.18), transparent 32rem),
    linear-gradient(135deg, #10131d 0%, #151827 48%, #0c0f18 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: #26314b;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover {
  background: #303d5d;
}

button:active {
  transform: translateY(1px);
}

.app {
  width: min(1080px, calc(100vw - 24px));
  margin: 0 auto;
  padding: clamp(16px, 4vw, 36px) 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.3rem, 8vw, 5rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 10px;
  color: var(--muted);
  font-size: clamp(0.98rem, 2.4vw, 1.1rem);
}

.secondary {
  padding: 0 18px;
  background: transparent;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(220px, 1fr);
  gap: clamp(14px, 3vw, 24px);
  align-items: start;
}

.board-shell {
  position: relative;
  width: min(100%, var(--board-width), 64vh, 420px);
  height: auto;
  aspect-ratio: 10 / 20;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  overflow: hidden;
  background: #0b0f18;
  box-shadow: var(--shadow);
}

#board {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  background: rgba(7, 10, 16, 0.72);
  backdrop-filter: blur(4px);
}

.overlay strong {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
}

.overlay span {
  color: var(--muted);
}

.sidebar {
  display: grid;
  gap: 14px;
}

.panel,
.stats {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(24, 29, 43, 0.86);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
}

.panel {
  padding: 16px;
}

.panel h2 {
  color: var(--muted);
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

#next {
  display: block;
  width: 120px;
  height: 120px;
  background: #111725;
  border-radius: 8px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
}

.stats div {
  display: grid;
  gap: 6px;
  padding: 16px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stats div:nth-child(2n) {
  border-right: 0;
}

.stats div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.stats span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats strong {
  font-size: clamp(1.35rem, 4vw, 2.1rem);
}

.touch-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.touch-controls button[data-action="drop"] {
  background: #30546b;
}

.touch-controls button[data-action="pause"] {
  background: #4b385e;
}

@media (max-width: 760px) {
  :root {
    --cell-size: min(5.4vw, 22px, calc((100svh - 220px) / 20));
  }

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

  body {
    min-height: 100svh;
  }

  .app {
    width: min(100vw - 12px, 520px);
    height: 100svh;
    min-height: 100svh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 6px;
    padding: 6px 0;
    overflow: hidden;
  }

  .topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
  }

  h1 {
    font-size: clamp(1.45rem, 8vw, 2rem);
    line-height: 1;
  }

  .topbar p {
    margin-top: 2px;
    font-size: 0.78rem;
    line-height: 1.2;
  }

  .secondary {
    width: auto;
    min-height: 34px;
    padding: 0 10px;
    font-size: 0.85rem;
  }

  .game-layout {
    grid-template-columns: minmax(0, var(--board-width)) minmax(92px, 1fr);
    gap: 8px;
    align-items: start;
    justify-content: center;
    min-height: 0;
  }

  .board-shell {
    width: var(--board-width);
    max-width: 100%;
    justify-self: center;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  }

  .sidebar {
    grid-template-columns: 1fr;
    gap: 8px;
    min-width: 0;
  }

  .panel {
    padding: 8px;
  }

  .panel h2 {
    margin-bottom: 6px;
    font-size: 0.68rem;
  }

  #next {
    width: min(100%, 88px);
    height: auto;
    aspect-ratio: 1;
  }

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

  .stats div,
  .stats div:nth-child(2n),
  .stats div:nth-last-child(-n + 2) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stats div {
    gap: 2px;
    padding: 7px 8px;
  }

  .stats div:last-child {
    border-bottom: 0;
  }

  .stats span {
    font-size: 0.63rem;
  }

  .stats strong {
    font-size: clamp(1rem, 5vw, 1.24rem);
  }

  .touch-controls {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
    margin-top: 0;
  }

  .touch-controls button {
    min-height: 42px;
    padding: 0 4px;
    border-radius: 7px;
    font-size: 0.76rem;
  }
}

@media (max-width: 430px) {
  .app {
    width: min(100vw - 10px, 430px);
  }

  .topbar p {
    display: none;
  }

  .game-layout {
    grid-template-columns: minmax(0, var(--board-width)) minmax(82px, 1fr);
    gap: 6px;
  }
}

@media (max-width: 360px) {
  :root {
    --cell-size: min(5vw, 20px, calc((100svh - 210px) / 20));
  }

  .touch-controls button {
    font-size: 0.68rem;
  }
}
