* { box-sizing: border-box; }

/* Inter, served from this site (no third-party font requests).
   Variable-weight files; licence in fonts/OFL.txt. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(fonts/inter-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(fonts/inter-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* =========================================================================
   Theme tokens
   ========================================================================= */
:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-muted: #f1f1ee;
  --surface-hover: #ebebe7;
  --ink: #18181b;
  --ink-soft: #3f3f46;
  --muted: #71717a;
  --line: #e4e4e0;
  --line-strong: #d4d4cf;

  --primary: #18181b;
  --primary-ink: #ffffff;
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --focus: rgba(24, 24, 27, 0.18);

  /* Puzzle colors */
  --c-white: #ffffff;
  --c-black: #1c1c1f;
  --c-clay: #d4643f;
  --c-teal: #14877c;
  --tile-edge: rgba(24, 24, 27, 0.14);
  /* Fine grain laid over the puzzle backdrop (blended in "overlay" mode, so
     the same texture lightens and darkens a little in both themes) */
  --board-texture: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 1.6 -0.3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  /* Puzzle background: mid-tone slate, distinct from white AND black tiles */
  --board: #c8ced8;
  --banner: #ebebe7;

  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(16, 16, 20, 0.05);
  --shadow-md: 0 1px 2px rgba(16, 16, 20, 0.04), 0 8px 24px -8px rgba(16, 16, 20, 0.1);

  --tile: 40px;
  --tile-gap: 3px;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0f0f11;
  --surface: #18181b;
  --surface-muted: #1f1f23;
  --surface-hover: #27272a;
  --ink: #f4f4f5;
  --ink-soft: #d4d4d8;
  --muted: #a1a1aa;
  --line: #27272a;
  --line-strong: #3f3f46;

  --primary: #f4f4f5;
  --primary-ink: #18181b;
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --focus: rgba(244, 244, 245, 0.22);

  --c-white: #f4f4f2;
  --c-black: #050506;
  --tile-edge: rgba(255, 255, 255, 0.08);
  --board: #484f5c;
  --banner: #18181b;
  --board-texture: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 1.6 -0.3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px -10px rgba(0, 0, 0, 0.6);

  color-scheme: dark;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "cv11", "ss01";
  background: var(--bg);
  color: var(--ink);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

button { font-family: inherit; }

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}

/* =========================================================================
   Top bar
   ========================================================================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--banner) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 26px;
  height: 26px;
  overflow: visible; /* lets the glow spread just past the squares */
}

.brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.top-nav {
  display: flex;
  gap: 2px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  padding: 3px;
  border-radius: 999px;
}

.nav-tab {
  border: none;
  background: none;
  color: var(--muted);
  font-weight: 550;
  font-size: 0.86rem;
  padding: 6px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.nav-tab:hover { color: var(--ink); }

.nav-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--line);
}

/* =========================================================================
   Layout
   ========================================================================= */
.app {
  flex: 1 0 auto;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 0;
}

/* Small site footer, pinned to the bottom on short pages */
.site-footer {
  flex-shrink: 0;
  margin-top: 48px;
  padding: 18px 16px 22px;
  background: var(--banner); /* same as the top bar */
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.76rem;
  text-align: center;
}
.footer-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 8px;
  margin: 0;
}
.footer-privacy { display: block; margin-top: 6px; font-size: 0.72rem; }
.footer-privacy strong { font-weight: 600; color: var(--ink-soft); }
.footer-sep { opacity: 0.6; }

.view.hidden { display: none !important; }

.hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* =========================================================================
   Play layout: sidebar + board panel
   ========================================================================= */
.play-layout {
  display: flex;
  align-items: flex-start;
  gap: 24px;
}

.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 8px;
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 104px);
  overflow-y: auto;
  scrollbar-width: thin;
}

.board-panel {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px 24px 20px;
}

/* Phones: the level list is hidden until the "Levels" button in the top
   bar opens it, as a panel dropping down over the page. */
.levels-btn { display: none; }
.levels-backdrop { display: none; }

@media (max-width: 720px) {
  .play-layout { flex-direction: column; align-items: stretch; gap: 16px; }
  .sidebar {
    position: fixed;
    z-index: 16; /* above the page, below the sticky top bar (20) */
    top: var(--levels-top, 112px);
    left: 12px;
    right: 12px;
    width: auto;
    max-height: calc(100dvh - var(--levels-top, 112px) - 16px);
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0s linear 0.16s;
  }
  body.levels-open .sidebar {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
  }
  .levels-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgba(10, 10, 12, 0.28);
  }
  .levels-backdrop[hidden] { display: none; }
  .board-panel { padding: 18px 14px 14px; }

  .levels-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink-soft);
    font-size: 0.86rem;
    font-weight: 600;
    cursor: pointer;
  }
  .levels-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
  .levels-btn[aria-expanded="true"] {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-ink);
  }
}
@media (max-width: 720px) and (prefers-reduced-motion: reduce) {
  .sidebar, body.levels-open .sidebar { transition: none; }
}

/* =========================================================================
   Sidebar level navigator
   ========================================================================= */
.nav-group + .nav-group { margin-top: 2px; }

.nav-group-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 8px;
  font-weight: 600;
  font-size: 0.84rem;
  color: var(--ink);
  border-radius: var(--radius-sm);
  transition: background 0.12s ease;
}

.nav-group-header:hover { background: var(--surface-muted); }

.nav-group-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.nav-group-swatches {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.chevron {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
  color: var(--muted);
}

.nav-group-header[aria-expanded="false"] .chevron { transform: rotate(-90deg); }

.nav-group-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.25s ease;
}

.nav-group-body.collapsed { grid-template-rows: 0fr; }

.nav-group-body-inner { overflow: hidden; }

.nav-level-list {
  list-style: none;
  margin: 2px 0 8px;
  padding: 0 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  position: relative;
}

.nav-level-list::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 4px;
  bottom: 4px;
  width: 1px;
  background: var(--line);
}

.nav-level-btn {
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  cursor: pointer;
  padding: 6px 10px 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-level-btn:hover { background: var(--surface-muted); color: var(--ink); }

.nav-level-btn.active {
  background: var(--surface-hover);
  color: var(--ink);
  font-weight: 600;
}

.nav-level-btn .check {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--success);
  font-size: 0.65rem;
  font-weight: 800;
}

.nav-empty-hint {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 4px 8px 10px 28px;
  margin: 0;
}

/* =========================================================================
   Game header + legend
   ========================================================================= */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

#level-title {
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: inset 0 0 0 1px var(--tile-edge);
}
.swatch.white, .mini-swatch.swatch-white { background: var(--c-white); }
.swatch.black, .mini-swatch.swatch-black { background: var(--c-black); }
.swatch.clay, .mini-swatch.swatch-clay { background: var(--c-clay); }
.swatch.teal, .mini-swatch.swatch-teal { background: var(--c-teal); }

.swatch.white { box-shadow: inset 0 0 0 1px var(--line-strong); }

.mini-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--tile-edge);
  flex-shrink: 0;
}
.mini-swatch.swatch-white { box-shadow: inset 0 0 0 1px var(--line-strong); }

/* =========================================================================
   Board
   ========================================================================= */
/* Board sits in a horizontally-scrollable strip in case a large board is
   wider than the viewport; the strip centers the board when it's narrower. */
.board-wrap {
  overflow-x: auto;
  padding: 8px 2px 4px;
}

.board {
  display: grid;
  gap: var(--tile-gap);
  padding: 10px;
  border-radius: 14px;
  background: var(--board);
  border: 1px solid var(--line);
  width: fit-content;
  margin: 0 auto;
}

