:root {
  color-scheme: dark;
  --bg: #101114;
  --surface: #181a20;
  --surface-2: #20232b;
  --surface-3: #292d36;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.22);
  --text: #f7f3e8;
  --muted: #aeb5c1;
  --cyan: #36d9d6;
  --yellow: #f4c24b;
  --rose: #ef5d7a;
  --green: #72d36b;
  --blue: #5f9fff;
  --shadow: rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    radial-gradient(circle at 50% 100%, rgba(54, 217, 214, 0.1), transparent 36%),
    var(--bg);
  background-size:
    44px 44px,
    44px 44px,
    auto,
    auto;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
canvas {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0;
  transition:
    background 150ms ease,
    border-color 150ms ease,
    transform 150ms ease,
    opacity 150ms ease;
}

button:hover:not(:disabled),
button:focus-visible:not(:disabled) {
  border-color: rgba(54, 217, 214, 0.72);
  background: var(--surface-3);
  transform: translateY(-1px);
}

button:focus-visible {
  outline: 3px solid rgba(54, 217, 214, 0.28);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.app-shell {
  display: grid;
  place-items: center;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  padding: 10px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(300px, 430px) minmax(286px, 340px);
  justify-content: center;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  height: min(700px, calc(100dvh - 20px));
  max-height: calc(100dvh - 20px);
}

.play-column {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.brand {
  position: relative;
  display: grid;
  min-height: 54px;
  align-content: center;
  padding-left: 66px;
  min-width: 0;
}

.brand::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: url("assets/tetris-symbol.svg") center/cover no-repeat;
  transform: translateY(-50%);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--cyan);
  font-size: 0.67rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.9rem, 6vw, 3.45rem);
  line-height: 0.9;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(58px, 1fr));
  justify-content: flex-end;
  gap: 6px;
  min-width: min(100%, 292px);
}

.action-row button {
  min-height: 38px;
  padding: 0 10px;
}

#startBtn,
#overlayButton {
  border-color: rgba(244, 194, 75, 0.55);
  background: linear-gradient(135deg, #816424, #6a3b34);
}

.board-shell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 18%),
    #14161b;
  box-shadow: 0 22px 48px var(--shadow);
  overflow: hidden;
  padding: 10px;
}

.board-shell::before {
  position: absolute;
  inset: 10px;
  content: "";
  border: 1px solid rgba(54, 217, 214, 0.14);
  border-radius: 6px;
  pointer-events: none;
}

.board-canvas {
  display: block;
  width: min(100%, 320px, 39dvh);
  max-width: 100%;
  height: auto;
  aspect-ratio: 1 / 2;
  border-radius: 6px;
  background: #0d0f14;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 18px 34px rgba(0, 0, 0, 0.38);
}

.game-overlay {
  position: absolute;
  inset: 10px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  border-radius: 6px;
  background: rgba(13, 15, 20, 0.8);
  text-align: center;
  padding: 12px;
}

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

.game-overlay h2 {
  max-width: 11ch;
  font-size: clamp(1.75rem, 5vw, 3.2rem);
  line-height: 0.96;
}

.overlay-instructions {
  display: grid;
  gap: 7px;
  width: min(100%, 290px);
}

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

.overlay-instructions div {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  padding: 8px;
  text-align: left;
}

.overlay-instructions strong,
.overlay-instructions span {
  display: block;
}

.overlay-instructions strong {
  color: var(--yellow);
  font-size: 0.78rem;
}

.overlay-instructions span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.25;
}

.overlay-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(92px, 1fr));
  gap: 8px;
  width: min(100%, 250px);
}

.overlay-actions button {
  min-height: 40px;
  padding: 0 12px;
}

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

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

.touch-controls button {
  min-width: 0;
  min-height: 38px;
  aspect-ratio: auto;
  padding: 0 8px;
  font-size: clamp(0.88rem, 2.4vw, 1.08rem);
}

.touch-controls button[data-control="drop"],
.touch-controls button[data-control="hold"] {
  color: var(--yellow);
}

.hud-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, auto);
  align-content: start;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat-tile,
.preview-panel,
.instructions-panel,
.status-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 26, 32, 0.92);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.26);
}

.stat-tile {
  min-width: 0;
  padding: 10px;
}

.stat-tile span,
.instructions-panel span,
.status-panel span,
.panel-heading span {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
  text-transform: uppercase;
}

.stat-tile strong {
  display: block;
  margin-top: 5px;
  font-size: clamp(1rem, 2.6vw, 1.45rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

.preview-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.preview-panel {
  display: grid;
  gap: 7px;
  padding: 10px;
  min-width: 0;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading strong {
  color: var(--cyan);
  font-size: 0.76rem;
  overflow-wrap: anywhere;
}

.preview-panel canvas {
  display: block;
  width: min(100%, 112px);
  justify-self: center;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  background: #111319;
}

.instructions-panel {
  padding: 10px;
}

.instructions-panel p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.34;
}

.status-panel {
  display: grid;
  gap: 5px;
  padding: 10px;
}

.status-panel strong {
  color: var(--yellow);
  font-size: clamp(0.94rem, 2.4vw, 1.2rem);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

@media (max-width: 860px) {
  .app-shell {
    padding: 8px;
  }

  .game-layout {
    grid-template-columns: minmax(250px, 1fr) minmax(228px, 0.8fr);
    gap: 8px;
    height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
  }

  .hud-panel {
    gap: 6px;
  }

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

  .preview-row {
    grid-template-columns: 1fr;
  }

  .preview-panel canvas {
    width: min(100%, 78px);
  }

  .instructions-panel p {
    font-size: 0.72rem;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
  }

  .action-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-width: 0;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr) 118px;
  }

  h1 {
    font-size: clamp(1.7rem, 10vw, 2.3rem);
  }

  .hud-panel {
    gap: 5px;
  }

  .stat-grid,
  .preview-row {
    grid-template-columns: 1fr;
  }

  .stat-tile,
  .preview-panel,
  .instructions-panel,
  .status-panel {
    padding: 7px;
  }

  .stat-tile span,
  .instructions-panel span,
  .status-panel span,
  .panel-heading span {
    font-size: 0.58rem;
  }

  .stat-tile strong,
  .status-panel strong {
    font-size: 0.86rem;
  }

  .preview-panel canvas {
    width: min(100%, 62px);
  }

  .instructions-panel p {
    font-size: 0.65rem;
    line-height: 1.22;
  }

  .touch-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .touch-controls button,
  .action-row button {
    min-height: 34px;
    padding-inline: 5px;
  }
}
