:root {
  --bg: #1b1610;
  --panel: #2a2219;
  --line: #4a3d2c;
  --text: #f1e6cf;
  --muted: #b9a888;
  --accent: #ffd23f;      /* highlight for the tile to tap */
  --accent-ink: #1b1610;
  --primary: #c9952c;
  --primary-ink: #1b1610;
  --error: #ff8a7a;
  --frame: #3b2a14;
  --board: min(calc(100vw - 32px), 480px, calc(100svh - 300px));
}
@supports not (height: 100svh) {
  :root { --board: min(calc(100vw - 32px), 480px, calc(100vh - 300px)); }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main {
  max-width: 520px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
h1 { font-size: 1.25rem; margin: 4px 0 16px; letter-spacing: 0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 6px; }
[hidden] { display: none !important; }

.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 52px; padding: 0 20px;
  border: 2px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.button:disabled { opacity: 0.4; cursor: default; }
.button:focus-visible, .link-button:focus-visible, summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.upload-button { width: 100%; font-size: 1.1rem; min-height: 60px; position: relative; overflow: hidden; }
.upload-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.upload-button:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

.hint { color: var(--muted); margin: 14px 0 0; }
.privacy { color: var(--muted); font-size: 0.9rem; margin: 10px 0 0; }
.status { font-size: 1.1rem; padding: 24px 0; text-align: center; }
.error { background: var(--panel); border: 2px solid var(--error); border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; }
.error h2 { color: var(--error); }
.error p { margin: 0; }
.note { color: var(--muted); font-size: 0.9rem; margin: 0 0 6px; text-align: center; }

.move-label { font-size: 1.35rem; font-weight: 700; text-align: center; margin: 0 0 10px; }
.move-label.solved { color: #8fdc7a; }

/* Board: 5×5 tiles inside a dark frame. Tiles are absolutely positioned so a
   moved tile slides to its new cell. */
.board {
  position: relative;
  width: var(--board); height: var(--board);
  margin: 0 auto;
  background: var(--frame);
  border: 6px solid var(--frame);
  border-radius: 6px;
  box-sizing: border-box;
}
.tile {
  position: absolute;
  width: 20%; height: 20%;
  left: calc(var(--c) * 20%); top: calc(var(--r) * 20%);
  padding: 2px;
  transition: left 160ms ease-out, top 160ms ease-out;
}
.tile img {
  display: block; width: 100%; height: 100%;
  image-rendering: pixelated; image-rendering: crisp-edges;
  border-radius: 2px;
  filter: brightness(0.62) saturate(0.8);
  transition: filter 160ms;
}
.board.solved .tile img, .tile.next img { filter: none; }
.tile.next { z-index: 2; }
.tile.next::after {
  content: ""; position: absolute; inset: -3px;
  border: 5px solid var(--accent); border-radius: 6px;
  box-shadow: 0 0 0 2px var(--accent-ink), 0 0 14px 4px #ffd23fb0;
  animation: pulse 1.2s ease-in-out infinite;
  pointer-events: none;
}
.tile .badge {
  position: absolute; right: 5px; bottom: 5px;
  min-width: 22px; padding: 0 4px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 14px; font-weight: 700; line-height: 20px; text-align: center;
  border-radius: 4px;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 2px var(--accent-ink), 0 0 4px 1px #ffd23f80; } }
@media (prefers-reduced-motion: reduce) {
  .tile, .tile img { transition: none; }
  .tile.next::after { animation: none; }
}

.upcoming { color: var(--muted); text-align: center; margin: 10px 0 0; min-height: 1.45em; font-size: 0.95rem; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.link-button {
  display: block; margin: 14px auto 0; padding: 10px 16px; min-height: 44px;
  background: none; border: 0; color: var(--muted); font: inherit; text-decoration: underline; cursor: pointer;
}