@media (max-width: 720px) {
  .app { padding: 18px 14px 0; }
  .topbar-inner { padding: 10px 14px; }
  .board { padding: 7px; }
}

/* --- Tiles --- */
.tile {
  width: var(--tile);
  height: var(--tile);
  position: relative;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px var(--tile-edge);
  transition: background-color 0.16s ease, transform 0.1s ease, box-shadow 0.16s ease;
}

.white_tile {
  background-color: var(--c-white);
  box-shadow: inset 0 0 0 1px var(--line-strong), 0 1px 1px rgba(16, 16, 20, 0.04);
}
.black_tile { background-color: var(--c-black); }
.clay_tile  { background-color: var(--c-clay); }
.teal_tile  { background-color: var(--c-teal); }

[data-theme="dark"] .black_tile { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18); }

/* Holes in the board: nothing drawn, so the textured board shows through */
.tile.vacant {
  background: none;
  box-shadow: none;
  cursor: default;
}

.tile.locked { cursor: default; }

.tile.free { cursor: pointer; }

.tile.free:hover {
  filter: brightness(0.95);
}
.black_tile.free:hover,
.teal_tile.free:hover,
.clay_tile.free:hover { filter: brightness(1.15); }

.tile.free:active { transform: scale(0.92); }

/* Lock icon: small, subtle, lighter on dark tiles for contrast */
.lock-icon,
.tile.locked > svg {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30%;
  height: 30%;
  transform: translate(-50%, -50%);
  color: rgba(24, 24, 27, 0.32);
  pointer-events: none;
}

.locked.black_tile .lock-icon,
.locked.clay_tile .lock-icon,
.locked.teal_tile .lock-icon,
.locked.black_tile > svg,
.locked.clay_tile > svg,
.locked.teal_tile > svg { color: rgba(255, 255, 255, 0.55); }

/* --- Correct-patch outline ---
   One SVG path per patch, drawn over the tiles by drawPatchOutlines() in
   game.js, so the line runs smoothly around inside and outside corners. */
.board { position: relative; }
.board > svg.patch-outlines {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 2;
}
.board > svg.patch-outlines path {
  fill: none;
  stroke: var(--success);
  stroke-width: 2.5;
  stroke-linejoin: round;
}

/* =========================================================================
   Buttons
   ========================================================================= */
.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}

.controls button, .create-actions button, .wide-btn {
  padding: 9px 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease, transform 0.08s ease;
}

.controls button:hover, .create-actions button:hover, .wide-btn:hover {
  background: var(--surface-muted);
}

.controls button:active, .create-actions button:active, .wide-btn:active { transform: translateY(1px); }

#next-btn, #create-play-btn {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}
#next-btn:hover, #create-play-btn:hover { opacity: 0.88; background: var(--primary); }

.controls button:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}
#next-btn:disabled:hover { opacity: 0.35; }

.status-msg {
  text-align: center;
  margin: 16px auto 0;
  font-weight: 600;
  font-size: 0.88rem;
  min-height: 1.4em;
}

.status-msg.ok,
.status-msg.bad {
  width: fit-content;
  padding: 7px 14px;
  border-radius: 999px;
}
.status-msg.ok { color: var(--success); background: var(--success-soft); }
.status-msg.bad { color: var(--danger); background: var(--danger-soft); }

/* =========================================================================
   Create view
   ========================================================================= */
.create-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.create-layout > .create-board-area {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.create-panel {
  width: 300px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}

.field-row-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.field-row > label {
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field-row input[type="number"],
.field-row input[type="text"],
.create-patch-sizes .patch-size-row input {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.field-row input:focus,
.create-patch-sizes .patch-size-row input:focus {
  outline: none;
  border-color: var(--ink-soft);
  box-shadow: 0 0 0 3px var(--focus);
}

.field-row input[type="number"] { width: 84px; }

.create-color-toggles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.color-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  font-weight: 500;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  cursor: pointer;
}

.color-toggle input { accent-color: var(--ink); margin: 0; }

.create-patch-sizes {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.create-patch-sizes .patch-size-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.86rem;
}

.create-patch-sizes .patch-size-row input { width: 70px; padding: 6px 8px; }

.wide-btn { width: 100%; margin-bottom: 20px; }

.create-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool-btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.tool-btn:hover { background: var(--surface-muted); }

.tool-btn.active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--surface);
}

.create-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.create-actions button { flex: 1; }

@media (max-width: 760px) {
  .create-layout { flex-direction: column; align-items: stretch; }
  .create-panel { width: 100%; }
  .create-layout > .create-board-area { width: 100%; padding: 14px; }
}

/* =========================================================================
   Settings view
   ========================================================================= */
