:root {
  color-scheme: light dark;
  --bg: #f3f4f7;
  --surface: #ffffff;
  --text: #1b1d22;
  --muted: #545b66;
  --accent: #2459c4;
  --on-accent: #ffffff;
  --button: #e1e6f0;
  --error: #b3261e;
  --star: #b87700;
  --check: #2e7d32;
  /* The selection ring, cursor and tap pulse, drawn over Plastic's navy floor in both modes. */
  --ring: #ffffff;
  --cell: 0px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121418;
    --surface: #1e2128;
    --text: #e6e8ec;
    --muted: #a9b0bb;
    --accent: #8db1ff;
    --on-accent: #0d1a33;
    --button: #2b303a;
    --error: #ffb4ab;
    --star: #f2b33d;
    --check: #81c784;
  }
}

:root[data-theme="dark"] {
  --bg: #121418;
  --surface: #1e2128;
  --text: #e6e8ec;
  --muted: #a9b0bb;
  --accent: #8db1ff;
  --on-accent: #0d1a33;
  --button: #2b303a;
  --error: #ffb4ab;
  --star: #f2b33d;
  --check: #81c784;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, p { margin: 0; }

/* Taller than wide: HUD, board, controls. Wider than tall: the board beside a side column (developer.md §4.8). */
.app {
  height: 100vh;
  height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: grid;
  gap: 16px;
  grid-template: "hud" auto "slot" minmax(0, 1fr) "side" auto / minmax(0, 1fr);
}

@media (min-aspect-ratio: 1001/1000) {
  .app {
    grid-template: "slot hud" auto "slot side" minmax(0, 1fr) / minmax(0, 1fr) 216px;
  }
  .side { align-self: end; max-height: 100%; overflow-y: auto; }
}

/* Phone landscape has no room for the promo beside the controls; portrait shows it. */
@media (min-aspect-ratio: 1001/1000) and (max-height: 500px) {
  .side .promo { display: none; }
}

.hud { grid-area: hud; text-align: center; font-variant-numeric: tabular-nums; }
.hud h1 { font-size: 1.375rem; }
.warning { color: var(--error); margin-top: 4px; }

.side { grid-area: side; display: grid; gap: 12px; }
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 20px; }
.controls .group { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.promo { color: var(--muted); font-size: 0.875rem; text-align: center; display: grid; gap: 8px; }
.promo a { color: var(--accent); }
.stores { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.stores img { display: block; height: 40px; width: auto; }
/* Google's badge has a transparent margin of 41 of its 250 pixels: scaled so the badge itself is 40 px tall, like Apple's. */
.stores .play { height: 59.5px; margin: -9.75px; }
.stores a:not([href]) img { opacity: 0.4; filter: grayscale(1); }
.legal { font-size: 0.6875rem; }

button {
  font: inherit;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 22px;
  background: var(--button);
  color: var(--text);
  cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: var(--on-accent); }
button:focus-visible, #board:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* The board */

.slot { grid-area: slot; position: relative; min-height: 0; }

#board {
  position: absolute;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  border-radius: 4px;
}

#cells > div, .block, #cursor, .pulse {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cell);
  height: var(--cell);
}

#cells > div, .face { background-size: 100% 100%; }
.wall { background-image: url("tiles/wall.png"); }
.floor { background-image: url("tiles/floor.png"); }

.face { position: relative; width: 100%; height: 100%; }
.type1 { background-image: url("tiles/block1.png"); }
.type2 { background-image: url("tiles/block2.png"); }
.type3 { background-image: url("tiles/block3.png"); }
.type4 { background-image: url("tiles/block4.png"); }
.type5 { background-image: url("tiles/block5.png"); }
.type6 { background-image: url("tiles/block6.png"); }
.type7 { background-image: url("tiles/block7.png"); }
.type8 { background-image: url("tiles/block8.png"); }

/* A vanishing block scales to 0.2 while it fades out; with Reduce Motion it only fades. */
.vanishing .face { transform: scale(0.2); opacity: 0; }
.reduced .vanishing .face { transform: none; }

/* Rounded rings inside the cell, their corners matching the tile's. */
.selected .face::after, #cursor, .pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: calc(var(--cell) * 0.18);
  border: max(3px, calc(var(--cell) * 0.08)) solid var(--ring);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.35), inset 0 0 0 1px rgb(0 0 0 / 0.35);
}
#cursor { border-width: max(2px, calc(var(--cell) * 0.05)); border-style: dashed; }
.pulse::after { border-width: max(2px, calc(var(--cell) * 0.06)); }
.pulse { animation: pulse 450ms ease-out forwards; }

@keyframes pulse {
  from { transform: scale(0.6); opacity: 1; }
  to { transform: scale(1); opacity: 0; }
}

/* Panels over the board */

.panel {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.3);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#playback {
  top: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 4px 20px;
  border-radius: 28px;
  white-space: nowrap;
}

#banner {
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(320px, calc(100% - 32px));
  padding: 24px;
  display: grid;
  gap: 12px;
  justify-items: center;
  animation: fade-in 250ms ease-out;
}
.reduced #banner { animation: none; }
#banner h2 { font-size: 1.375rem; }
.check { color: var(--check); font-size: 2.25rem; line-height: 1; }
.badge span { color: var(--star); }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

[hidden] { display: none !important; }

/* Dialogs */

dialog {
  border: 0;
  border-radius: 16px;
  padding: 24px;
  background: var(--surface);
  color: var(--text);
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h2 { font-size: 1.25rem; margin-bottom: 8px; }
dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

#levels-dialog select { width: 100%; font: inherit; padding: 6px; }
#level-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
#level-list button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-radius: 12px;
  text-align: left;
  font-variant-numeric: tabular-nums;
}
#level-list button[aria-current="true"] { outline: 2px solid var(--accent); }
#level-list .result { color: var(--muted); white-space: nowrap; }

.visually-hidden {
  position: fixed;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