.settings-panel {
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 4px 22px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.settings-row:last-child { border-bottom: none; }

.settings-row-text strong { font-size: 0.93rem; font-weight: 600; }
.settings-row-text p {
  margin: 3px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.danger-btn {
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
  font-size: 0.84rem;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}

.danger-btn:hover { background: var(--danger); color: #fff; }

/* Toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 24px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; position: absolute; }

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--line-strong);
  border-radius: 24px;
  transition: background 0.18s ease;
}

.slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.18s cubic-bezier(.3, .7, .4, 1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px var(--focus); }

[data-theme="dark"] .swatch.black,
[data-theme="dark"] .mini-swatch.swatch-black { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35); }

/* Group fully completed: solid green check badge next to the swatches */
.nav-group-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.group-complete {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
}

.group-complete svg { width: 10px; height: 10px; }

[data-theme="dark"] .group-complete { color: #0f0f11; }

/* Unfinished group: compact solved/total count */
.group-count {
  min-width: 30px;
  text-align: right;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Fixed-width columns so each colour's marker lines up across every group
   row, no matter how many colours a group uses or what its status shows.
   The markers are small versions of the patch-size icons: rounded squares
   in Classic, little cubes in 3D. Room for 4: 4 x 10px + 3 x 3px = 49px. */
.nav-group-swatches {
  width: 49px;
  justify-content: flex-start;
  align-items: center;
}
.nav-group-swatches .target-tile {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}
.nav-group-swatches .target-cube {
  width: 12px;
  height: 12px;
  margin: 0 -1px;
  flex-shrink: 0;
}

.nav-group-status {
  width: 30px;
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

.group-count { min-width: 0; }

/* =========================================================================
   Banner: layout, version switch, theme icon
   ========================================================================= */
.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.brand-3d {
  display: inline-block;
  margin-left: 3px;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  vertical-align: 2px;
}

/* Things that only exist in Patchwork3D */
.only-3d { display: none !important; }
html[data-mode="3d"] .only-3d { display: revert !important; }
html[data-mode="3d"] .field-row.only-3d { display: flex !important; }
/* The "3D" tag keeps its space in Classic too (just invisible), so the
   Classic/3D switch beside it doesn't shift when the mode changes. */
.brand-3d.only-3d {
  display: inline-block !important;
  visibility: hidden;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;
}
html[data-mode="3d"] .brand-3d.only-3d {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.mode-switch {
  position: relative;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}
/* One dark "thumb" slides under the active button (placed by game.js), so
   there's never a moment where both buttons are lit. */
.mode-switch::before {
  content: "";
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  width: var(--thumb-w, 0px);
  transform: translateX(var(--thumb-x, 0px));
  border-radius: 7px;
  background: var(--ink);
  transition: transform 0.24s cubic-bezier(.4, 0, .2, 1), width 0.24s cubic-bezier(.4, 0, .2, 1);
}
.mode-switch.no-anim::before { transition: none; }
@media (prefers-reduced-motion: reduce) { .mode-switch::before { transition: none; } }

.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 7px;
  cursor: pointer;
  position: relative; /* above the sliding thumb */
  z-index: 1;
  transition: color 0.2s ease;
}

.mode-btn svg { width: 14px; height: 14px; }
.mode-btn:hover { color: var(--ink); }

.mode-btn.active { color: var(--bg); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.2s ease;
}

.icon-btn:hover { color: var(--ink); background: var(--surface-muted); }
.icon-btn:active { transform: rotate(-20deg) scale(0.94); }
.icon-btn svg { width: 17px; height: 17px; }

.icon-btn .icon-sun { display: none; }
[data-theme="dark"] .icon-btn .icon-sun { display: block; }
[data-theme="dark"] .icon-btn .icon-moon { display: none; }

/* Phones: two rows. Top: logo, Classic/3D, theme toggle. Bottom: Levels
   button, then the Play / Create / Settings tabs. (The two groups' children
   are laid out directly in the bar; ::after forces the line break.) */
@media (max-width: 720px) {
  .topbar-inner { gap: 10px; flex-wrap: wrap; justify-content: flex-start; }
  .topbar-left, .topbar-right { display: contents; }
  .brand { order: 1; }
  .mode-switch { order: 2; }
  #theme-btn { order: 3; margin-left: auto; }
  .topbar-inner::after { content: ""; order: 4; flex-basis: 100%; height: 0; margin-top: -10px; }
  .levels-btn { order: 5; }
  .top-nav { order: 6; margin-left: auto; }
}
@media (max-width: 380px) {
  .nav-tab { padding: 6px 12px; }
}
/* Very narrow phones: shorter Levels button (icon only) and a tighter top row */
@media (max-width: 350px) {
  .topbar-inner { column-gap: 8px; }
  .mode-btn { padding: 5px 7px; }
  .brand { gap: 8px; }
  .levels-btn { padding: 0; width: 36px; justify-content: center; font-size: 0; gap: 0; }
}

/* =========================================================================
   Level header extras
   ========================================================================= */
.game-header { gap: 12px; justify-content: flex-start; align-items: baseline; flex-wrap: wrap; }

.level-dims {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* =========================================================================
   Patchwork3D: rotatable stack view
   ========================================================================= */
.view3d {
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    radial-gradient(ellipse at 55% 40%, color-mix(in srgb, var(--board) 88%, #fff), transparent 72%),
    var(--board);
  overflow: hidden;
  margin-bottom: 12px;
}

.scene {
  perspective: 1400px;
  perspective-origin: 50% 40%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.scene.dragging { cursor: grabbing; }

.stack {
  position: relative;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  /* smooth "Reset view"; switched off while dragging */
  transition: transform 0.4s cubic-bezier(.4, 0, .2, 1);
}

/* Zoom wrapper (the + / - buttons on the rail) */
.zoomer {
  position: relative;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  transition: transform 0.3s cubic-bezier(.4, 0, .2, 1);
}

.plate {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  /* Opening/closing the space between layers animates over half a second */
  transition: transform 0.5s cubic-bezier(.4, 0, .2, 1);
}

.plate .tile { border-radius: 4px; }
.plate .tile.vacant { background: none; }
.plate .tile.free:active { transform: none; }
.plate .lock-icon, .plate .tile.locked > svg { width: 36%; height: 36%; }

.view3d-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  font-size: 0.76rem;
  color: var(--muted);
}

.view3d-reset {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.view3d-reset:hover { background: var(--surface-muted); color: var(--ink); }

/* Patch readout (hover a square to see its patch size) */
.patch-readout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  margin: 0 auto 6px;
  font-size: 0.84rem;
  color: var(--muted);
}
.patch-readout b { color: var(--ink); font-variant-numeric: tabular-nums; }
.patch-readout .readout-sub { color: var(--muted); }
.patch-readout .readout-ok { color: var(--success); font-weight: 800; }

/* Flat layer boards, side by side */
.layers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px 22px;
}

.layer { display: flex; flex-direction: column; align-items: center; min-width: 0; max-width: 100%; }
.layer .board-wrap { padding-top: 4px; max-width: 100%; }
.layers .board { padding: 7px; }

.layer-label {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.layer-label span {
  margin-left: 4px;
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

/* Tracing: dim everything except the hovered patch */
.board-area.tracing .tile:not(.vacant):not(.traced) { opacity: 0.28; }
.board-area.tracing .tile.traced { box-shadow: inset 0 0 0 2px var(--ink), 0 0 0 1px var(--surface); }
[data-theme="dark"] .board-area.tracing .tile.traced { box-shadow: inset 0 0 0 2px #fff, 0 0 0 1px #000; }
.tile { transition: background-color 0.16s ease, transform 0.1s ease, box-shadow 0.16s ease, opacity 0.12s ease; }

.create-board-area .layers { padding: 4px 0; }

@media (max-width: 720px) {
  .layers .board { padding: 6px; }
  .layers { gap: 14px; }
}

/* =========================================================================
   Patchwork3D cubes
   ========================================================================= */
:root { --ease-layout: cubic-bezier(.4, 0, .2, 1); }

.view3d-body { display: flex; align-items: stretch; }
.view3d-body .scene { flex: 1; min-width: 0; }

/* Scale wrapper used by "expand all" so the exploded stack still fits */
.stack-inner {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  transition: transform 0.5s var(--ease-layout);
  /* distance between neighbouring cube centres within a layer */
  --pitch: calc(var(--cell) + var(--gxy));
}

/* Each cube is placed from CSS variables, so changing the gap variables
   animates every cube into its new position */
.cube {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cell);
  height: var(--cell);
  transform-style: preserve-3d;
  /* --px/--py/--pz: this cube's patch offset, applied when patches are
     separated (--sep = 1) so the whole patch moves as one piece */
  transform: translate3d(
    calc((var(--c) - var(--mid)) * var(--pitch) - var(--h) + var(--px, 0px) * var(--sep, 0)),
    calc((var(--r) - var(--mid)) * var(--pitch) - var(--h) + var(--py, 0px) * var(--sep, 0)),
    calc(var(--h) + var(--pz, 0px) * var(--sep, 0))
  );
  transition: transform 0.5s var(--ease-layout);
  cursor: default;
}
.cube.free { cursor: pointer; }

.face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: opacity 0.12s ease;
}

.cube.c-white .face { background: var(--c-white); box-shadow: inset 0 0 0 1px rgba(24, 24, 27, 0.16); }
.cube.c-black .face { background: var(--c-black); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14); }
.cube.c-clay  .face { background: var(--c-clay);  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.cube.c-teal  .face { background: var(--c-teal);  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }

/* Fixed per-face shading so the cubes read as solid */
.face::before { content: ""; position: absolute; inset: 0; pointer-events: none; }
.face.f-north::before  { background: rgba(0, 0, 0, 0.07); }
.face.f-south::before  { background: rgba(0, 0, 0, 0.17); }
.face.f-east::before   { background: rgba(0, 0, 0, 0.12); }
.face.f-west::before   { background: rgba(0, 0, 0, 0.22); }
.face.f-bottom::before { background: rgba(0, 0, 0, 0.3); }
.cube.c-black .face.f-top::before   { background: rgba(255, 255, 255, 0.07); }
.cube.c-black .face.f-north::before { background: rgba(255, 255, 255, 0.04); }
.cube.c-black .face.f-south::before,
.cube.c-black .face.f-east::before,
.cube.c-black .face.f-west::before  { background: rgba(255, 255, 255, 0); }

.cube.free:hover .face { filter: brightness(0.93); }
.cube.c-black.free:hover .face,
.cube.c-clay.free:hover .face,
.cube.c-teal.free:hover .face { filter: brightness(1.25); }

/* Lock icon on every face of a locked cube */
.face > svg {
  position: relative;
  width: 36%;
  height: 36%;
  color: rgba(24, 24, 27, 0.4);
  pointer-events: none;
}
.cube.c-black .face > svg,
.cube.c-clay .face > svg,
.cube.c-teal .face > svg { color: rgba(255, 255, 255, 0.6); }

/* ---- Connector lines between neighbouring cubes ----
   Each line is two thin crossed strips (so it stays visible from any angle)
   spanning the gap from one face centre to the next. Lines only show while
   the gap they cross is open, and grow/shrink with it. */
.conn {
  position: absolute;
  transform-style: preserve-3d;
  pointer-events: none;
  transition: width 0.5s var(--ease-layout), height 0.5s var(--ease-layout), top 0.5s var(--ease-layout);
  --conn-line: rgb(24, 24, 27);
}
[data-theme="dark"] .conn { --conn-line: rgb(255, 255, 255); }
/* lines inside a patch that's the right size turn green */
.conn.ok,
[data-theme="dark"] .conn.ok { --conn-line: var(--success); }

.conn::before,
.conn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--conn-line);
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* east: in the cube's mid-plane, from the east face across the in-layer gap */
.conn-e { left: 100%; top: calc(var(--h) - 1px); width: var(--gxy); height: 2px; }
.conn-e::after { transform: rotateX(90deg); }
/* south */
.conn-s { top: 100%; left: calc(var(--h) - 1px); height: var(--gxy); width: 2px; }
.conn-s::after { transform: rotateY(90deg); }
/* up: stands on the top face and reaches across the gap to the layer above */
.conn-u {
  left: calc(var(--h) - 1px);
  width: 2px;
  top: calc(var(--h) - var(--gup));
  height: var(--gup);
  transform-origin: 50% 100%;
  transform: translateZ(var(--h)) rotateX(-90deg);
}
.conn-u::after { transform: rotateY(90deg); }

.stack-inner.xy-open .conn-e::before, .stack-inner.xy-open .conn-e::after,
.stack-inner.xy-open .conn-s::before, .stack-inner.xy-open .conn-s::after,
.plate.up-open .conn-u::before, .plate.up-open .conn-u::after { opacity: 1; }

/* Lines between cubes of different colours are faint (12%) */
.stack-inner.xy-open .conn-e.diff::before, .stack-inner.xy-open .conn-e.diff::after,
.stack-inner.xy-open .conn-s.diff::before, .stack-inner.xy-open .conn-s.diff::after,
.plate.up-open .conn-u.diff::before, .plate.up-open .conn-u.diff::after { opacity: 0.12; }

/* ---- Correct-patch shell: a faint green hull floating just off the patch ----
   Panels are positioned from the same layout variables as the cubes (see
   buildPatchShell in game.js), so they animate along with them. */
.shells {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  pointer-events: none;
}

.shell-face {
  position: absolute;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  pointer-events: none;
  transition: transform 0.5s var(--ease-layout), width 0.5s var(--ease-layout),
              height 0.5s var(--ease-layout), left 0.5s var(--ease-layout),
              top 0.5s var(--ease-layout), opacity 0.12s ease;
}

.shell-face > i {
  position: absolute;
  background: color-mix(in srgb, var(--success) 20%, transparent);
}
[data-theme="dark"] .shell-face > i { background: color-mix(in srgb, var(--success) 25%, transparent); }

/* Tracing: fade every cube (and shell) outside the hovered patch. Opacity
   goes on the faces, not the cube, so the cubes stay 3D. */
.board-area.tracing .cube:not(.traced) .face,
.board-area.tracing .shell-face:not(.traced) { opacity: 0.2; }

/* ---- Left rail: expand all, and open/close the space between layers ---- */
.gap-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 12px 8px;
  flex-shrink: 0;
}

.explode-btn,
.gap-btn {
  display: grid;
  place-items: center;
  width: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, height 0.5s var(--ease-layout);
}
.explode-btn { height: 30px; }
.explode-btn svg { width: 18px; height: 18px; }
.explode-btn:hover,
.gap-btn:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--ink); }
.explode-btn.active { background: var(--ink); color: var(--bg); }

.rail-divider {
  width: 16px;
  height: 1px;
  margin: 8px 0;
  background: color-mix(in srgb, var(--ink) 18%, transparent);
}

.rail-layer {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  line-height: 1.6;
}

.gap-btn { height: 22px; opacity: 0.75; }
.gap-btn svg { width: 14px; height: 14px; }
/* Open gaps get a taller button, echoing the space in the stack */
.gap-btn.open { height: 40px; opacity: 1; }

@media (max-width: 720px) {
  .gap-rail { padding: 8px 4px; }
  .explode-btn, .gap-btn { width: 26px; }
}

/* ---- Zoom buttons ---- */
.zoom-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}
.zoom-btn svg { width: 16px; height: 16px; }
.zoom-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--ink); }
.zoom-btn:disabled { opacity: 0.3; cursor: default; }
@media (max-width: 720px) { .zoom-btn { width: 26px; } }

/* ---- Solved indication in the 3D view ---- */
.scene { position: relative; }

.view3d { transition: border-color 0.3s ease, box-shadow 0.3s ease; }
.view3d.solved {
  border-color: color-mix(in srgb, var(--success) 70%, transparent);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.solved-corner {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.solved-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 8px;
  border-radius: 999px;
  background: var(--success);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--success) 70%, transparent);
  pointer-events: none;
}
.solved-badge svg { width: 14px; height: 14px; }
[data-theme="dark"] .solved-badge { color: #0f0f11; }

/* The moment a puzzle is solved: the badge pops in and a green ring pulses */
.solved-badge.just-solved { animation: badge-pop 0.5s cubic-bezier(.3, 1.6, .5, 1) both; }
.view3d.just-solved { animation: solved-pulse 1.2s ease-out; }

@keyframes badge-pop {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
@keyframes solved-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 55%, transparent); }
  70%  { box-shadow: 0 0 0 14px transparent; }
  100% { box-shadow: 0 0 0 3px var(--success-soft); }
}

/* ---- Ghost cubes: empty cells in the 3D Create view ---- */
.cube.ghost .face {
  background: color-mix(in srgb, var(--surface) 10%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 22%, transparent);
}
.cube.ghost .face::before { display: none; }
.cube.ghost.free:hover .face {
  filter: none;
  background: color-mix(in srgb, var(--surface) 45%, transparent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ink) 55%, transparent);
}

/* =========================================================================
   Create: My puzzles
   ========================================================================= */
.my-puzzles {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px 18px;
  margin-bottom: 20px;
}

.my-puzzles-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.my-puzzles-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.my-puzzles-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}
.my-puzzles-count:empty { display: none; }

.new-puzzle-btn {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
}
.new-puzzle-btn:hover { opacity: 0.88; }

.my-puzzles-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}

.my-puzzles-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.puzzle-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  min-width: 0;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.puzzle-card:hover { background: var(--surface-muted); }
.puzzle-card.selected {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}

.mini-preview {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  padding: 4px;
  border-radius: 7px;
  background: var(--board);
}

.mini-grid {
  display: grid;
  gap: 1px;
  width: 44px;
}
.mini-preview .mini-grid:only-child { width: 56px; }
.mini-grid i { aspect-ratio: 1; border-radius: 1px; }
.mini-grid i.v { background: transparent; }
.mini-grid i.f { opacity: 0.55; }
.mini-grid i.swatch-white { background: var(--c-white); }
.mini-grid i.swatch-black { background: var(--c-black); }
.mini-grid i.swatch-clay  { background: var(--c-clay); }
.mini-grid i.swatch-teal  { background: var(--c-teal); }

.mini-more {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--ink-soft);
  padding: 0 2px;
}

.puzzle-card-info { flex: 1; min-width: 0; }

.puzzle-card-name {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.puzzle-card-name .check { color: var(--success); font-weight: 800; font-size: 0.8rem; }

.puzzle-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
  font-size: 0.74rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.puzzle-card-swatches { display: inline-flex; gap: 3px; }

.puzzle-card-actions { display: flex; gap: 2px; flex-shrink: 0; }

.card-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.card-btn svg { width: 15px; height: 15px; }
.card-btn:hover { background: var(--surface-hover); color: var(--ink); }
.card-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.create-editing {
  font-size: 0.8rem;
  color: var(--muted);
  margin: -4px 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.create-editing b { color: var(--ink); font-weight: 700; }

@media (max-width: 720px) {
  .my-puzzles { padding: 14px; }
  .my-puzzles-list { grid-template-columns: 1fr; }
}

/* ---- Connector lines toggle ---- */
.stack-inner.no-lines .conn::before,
.stack-inner.no-lines .conn::after { opacity: 0 !important; }

.lines-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-top: 4px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  opacity: 0.55;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}
.lines-btn svg { width: 17px; height: 17px; }
.lines-btn:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--ink); opacity: 1; }
/* "on" reads as a softly filled button so it's distinct from Expand all */
.lines-btn.active { opacity: 1; background: color-mix(in srgb, var(--surface) 60%, transparent); color: var(--ink); }
@media (max-width: 720px) { .lines-btn { width: 26px; } }



/* =========================================================================
   Board area + patch-size targets column
   ========================================================================= */
.play-main {
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

/* The board area is a size container, so boards can size their tiles to
   the width actually available beside the targets column. */
.board-area {
  flex: 1;
  min-width: 0;
  container-type: inline-size;
}

.board {
  --tile: clamp(14px, calc((100cqi - 26px - (var(--cols, 8) - 1) * var(--tile-gap)) / var(--cols, 8)), 40px);
}
.layers .board {
  --tile: clamp(14px, calc((100cqi - 24px - (var(--cols, 8) - 1) * var(--tile-gap)) / var(--cols, 8)), 32px);
}

.targets {
  width: 128px;
  flex-shrink: 0;
  position: sticky;
  top: 84px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.targets-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0 2px 2px;
}

.target {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

/* Colour icon: a small square tile matching the board's tiles */
.target-tile {
  grid-row: 1 / span 2;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px var(--tile-edge);
}
.target-tile.c-white { background: var(--c-white); box-shadow: inset 0 0 0 1px var(--line-strong), 0 1px 2px rgba(16, 16, 20, 0.06); }
.target-tile.c-black { background: var(--c-black); }
.target-tile.c-clay  { background: var(--c-clay); }
.target-tile.c-teal  { background: var(--c-teal); }
[data-theme="dark"] .target-tile.c-black { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22); }

.target-name {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.1;
}

.target-size {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* While hovering a patch in 3D, its colour's target lights up */
.target.lit {
  border-color: var(--ink);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--ink);
}

/* Narrow screens: targets become a compact row above the board */
@media (max-width: 860px) {
  .play-main { flex-direction: column; align-items: stretch; gap: 12px; }
  .targets {
    order: -1;
    position: static;
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
  }
  .targets-title { width: 100%; padding-bottom: 0; }
  .target { flex: 1 1 40%; padding: 8px 12px; column-gap: 10px; }
  .target-tile { width: 26px; height: 26px; border-radius: 6px; }
  .target-size { font-size: 1.3rem; }
}

.target-tile.readout-tile { width: 16px; height: 16px; border-radius: 4px; grid-row: auto; }

/* =========================================================================
   Solved badge: Classic sticker + 3D badge
   ========================================================================= */

/* Classic: the badge sits on the board's top-right corner like a sticker,
   and the board frame glows green */
.board-area > .board-wrap { overflow: visible; }

.board-frame {
  position: relative;
  width: fit-content;
  margin: 0 auto;
}
.board-frame .board { margin: 0; transition: border-color 0.3s ease, box-shadow 0.3s ease; }
.board-frame.solved .board {
  border-color: color-mix(in srgb, var(--success) 70%, transparent);
  box-shadow: 0 0 0 3px var(--success-soft);
}
.board-frame .solved-badge {
  position: absolute;
  top: -13px;
  right: -13px;
  z-index: 3;
}
.board-frame.just-solved .solved-badge { animation: badge-pop 0.5s cubic-bezier(.3, 1.6, .5, 1) both; }
.board-frame.just-solved .board { animation: solved-pulse 1.2s ease-out; }

/* 3D: a thick pill that spins in, then gently sways */
.badge3d {
  perspective: 360px;
  margin: 4px 6px 2px;
  pointer-events: none;
}

.badge3d-body {
  position: relative;
  transform-style: preserve-3d;
  animation: badge3d-sway 5s ease-in-out infinite alternate;
}
.badge3d.just-solved .badge3d-body {
  animation:
    badge3d-spin-in 0.9s cubic-bezier(.2, .9, .3, 1.15) both,
    badge3d-sway 5s ease-in-out 0.9s infinite alternate;
}

.badge3d-face {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 15px 8px 10px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 55%),
    var(--success);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.badge3d-face svg { width: 16px; height: 16px; }
.badge3d-front { position: relative; }
.badge3d-back { position: absolute; inset: 0; }
[data-theme="dark"] .badge3d-face { color: #0f0f11; }

/* The pill's thickness: thin darker-green layers stacked behind the front */
.badge3d-edge {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--success) 68%, #000);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

@keyframes badge3d-spin-in {
  from { transform: rotateY(-200deg) rotateX(20deg) scale(0.3); opacity: 0; }
  40%  { opacity: 1; }
  to   { transform: rotateY(0deg) rotateX(0deg) scale(1); opacity: 1; }
}
@keyframes badge3d-sway {
  from { transform: rotateY(-34deg) rotateX(12deg); }
  to   { transform: rotateY(34deg) rotateX(-8deg); }
}

@media (prefers-reduced-motion: reduce) {
  .badge3d-body,
  .badge3d.just-solved .badge3d-body { animation: none; transform: rotateY(-18deg) rotateX(8deg); }
}

/* =========================================================================
   Play: board on the left, info column on the right
   ========================================================================= */
.board-col { flex: 1; min-width: 0; }
.board-col .hint { margin: 0 0 14px; }

.side-col {
  width: 156px;
  flex-shrink: 0;
  position: sticky;
  top: 84px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.side-title h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.side-title .level-dims { display: block; margin-top: 4px; }
.side-title .level-dims:empty { display: none; }

/* patch sizes: a touch smaller than before, still the most prominent thing */
.targets {
  width: auto;
  position: static;
  gap: 7px;
}
.target { padding: 9px 12px; column-gap: 10px; }
.target-tile { width: 28px; height: 28px; border-radius: 6px; }
.target-size { font-size: 1.4rem; }
.target-name { font-size: 0.7rem; }

/* 3D: the colour icon is a little isometric cube */
.target-cube { grid-row: 1 / span 2; width: 30px; height: 30px; display: block; }
.target-cube .fill { stroke: none; }
.target-cube.c-white .fill { fill: var(--c-white); }
.target-cube.c-black .fill { fill: var(--c-black); }
.target-cube.c-clay  .fill { fill: var(--c-clay); }
.target-cube.c-teal  .fill { fill: var(--c-teal); }
.target-cube .shade-l { fill: rgba(0, 0, 0, 0.13); }
.target-cube .shade-r { fill: rgba(0, 0, 0, 0.26); }
.target-cube .edge { fill: none; stroke: rgba(24, 24, 27, 0.28); stroke-width: 0.9; stroke-linejoin: round; }
.target-cube.c-black .shade-l { fill: rgba(255, 255, 255, 0.06); }
.target-cube.c-black .shade-r { fill: rgba(255, 255, 255, 0); }
.target-cube.c-black .edge { stroke: rgba(255, 255, 255, 0.3); }

/* Solved badge sits in its own slot in the column */
.solved-slot { display: flex; justify-content: flex-start; }
.solved-slot:empty { display: none; }
.solved-slot .badge3d { margin: 2px 0 0 8px; }

/* Next / Reset stacked full-width in the column */
.side-controls {
  flex-direction: column;
  gap: 8px;
  margin-top: 0;
}
.side-controls button { width: 100%; }

/* ---- 3D rail: shared icon-button look ---- */
.rail-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}
.rail-btn svg { width: 17px; height: 17px; }
.rail-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--ink); }
.rail-btn:disabled { opacity: 0.3; cursor: default; }
.rail-btn.explode-btn.active,
.rail-btn.separate-btn.active { background: var(--ink); color: var(--bg); }
.rail-btn.zoom-btn { height: 28px; }
.rail-btn.zoom-btn svg { width: 16px; height: 16px; }
@media (max-width: 720px) { .rail-btn { width: 26px; } }



/* Narrow screens: the column becomes a block above the board */
@media (max-width: 860px) {
  .play-main { flex-direction: column; align-items: stretch; gap: 14px; }
  .side-col {
    order: -1;
    position: static;
    width: auto;
    gap: 10px;
  }
  .side-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
  .side-title .level-dims { margin-top: 0; }
  .targets { order: 0; flex-direction: row; flex-wrap: wrap; }
  .target { flex: 1 1 40%; padding: 8px 12px; }
  .target-cube { width: 26px; height: 26px; }
  .side-controls { flex-direction: row; }
  .side-controls button { flex: 1; }
}

/* =========================================================================
   Solved check badge, top-right beside the level title
   ========================================================================= */
.side-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.side-title-text { min-width: 0; }
.solved-slot { flex-shrink: 0; display: block; margin: 0; }
.solved-slot:empty { display: none; }

/* Classic: a white check on a flat green circle */
.solved-check {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  box-shadow: 0 3px 10px -3px color-mix(in srgb, var(--success) 70%, transparent);
}
.solved-check svg { width: 17px; height: 17px; }
.solved-check.just-solved { animation: badge-pop 0.5s cubic-bezier(.3, 1.6, .5, 1) both; }

/* 3D: the same check on a thick green coin */
.solved-slot .badge3d { margin: 2px 2px 0 0; }
.badge3d .badge3d-face,
.badge3d .badge3d-edge {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
}
.badge3d .badge3d-face {
  display: grid;
  place-items: center;
  color: #fff;
}
.badge3d .badge3d-face svg { width: 17px; height: 17px; }
[data-theme="dark"] .badge3d .badge3d-face { color: #fff; }

@media (max-width: 860px) {
  .side-title { align-items: center; flex-wrap: nowrap; }
  .side-title-text { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
}

/* ---- Saved-puzzle cards: preview on the left; name + details on top,
   actions on their own row underneath (so nothing gets squeezed) ---- */
.my-puzzles-list { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }

.puzzle-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 4px;
  align-items: center;
}
.puzzle-card .mini-preview { grid-row: 1 / span 2; align-self: center; }
.puzzle-card-info { grid-column: 2; grid-row: 1; align-self: end; }
.puzzle-card-actions { grid-column: 2; grid-row: 2; align-self: start; margin-left: -6px; }

/* Layer previews a little narrower so 3D puzzles leave room for the text */
.mini-grid { width: 34px; }
.mini-preview .mini-grid:only-child { width: 52px; }

.puzzle-card-meta { flex-wrap: wrap; row-gap: 2px; white-space: normal; }
.puzzle-card-meta > span:first-child { white-space: nowrap; }

/* Long names wrap to two lines before they're cut off */
.puzzle-card-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  white-space: normal;
  overflow: hidden;
  overflow-wrap: anywhere;
  line-height: 1.25;
}
.puzzle-card-name .check { margin-left: 5px; }

/* =========================================================================
   Create: one compact side panel with three tabs
   (Puzzles · Setup · Paint) and a footer with Save / Play Now
   ========================================================================= */
.create-layout { gap: 20px; }

.create-panel {
  width: 296px;
  padding: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 104px);
  overflow: hidden;
}

/* Tabs */
.panel-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.panel-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 6px 10px;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.panel-tab:hover { color: var(--ink); }
.panel-tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.tab-count {
  font-size: 0.66rem;
  font-weight: 700;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.5;
}
.tab-count:empty { display: none; }

/* Tab bodies scroll on their own; the footer stays put */
.panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
}
.panel-body[hidden] { display: none; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.field-label-row { display: flex; justify-content: space-between; align-items: baseline; padding-right: 4px; }

.create-panel input[type="text"],
.create-panel input[type="number"] {
  font-family: inherit;
  font-size: 0.86rem;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}
.create-panel input:focus { outline: none; border-color: var(--ink-soft); box-shadow: 0 0 0 3px var(--focus); }

/* Size row: Grid · Layers · New grid */
.size-row { display: flex; align-items: flex-end; gap: 8px; }
.mini-field { display: flex; flex-direction: column; gap: 3px; }
.mini-field span { font-size: 0.7rem; color: var(--muted); font-weight: 600; }
.create-panel .mini-field input { width: 64px; }
html[data-mode="3d"] .mini-field.only-3d { display: flex !important; }
.apply-btn {
  margin-left: auto;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.apply-btn:hover { background: var(--surface-muted); }

/* Colour rows: [x] tile Name ........ [size] */
.color-rows { display: flex; flex-direction: column; gap: 4px; }
.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 4px 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  border: 1px solid var(--line);
}
.color-pick { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.84rem; font-weight: 600; }
.color-pick input { margin: 0; accent-color: var(--ink); }
.color-row .target-tile { width: 18px; height: 18px; border-radius: 4px; grid-row: auto; }
.create-panel .color-row .color-size { width: 58px; padding: 4px 6px; text-align: right; }
.color-row.off .color-name { color: var(--muted); font-weight: 500; }
.color-row.off .target-tile { opacity: 0.45; }
.color-row.off .color-size { opacity: 0.45; }

/* Paint tools: two columns, each showing what it paints */
.create-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.create-panel .tool-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  font-weight: 600;
}
.create-panel .tool-btn:hover { background: var(--surface-muted); }
.create-panel .tool-btn.active {
  border-color: var(--ink);
  background: var(--surface-muted);
  color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}
.tool-swatch {
  position: relative;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 5px;
}
.tool-swatch.target-tile { grid-row: auto; width: 24px; height: 24px; border-radius: 5px; }
.tool-swatch.vacant {
  background: var(--board-texture) 0 0 / 120px 120px, var(--board);
  background-blend-mode: overlay, normal;
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.tool-swatch svg { width: 55%; height: 55%; color: rgba(24, 24, 27, 0.4); }
.tool-swatch.c-black svg, .tool-swatch.c-clay svg, .tool-swatch.c-teal svg { color: rgba(255, 255, 255, 0.65); }
.tool-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.tool-label { font-size: 0.8rem; font-weight: 650; }
.tool-note { font-size: 0.66rem; font-weight: 500; color: var(--muted); }

.panel-note { margin: 0; font-size: 0.74rem; line-height: 1.45; color: var(--muted); }
.panel-note b { color: var(--ink-soft); font-weight: 650; }

/* Puzzles tab: full-width New button, compact one-column list */
.create-panel .new-puzzle-btn { width: 100%; padding: 8px 12px; }
.create-panel .my-puzzles-list { grid-template-columns: 1fr; gap: 6px; }
.create-panel .puzzle-card { padding: 8px; column-gap: 10px; row-gap: 2px; }
.create-panel .mini-grid { width: 24px; }
.create-panel .mini-preview .mini-grid:only-child { width: 40px; }
.create-panel .mini-preview { padding: 3px; gap: 2px; }
.create-panel .card-btn { width: 26px; height: 26px; }
.create-panel .my-puzzles-empty { font-size: 0.8rem; line-height: 1.45; }

/* Footer: what's open + Save / Play Now */
.panel-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
}
.panel-footer .create-editing { margin: 0; padding: 0; border: none; font-size: 0.76rem; }
.panel-footer .create-actions { margin: 0; gap: 8px; }
.panel-footer .create-actions button { padding: 8px 12px; font-size: 0.84rem; }
.panel-footer .status-msg { margin: 0; font-size: 0.76rem; min-height: 0; padding: 5px 10px; }
.panel-footer .status-msg:empty { display: none; }

@media (max-width: 760px) {
  .create-panel { width: 100%; position: static; max-height: none; }
}

/* =========================================================================
   Puzzle backdrop (3D view, 3D layer boards and Classic board): a soft, slightly off-centre
   glow built from several layers so it isn't a plain radial — a main light
   pool up and left of centre, a smaller secondary glow down and right, a
   darker "floor" along the bottom, and a diagonal sweep underneath it all.
   ========================================================================= */
.view3d,
.board-area .board {
  --glow-1: color-mix(in srgb, var(--board) 68%, #fff);
  --glow-2: color-mix(in srgb, var(--board) 80%, #fff);
  --floor:  color-mix(in srgb, var(--board) 80%, #000);
  --sweep-hi: color-mix(in srgb, var(--board) 90%, #fff);
  --sweep-lo: color-mix(in srgb, var(--board) 87%, #000);
  background:
    var(--board-texture) 0 0 / 160px 160px,
    radial-gradient(ellipse 58% 46% at 44% 38%, var(--glow-1) 0%, transparent 72%),
    radial-gradient(ellipse 34% 28% at 64% 60%, var(--glow-2) 0%, transparent 75%),
    radial-gradient(ellipse 90% 45% at 52% 118%, var(--floor) 0%, transparent 70%),
    linear-gradient(155deg, var(--sweep-hi) 0%, var(--board) 48%, var(--sweep-lo) 100%);
  background-blend-mode: overlay, normal, normal, normal, normal;
}

/* In dark mode the light pools are a little gentler */
[data-theme="dark"] .view3d,
[data-theme="dark"] .board-area .board {
  --glow-1: color-mix(in srgb, var(--board) 76%, #fff);
  --glow-2: color-mix(in srgb, var(--board) 86%, #fff);
  --floor:  color-mix(in srgb, var(--board) 72%, #000);
}

/* =========================================================================
   Sharing: Import button, share/import dialogs
   ========================================================================= */
.puzzles-actions { display: flex; gap: 6px; }
.puzzles-actions .new-puzzle-btn { flex: 1; width: auto; }
.import-btn,
.nav-import-btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
}
.import-btn:hover,
.nav-import-btn:hover { background: var(--surface-muted); }

/* Lines up with the level buttons in the other groups; never wider than
   the sidebar (it wraps instead of being cut off). */
.nav-import-btn {
  display: block;
  margin: 2px 0 10px 14px;
  max-width: calc(100% - 14px);
  white-space: normal;
  text-align: left;
  padding: 5px 10px;
  font-size: 0.76rem;
  border-style: dashed;
  color: var(--ink-soft);
}

.pw-dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.45);
}
.pw-dialog::backdrop { background: rgba(10, 10, 14, 0.42); backdrop-filter: blur(2px); }
.dialog-inner { display: flex; flex-direction: column; gap: 10px; padding: 18px 18px 16px; }
.dialog-inner h3 { margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.dialog-note { margin: 0; font-size: 0.82rem; line-height: 1.45; color: var(--muted); }
.dialog-note b { color: var(--ink-soft); font-weight: 650; }

.code-box {
  width: 100%;
  resize: vertical;
  min-height: 84px;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  line-height: 1.4;
  word-break: break-all;
}
.code-box:focus { outline: none; border-color: var(--ink-soft); box-shadow: 0 0 0 3px var(--focus); }

.dialog-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 2px; }
.dialog-status { margin-right: auto; font-size: 0.8rem; font-weight: 600; color: var(--success); }
.dialog-error {
  margin: 0;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 600;
}
.dialog-btn {
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}
.dialog-btn:hover { background: var(--surface-muted); }
.dialog-btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.dialog-btn.primary:hover { opacity: 0.88; }

/* =========================================================================
   3D left rail: always drawn above the model. When the model is zoomed or
   spread into the rail, the rail's frosted, semi-opaque panel blurs it.
   ========================================================================= */
.gap-rail {
  position: relative;
  z-index: 2;
  /* own compositing layer, so Safari never sorts 3D cubes in front of it */
  transform: translateZ(0);
  margin: 8px 0 8px 8px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  border: 1px solid color-mix(in srgb, var(--line-strong) 70%, transparent);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  backdrop-filter: blur(8px) saturate(140%);
}
@media (max-width: 720px) {
  .gap-rail { margin: 6px 0 6px 6px; border-radius: 10px; }
}

/* =========================================================================
   Phones: all the patch-size cards on one row (up to four colours)
   ========================================================================= */
@media (max-width: 720px) {
  .targets { flex-wrap: wrap; gap: 6px; }
  .target {
    flex: 1 1 0;
    min-width: 0;
    padding: 6px 8px;
    column-gap: 6px;
    border-radius: 10px;
  }
  .target-tile { width: 20px; height: 20px; border-radius: 5px; }
  .target-cube { width: 22px; height: 22px; }
  .target-name { font-size: 0.62rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .target-size { font-size: 1.1rem; }
}
/* Very narrow phones: drop the colour name (the icon shows the colour) */
@media (max-width: 360px) {
  .target { grid-template-columns: auto auto; justify-content: center; padding: 6px; }
  .target-name { display: none; }
  .target-tile, .target-cube { grid-row: auto; }
}

/* Narrow phones: keep logo, Classic/3D and the theme toggle on one row
   (the reserved "3D" tag space makes the brand a little wider). */
@media (max-width: 370px) {
  .mode-btn svg { display: none; }
}
@media (max-width: 340px) {
  .topbar-inner { column-gap: 6px; }
  .brand { gap: 6px; }
  .brand-name { font-size: 0.98rem; }
}


/* =========================================================================
   Page backgrounds (Settings → Background). "Plain" is the flat --bg; the
   others add a fixed layer behind everything, built from the site's own
   colours at low strength, animated only with transforms (cheap to run).
   ========================================================================= */
:root {
  --bg-clay: rgba(212, 100, 63, 0.13);
  --bg-teal: rgba(20, 135, 124, 0.12);
  --bg-slate: rgba(120, 132, 150, 0.16);
  --bg-line: rgba(24, 24, 27, 0.055);
  --bg-shine: rgba(255, 255, 255, 0.55);
  --au-clay: rgba(212, 100, 63, 0.24);
  --au-teal: rgba(20, 135, 124, 0.22);
  --au-slate: rgba(120, 132, 150, 0.26);
}
[data-theme="dark"] {
  --bg-clay: rgba(212, 100, 63, 0.12);
  --bg-teal: rgba(20, 160, 146, 0.12);
  --bg-slate: rgba(130, 145, 170, 0.12);
  --bg-line: rgba(255, 255, 255, 0.045);
  --bg-shine: rgba(255, 255, 255, 0.05);
  --au-clay: rgba(212, 100, 63, 0.2);
  --au-teal: rgba(20, 160, 146, 0.2);
  --au-slate: rgba(130, 145, 170, 0.18);
}

.site-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  display: none;
}
html[data-bg="drift"] .site-bg,
html[data-bg="tiles"] .site-bg,
html[data-bg="aurora"] .site-bg { display: block; }
.site-bg i {
  position: absolute;
  display: block;
  will-change: transform;
}

/* --- Drift: three soft glows wandering slowly --- */
html[data-bg="drift"] .site-bg i {
  width: 70vmax;
  height: 70vmax;
  border-radius: 50%;
}
html[data-bg="drift"] .site-bg i:nth-child(1) {
  left: -20vmax; top: -25vmax;
  background: radial-gradient(closest-side, var(--bg-clay), transparent);
  animation: bg-drift-a 24s ease-in-out infinite alternate;
}
html[data-bg="drift"] .site-bg i:nth-child(2) {
  right: -25vmax; top: 10vh;
  background: radial-gradient(closest-side, var(--bg-teal), transparent);
  animation: bg-drift-b 31s ease-in-out infinite alternate;
}
html[data-bg="drift"] .site-bg i:nth-child(3) {
  left: 15vw; bottom: -40vmax;
  background: radial-gradient(closest-side, var(--bg-slate), transparent);
  animation: bg-drift-c 27.5s ease-in-out infinite alternate;
}
@keyframes bg-drift-a { to { transform: translate3d(28vw, 22vh, 0) scale(1.15); } }
@keyframes bg-drift-b { to { transform: translate3d(-30vw, 18vh, 0) scale(0.9); } }
@keyframes bg-drift-c { to { transform: translate3d(20vw, -25vh, 0) scale(1.2); } }

/* --- Tiles: a faint grid of rounded squares gliding diagonally, with a
       slow band of light passing over it --- */
html[data-bg="tiles"] .site-bg i:nth-child(1) {
  inset: -56px;
  --tile-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56'%3E%3Crect x='6' y='6' width='44' height='44' rx='9' fill='none' stroke='black' stroke-width='1.5'/%3E%3C/svg%3E");
  background: var(--bg-line);
  -webkit-mask: var(--tile-svg) 0 0 / 56px 56px;
  mask: var(--tile-svg) 0 0 / 56px 56px;
  animation: bg-tiles 18s linear infinite;
}
html[data-bg="tiles"] .site-bg i:nth-child(2) {
  top: -50%; bottom: -50%;
  left: 0; width: 40vw;
  background: linear-gradient(90deg, transparent, var(--bg-shine), transparent);
  transform: translateX(-60vw) rotate(18deg);
  animation: bg-shine 11s ease-in-out infinite;
}
html[data-bg="tiles"] .site-bg i:nth-child(3) {
  inset: 0;
  background:
    radial-gradient(60vmax 45vmax at 85% 10%, var(--bg-teal), transparent 70%),
    radial-gradient(55vmax 40vmax at 10% 95%, var(--bg-clay), transparent 70%);
  opacity: 0.7;
}
@keyframes bg-tiles { to { transform: translate3d(56px, 56px, 0); } }
@keyframes bg-shine {
  0%, 30% { transform: translateX(-60vw) rotate(18deg); }
  70%, 100% { transform: translateX(130vw) rotate(18deg); }
}

/* --- Aurora: broad colour ribbons arcing over the top of the page,
       turning very slowly --- */
html[data-bg="aurora"] .site-bg i:nth-child(1),
html[data-bg="aurora"] .site-bg i:nth-child(2) {
  width: 170vmax;
  height: 170vmax;
  left: calc(50% - 85vmax);
  top: -128vmax;
  border-radius: 50%;
}
html[data-bg="aurora"] .site-bg i:nth-child(1) {
  background: conic-gradient(from 0deg, transparent 0deg, var(--au-teal) 45deg, transparent 100deg, var(--au-clay) 160deg, transparent 220deg, var(--au-slate) 280deg, transparent 340deg);
  -webkit-mask: radial-gradient(closest-side, transparent 66%, #000 76%, #000 84%, transparent 96%);
  mask: radial-gradient(closest-side, transparent 66%, #000 76%, #000 84%, transparent 96%);
  animation: bg-turn 75s linear infinite;
}
html[data-bg="aurora"] .site-bg i:nth-child(2) {
  background: conic-gradient(from 120deg, transparent 0deg, var(--au-clay) 55deg, transparent 125deg, var(--au-teal) 205deg, transparent 265deg);
  -webkit-mask: radial-gradient(closest-side, transparent 78%, #000 86%, transparent 97%);
  mask: radial-gradient(closest-side, transparent 78%, #000 86%, transparent 97%);
  opacity: 0.85;
  animation: bg-turn 105s linear infinite reverse;
}
html[data-bg="aurora"] .site-bg i:nth-child(3) {
  inset: 0;
  background: radial-gradient(80vmax 50vmax at 50% 115%, var(--bg-slate), transparent 70%);
}
@keyframes bg-turn { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .site-bg i { animation: none !important; }
}

/* Settings: background picker */
.settings-row-wrap { flex-wrap: wrap; }
.bg-options { display: flex; gap: 8px; flex-wrap: wrap; }
.bg-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.bg-option:hover { color: var(--ink); border-color: var(--line-strong); }
.bg-option[aria-checked="true"] {
  color: var(--ink);
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}
.bg-thumb {
  width: 64px;
  height: 42px;
  border-radius: 8px;
  background-color: var(--bg);
  box-shadow: inset 0 0 0 1px var(--line);
}
.bg-thumb-drift {
  background-image:
    radial-gradient(circle at 20% 25%, var(--bg-clay), transparent 55%),
    radial-gradient(circle at 85% 45%, var(--bg-teal), transparent 55%),
    radial-gradient(circle at 45% 110%, var(--bg-slate), transparent 60%);
}
.bg-thumb-tiles {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14'%3E%3Crect x='1.5' y='1.5' width='11' height='11' rx='2.5' fill='none' stroke='%23888' stroke-opacity='.35' stroke-width='1'/%3E%3C/svg%3E"),
    radial-gradient(circle at 90% 0%, var(--bg-teal), transparent 60%),
    radial-gradient(circle at 0% 100%, var(--bg-clay), transparent 60%);
  background-size: 14px 14px, auto, auto;
}
.bg-thumb-aurora {
  background-image:
    radial-gradient(120% 90% at 50% -40%, transparent 45%, var(--au-teal) 58%, var(--au-clay) 70%, transparent 82%),
    radial-gradient(90% 60% at 50% 120%, var(--bg-slate), transparent 70%);
}
@media (max-width: 720px) {
  .bg-options { width: 100%; justify-content: space-between; }
  .bg-option { flex: 1 1 0; min-width: 0; }
  .bg-thumb { width: 100%; }
}

/* Classic, side-by-side layout: a board shorter than the info column beside
   it sits centred against that column instead of at the top. */
@media (min-width: 861px) {
  html:not([data-mode="3d"]) .play-main { align-items: stretch; }
  html:not([data-mode="3d"]) .play-main > .side-col { align-self: flex-start; }
  html:not([data-mode="3d"]) .board-col {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  html:not([data-mode="3d"]) .board-col > .board-area { flex: 0 0 auto; }
}
