/* ---------- themes ---------- */
:root, [data-theme="arcade"] {
  --bg: #0b0820; --bg2: #1d1050; --board: rgba(20, 13, 52, .82); --board-edge: #3a2a8a;
  --ink: #f5f1ff; --muted: #9d93c9; --tile: #1b1540; --empty: rgba(255,255,255,.04);
  --accent: #ff3d8b; --accent2: #29e7ff; --accent3: #ffd23f;
  --btn: #2a1f66; --btn-edge: #120b33; --btn-ink: #f5f1ff;
  --glow: 0 0 18px rgba(255, 61, 139, .55), 0 0 42px rgba(41, 231, 255, .25);
  --title-shadow: 3px 3px 0 #29e7ff, 6px 6px 0 rgba(255,61,139,.6);
  --floor: rgba(255, 61, 139, .55); --star: #fff;
  color-scheme: dark;
}
[data-theme="gameboy"] {
  --bg: #0f380f; --bg2: #1f4d1f; --board: rgba(48, 98, 48, .88); --board-edge: #0f380f;
  --ink: #e0f8d0; --muted: #9bbc0f; --tile: #0f380f; --empty: rgba(15, 56, 15, .35);
  --accent: #9bbc0f; --accent2: #e0f8d0; --accent3: #8bac0f;
  --btn: #306230; --btn-edge: #0b2a0b; --btn-ink: #e0f8d0;
  --glow: 0 0 0 4px #0f380f, 0 0 0 8px #8bac0f;
  --title-shadow: 3px 3px 0 #0f380f;
  --floor: rgba(155, 188, 15, .45); --star: #9bbc0f;
  color-scheme: dark;
}
[data-theme="console"] {
  --bg: #d9d6e8; --bg2: #b8b3d4; --board: rgba(245, 243, 252, .92); --board-edge: #4f43ae;
  --ink: #221c35; --muted: #6d6690; --tile: #ccc8e0; --empty: rgba(79, 67, 174, .06);
  --accent: #4f43ae; --accent2: #d7263d; --accent3: #1fa37a;
  --btn: #f5f3fc; --btn-edge: #8c86b0; --btn-ink: #221c35;
  --glow: 0 10px 0 #8c86b0, 0 18px 40px rgba(34, 28, 53, .25);
  --title-shadow: 3px 3px 0 #b8b3d4;
  --floor: rgba(79, 67, 174, .35); --star: #4f43ae;
  color-scheme: light;
}
[data-theme="paper"] {
  --bg: #f1ead8; --bg2: #dfe9d6; --board: rgba(253, 249, 238, .94); --board-edge: #2f3b33;
  --ink: #1d2b24; --muted: #6b7a6f; --tile: #e4dccb; --empty: rgba(29, 43, 36, .04);
  --accent: #e0582f; --accent2: #2f6d4f; --accent3: #d9a321;
  --btn: #fdf9ee; --btn-edge: #2f3b33; --btn-ink: #1d2b24;
  --glow: 6px 6px 0 #2f3b33;
  --title-shadow: none;
  --floor: rgba(47, 109, 79, .25); --star: #d9a321;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh; min-height: 100dvh;
  background: radial-gradient(ellipse at 50% -10%, var(--bg2), var(--bg) 65%) fixed, var(--bg);
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background .4s, color .4s;
}
a { color: var(--accent2); }
[data-theme="console"] a, [data-theme="paper"] a { color: var(--accent); }
button { font: inherit; color: inherit; }
svg { width: 1em; height: 1em; fill: currentColor; flex: none; }

/* ---------- living background ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: -1; overflow: hidden; }
.stars {
  position: absolute; inset: -50%;
  background-image:
    radial-gradient(1.5px 1.5px at 20px 30px, var(--star), transparent),
    radial-gradient(1px 1px at 90px 120px, var(--star), transparent),
    radial-gradient(1.5px 1.5px at 160px 60px, var(--star), transparent),
    radial-gradient(1px 1px at 230px 190px, var(--star), transparent);
  background-size: 260px 240px;
  opacity: .5; animation: drift 120s linear infinite;
}
.stars.far { background-size: 180px 170px; opacity: .25; animation-duration: 200s; animation-direction: reverse; }
.floor {
  position: absolute; left: -50%; right: -50%; bottom: -10%; height: 55vh;
  background-image:
    linear-gradient(var(--floor) 2px, transparent 2px),
    linear-gradient(90deg, var(--floor) 2px, transparent 2px);
  background-size: 60px 60px;
  transform: perspective(300px) rotateX(62deg);
  transform-origin: 50% 100%;
  mask-image: linear-gradient(to top, #000 10%, transparent 85%);
  -webkit-mask-image: linear-gradient(to top, #000 10%, transparent 85%);
  animation: roll 3s linear infinite;
  opacity: .55;
}
@keyframes drift { to { transform: translate(260px, 240px); } }
@keyframes roll { to { background-position: 0 60px, 0 0; } }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: 1180px; margin: 0 auto; padding: 18px 16px 8px;
}
.logo {
  font-family: "Press Start 2P", monospace; font-size: clamp(16px, 3.4vw, 24px);
  text-decoration: none; display: inline-flex; align-items: center; letter-spacing: 1px;
}
.logo span { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.logo span:nth-child(3n+1) { color: var(--accent); }
.logo span:nth-child(3n+2) { color: var(--accent2); }
.logo span:nth-child(3n) { color: var(--accent3); }
.logo span:nth-child(5) { margin-left: .35em; }
.logo span:nth-child(1) { animation-delay: 0s } .logo span:nth-child(2) { animation-delay: .1s }
.logo span:nth-child(3) { animation-delay: .2s } .logo span:nth-child(4) { animation-delay: .3s }
.logo span:nth-child(5) { animation-delay: .4s } .logo span:nth-child(6) { animation-delay: .5s }
.logo span:nth-child(7) { animation-delay: .6s } .logo span:nth-child(8) { animation-delay: .7s }
.caret { display: inline-block; width: .55em; height: 1em; margin-left: .3em; background: var(--ink); animation: blink 1s steps(1) infinite; }
@keyframes bob { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }
@keyframes blink { 50% { opacity: 0; } }

.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- buttons ---------- */
.btn {
  --edge: var(--btn-edge);
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  min-height: 40px; padding: 8px 14px; border-radius: 10px;
  background: var(--btn); color: var(--btn-ink); border: 2px solid var(--edge);
  box-shadow: 0 4px 0 var(--edge);
  font-weight: 700; font-size: 14px; cursor: pointer; text-decoration: none;
  transition: transform .08s, box-shadow .08s, background .2s, filter .2s;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.btn:hover { filter: brightness(1.12); }
.btn:active, .btn.pressed { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
.btn:focus-visible { outline: 3px solid var(--accent2); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: default; filter: none; }
.btn.icon { width: 40px; padding: 0; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.big { min-height: 48px; padding: 10px 18px; font-size: 15px; }
.btn.accent { background: var(--accent); color: #fff; --edge: color-mix(in srgb, var(--accent) 55%, #000); }
.btn.danger { background: color-mix(in srgb, #e5484d 85%, var(--btn)); color: #fff; --edge: #7a1d20; }
.btn.ghostbtn { background: transparent; box-shadow: none; border-color: color-mix(in srgb, var(--muted) 50%, transparent); color: var(--muted); }
.btn.ghostbtn:active { transform: translateY(1px); }
.btn[aria-pressed="false"] { opacity: .55; }
#soundBtn .mute { display: none; }
#soundBtn[aria-pressed="false"] .mute { display: block; }
#soundBtn[aria-pressed="false"] .wave { display: none; }
.swatch { width: 14px; height: 14px; border-radius: 4px; background: conic-gradient(var(--accent) 0 33%, var(--accent2) 0 66%, var(--accent3) 0); border: 1.5px solid var(--btn-edge); }

/* ---------- size popover ---------- */
.sizewrap { position: relative; }
.popover {
  position: absolute; top: calc(100% + 10px); right: 0; z-index: 50;
  background: var(--board); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 2px solid var(--board-edge); border-radius: 14px; padding: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,.4);
  animation: popin .18s cubic-bezier(.2,.9,.3,1.3);
}
@media (min-width: 700px) { .popover { right: auto; left: 0; } }
@media (max-width: 699px) { .popover { position: fixed; top: 120px; left: 0; right: 0; margin: 0 auto; width: max-content; } }
.poplabel { font-family: "Press Start 2P", monospace; font-size: 12px; text-align: center; margin-bottom: 10px; color: var(--accent3); }
[data-theme="console"] .poplabel, [data-theme="paper"] .poplabel { color: var(--accent); }
.matrix { display: grid; grid-template-columns: repeat(8, 24px); gap: 4px; touch-action: none; }
.matrix i {
  width: 24px; height: 24px; border-radius: 5px; border: 2px solid color-mix(in srgb, var(--muted) 50%, transparent);
  background: var(--empty); cursor: pointer; transition: background .08s, transform .08s, border-color .08s;
}
.matrix i.cur { border-color: var(--accent2); }
.matrix i.on { background: var(--accent); border-color: var(--accent); transform: scale(1.06); }
.steppers { display: flex; gap: 12px; margin-top: 12px; justify-content: space-between; }
.stepper { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.stepper b { color: var(--ink); min-width: 1ch; text-align: center; }
.mini { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--btn-edge); background: var(--btn); color: var(--btn-ink); cursor: pointer; font-weight: 700; }
@keyframes popin { from { opacity: 0; transform: translateY(-6px) scale(.96); } }

/* ---------- view banner ---------- */
.viewbanner {
  max-width: 1180px; margin: 6px auto 0; padding: 10px 16px; display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap;
  font-weight: 500;
}
.viewbanner[hidden] { display: none; }

/* ---------- board ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 8px 16px 24px; }
.board {
  --gap: clamp(5px, 1.4vw, 14px);
  width: min(100%, calc(var(--cols, 3) * 185px + 80px));
  margin: 14px auto 0; padding: clamp(14px, 3vw, 32px);
  background: var(--board); border: 3px solid var(--board-edge); border-radius: 22px;
  box-shadow: var(--glow);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: width .35s cubic-bezier(.2,.8,.2,1), background .4s, box-shadow .4s;
}
.board[data-cols="6"], .board[data-cols="7"], .board[data-cols="8"] { --gap: clamp(4px, .9vw, 10px); }
.title {
  font-family: "Press Start 2P", monospace; font-weight: 400;
  font-size: clamp(18px, 4.2vw, 38px); line-height: 1.25; text-align: center; margin: 4px 0 10px;
  text-shadow: var(--title-shadow); outline: none; border-radius: 8px; overflow-wrap: anywhere;
}
.subtitle { text-align: center; margin: 0 0 clamp(14px, 2.4vw, 26px); color: var(--muted); font-weight: 500; font-size: clamp(13px, 1.8vw, 17px); outline: none; border-radius: 6px; }
.title[contenteditable="true"]:hover, .subtitle[contenteditable="true"]:hover { background: var(--empty); cursor: text; }
.title:focus-visible, .subtitle:focus-visible { background: var(--empty); box-shadow: 0 0 0 2px var(--accent2); }

.grid { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: var(--gap); }

/* ---------- resize affordances ---------- */
.gridwrap { display: grid; grid-template-columns: minmax(0, 1fr) var(--strip); grid-template-rows: auto var(--strip); gap: var(--gap); position: relative; }
.gridwrap .grid { grid-column: 1; grid-row: 1; }
.addcol { grid-column: 2; grid-row: 1; }
.addrow { grid-column: 1; grid-row: 2; }
.corner { grid-column: 2; grid-row: 2; }
.board.viewing .gridwrap { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; }
.board.viewing .addstrip, .board.viewing .corner, .board.viewing .coach { display: none; }
.board { --strip: 24px; }
.addstrip {
  padding: 0; display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; border-radius: 8px;
  border: 2px dashed color-mix(in srgb, var(--accent2) 55%, transparent);
  background: color-mix(in srgb, var(--accent2) 7%, transparent); color: var(--accent2);
  transition: border-color .2s, color .2s, background .2s, transform .15s;
}
.addcol { flex-direction: column; }
.addstrip span { font-family: "Press Start 2P", monospace; font-size: 13px; line-height: 1; transition: transform .2s; }
.addstrip em { font-style: normal; font-family: "Press Start 2P", monospace; font-size: 8px; letter-spacing: 1px; text-transform: uppercase; opacity: .85; }
.addcol em { writing-mode: vertical-rl; }
.addstrip:hover, .addstrip:focus-visible { outline: none; border-style: solid; background: color-mix(in srgb, var(--accent2) 18%, transparent); }
.addstrip:hover span { transform: scale(1.4) rotate(90deg); }
.addstrip:active { transform: scale(.97); }
.addstrip.hot { animation: striphot 1.6s ease-in-out infinite; border-style: solid; }
@keyframes striphot { 50% { background: color-mix(in srgb, var(--accent2) 26%, transparent); } }
.addstrip:disabled { visibility: hidden; }
.corner {
  padding: 0; display: grid; place-items: center; border: 0; border-radius: 8px; cursor: nwse-resize; touch-action: none;
  --edge: color-mix(in srgb, var(--accent) 55%, #000);
  background: var(--accent); color: #fff; box-shadow: 0 3px 0 var(--edge);
  transition: transform .15s;
}
.corner svg { font-size: 15px; }
.corner:hover { transform: scale(1.12); }
.corner:focus-visible { outline: 3px solid var(--accent2); outline-offset: 2px; }
.nudge { animation: nudge 1.8s ease-out infinite; }
@keyframes nudge { 0% { box-shadow: 0 3px 0 var(--edge), 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent); } 70%, 100% { box-shadow: 0 3px 0 var(--edge), 0 0 0 12px transparent; } }
.coach {
  position: relative; width: fit-content; max-width: 100%; margin: 14px 0 0 auto; padding: 8px 12px; border-radius: 10px; cursor: pointer;
  background: var(--accent3); color: #1a1030; font-size: 13px; font-weight: 500; line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0,0,0,.3); animation: coachbob 1.3s ease-in-out infinite;
}
.coach b { font-weight: 700; }
.coach::after { content: ""; position: absolute; top: -7px; right: calc(var(--strip, 24px) / 2 - 7px); border: 7px solid transparent; border-top: 0; border-bottom-color: var(--accent3); }
.coach[hidden] { display: none; }
@keyframes coachbob { 50% { transform: translateY(4px); } }
.sizetag {
  position: fixed; z-index: 1200; pointer-events: none; transform: translate(14px, 14px);
  font-family: "Press Start 2P", monospace; font-size: 12px; background: var(--ink); color: var(--bg); padding: 7px 9px; border-radius: 6px;
}
.sizetag[hidden] { display: none; }
body.resizing, body.resizing * { cursor: nwse-resize !important; user-select: none; -webkit-user-select: none; }

/* ---------- tiles ---------- */
.tile {
  position: relative; aspect-ratio: 3 / 4; border-radius: clamp(6px, 1.2vw, 14px);
  container-type: inline-size; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.tile.empty {
  display: grid; place-items: center; cursor: pointer; background: var(--empty);
  border: 2px dashed color-mix(in srgb, var(--muted) 55%, transparent); color: var(--muted);
  transition: border-color .2s, color .2s, background .2s, transform .15s;
  padding: 0;
}
.tile.empty:hover, .tile.empty:focus-visible, .tile.empty.hot {
  border-color: var(--accent2); color: var(--accent2); background: color-mix(in srgb, var(--accent2) 8%, transparent); outline: none;
}
.tile.empty:active { transform: scale(.96); }
.tile.empty .plus { font-family: "Press Start 2P", monospace; font-size: clamp(12px, 22cqi, 40px); line-height: 1; transition: transform .25s; }
.tile.empty:hover .plus { transform: rotate(90deg) scale(1.15); }
.tile.empty .num { position: absolute; top: 6%; left: 8%; font-family: "Press Start 2P", monospace; font-size: clamp(6px, 7cqi, 12px); opacity: .7; }
.tile.empty.enter { animation: tilepop .45s cubic-bezier(.2,.9,.3,1.4) backwards; }
.grid:not(.live) .tile.empty .plus { animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .45; } }
@keyframes tilepop { from { transform: scale(.4); opacity: 0; } }

.tile.filled { cursor: grab; touch-action: manipulation; outline: none; }
.tile.filled:focus-visible .tile-inner { box-shadow: 0 0 0 3px var(--accent2); }
.tile-inner {
  position: absolute; inset: 0; border-radius: inherit; overflow: hidden; background: var(--tile);
  transform: perspective(700px) rotateX(var(--ry, 0deg)) rotateY(var(--rx, 0deg));
  transition: transform .25s ease-out, box-shadow .25s, opacity .2s;
  box-shadow: 0 6px 16px rgba(0,0,0,.35);
}
[data-theme="paper"] .tile-inner { box-shadow: 3px 3px 0 var(--board-edge); }
[data-theme="gameboy"] .tile-inner { box-shadow: 0 0 0 2px #0f380f; }
.tile.filled:hover .tile-inner { transition: transform .08s linear, box-shadow .25s; box-shadow: 0 14px 30px rgba(0,0,0,.45); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; background: var(--tile); }
.tile.wide img, .editcover.wide img, .res .thumb.wide img { object-fit: contain; object-position: 50% 42%; padding: 8% 5% 26%; }
.res .thumb.wide img { padding: 8%; }
[data-theme="gameboy"] .tile img { filter: sepia(.25) saturate(.9); }
.shine {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 30%), rgba(255,255,255,.45), rgba(255,255,255,0) 45%);
  mix-blend-mode: soft-light;
}
.tile.filled:hover .shine { opacity: 1; }
.cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 22% 7% 6%;
  background: linear-gradient(to top, rgba(8,5,22,.92) 30%, rgba(8,5,22,0));
  color: #fff; font-weight: 700; font-size: clamp(7px, 8.5cqi, 16px); line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0,0,0,.6); transition: opacity .25s;
}
[data-theme="paper"] .cap { background: none; padding: 0; left: 5%; right: 5%; bottom: 4%; }
[data-theme="paper"] .cap span { display: block; background: #fbf5e6; color: #1d2b24; text-shadow: none; padding: 5% 6%; border-radius: 4px; font-size: clamp(7px, 8cqi, 15px); }
.cap span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.nocap .cap { opacity: 0; }
.tile .num-badge {
  position: absolute; top: 5%; left: 6%; font-family: "Press Start 2P", monospace; font-size: clamp(6px, 7cqi, 11px);
  color: #fff; background: rgba(0,0,0,.55); padding: 3px 4px; border-radius: 4px; opacity: 0; transition: opacity .2s;
}
.tile.filled:hover .num-badge, .tile.filled:focus-visible .num-badge { opacity: 1; }
.yearchip {
  position: absolute; top: 5%; right: 6%; font-family: "Press Start 2P", monospace; font-size: clamp(6px, 8cqi, 12px);
  background: var(--accent3); color: #1a1030; padding: 4px 5px; border-radius: 5px; box-shadow: 0 2px 6px rgba(0,0,0,.4);
  animation: yearchip 2.8s ease-in-out forwards; pointer-events: none;
}
@keyframes yearchip { 0% { opacity: 0; transform: translateY(-6px) scale(.8); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.tile.fileover .tile-inner, .tile.empty.fileover { outline: 3px dashed var(--accent3); outline-offset: 2px; }

.tile.placeholder .tile-inner { opacity: .18; filter: grayscale(1); box-shadow: none; transform: none; }
.tile.placeholder::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; border: 3px dashed var(--accent); animation: march 1s linear infinite;
}
@keyframes march { 50% { border-color: var(--accent2); } }
.tile.landed .tile-inner { animation: land .4s cubic-bezier(.2,.9,.3,1.5); }
@keyframes land { 0% { transform: scale(1.08); } 50% { transform: scale(.95); } 100% { transform: none; } }
.tile.born .tile-inner { animation: born .55s cubic-bezier(.2,.9,.3,1.5); }
@keyframes born { 0% { transform: scale(.3) rotate(-8deg); opacity: 0; } 60% { transform: scale(1.06) rotate(2deg); opacity: 1; } }

.ghost {
  position: fixed !important; z-index: 1000; pointer-events: none; margin: 0; will-change: transform, left, top;
}
.ghost .tile-inner { transform: none !important; box-shadow: 0 30px 60px rgba(0,0,0,.55), 0 0 0 3px var(--accent); }
.ghost .shine { opacity: 1; }
body.dragging, body.dragging * { cursor: grabbing !important; }
body.dragging .tile.filled:not(.placeholder):hover .tile-inner { transform: none; }

/* ---------- bench ---------- */
.bench { max-width: 1000px; margin: 22px auto 0; }
.bench[hidden] { display: none; }
.bench h2 { font-size: 15px; margin: 0 0 10px; text-align: center; }
.bench h2 small { font-weight: 400; color: var(--muted); }
.benchrow { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.benchrow .tile { width: 72px; }

/* ---------- dock ---------- */
.dock {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 900;
  display: flex; gap: 12px; transform: translate(-50%, 160%); visibility: hidden;
  transition: transform .3s cubic-bezier(.2,.9,.3,1.2), visibility 0s .3s;
}
body.dragging .dock { transform: translate(-50%, 0); visibility: visible; transition: transform .3s cubic-bezier(.2,.9,.3,1.2); }
.dropzone {
  display: flex; align-items: center; gap: 8px; padding: 14px 22px; border-radius: 999px;
  background: var(--board); border: 2px dashed var(--muted); font-weight: 700; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: transform .15s, background .15s, border-color .15s; box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.dropzone span { font-size: 20px; }
.dropzone.over { transform: scale(1.12); border-style: solid; border-color: var(--accent2); background: color-mix(in srgb, var(--accent2) 25%, var(--board)); }
.dropzone.danger.over { border-color: #e5484d; background: color-mix(in srgb, #e5484d 35%, var(--board)); }

/* ---------- actions ---------- */
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 24px auto 0; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 14px auto 0; max-width: 640px; line-height: 1.5; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 16px 40px; line-height: 1.7; }

/* ---------- dialogs ---------- */
.dlg {
  width: min(560px, calc(100vw - 24px)); max-height: min(720px, calc(100dvh - 24px));
  padding: 0; border: 3px solid var(--board-edge); border-radius: 18px;
  background: color-mix(in srgb, var(--bg) 70%, var(--board)); color: var(--ink);
  box-shadow: 0 30px 80px rgba(0,0,0,.5); overflow: hidden;
}
[data-theme="console"] .dlg, [data-theme="paper"] .dlg { background: var(--board); }
.dlg[open] { display: flex; flex-direction: column; animation: dlgin .22s cubic-bezier(.2,.9,.3,1.2); }
.dlg::backdrop { background: rgba(5, 3, 15, .6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.dlg.wide { width: min(900px, calc(100vw - 24px)); }
.dlg.small { width: min(380px, calc(100vw - 24px)); padding: 20px; }
.dlg.small p { margin: 0 0 16px; line-height: 1.5; }
@keyframes dlgin { from { opacity: 0; transform: translateY(14px) scale(.97); } }
@media (max-width: 600px) {
  #searchDlg { margin: 8px auto auto; max-height: calc(100dvh - 16px); }
}
.dlghead { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px 20px; }
.dlghead h3 { margin: 0; font-family: "Press Start 2P", monospace; font-size: 14px; font-weight: 400; color: var(--accent3); }
[data-theme="console"] .dlghead h3, [data-theme="paper"] .dlghead h3 { color: var(--accent); }
.x { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); width: 36px; height: 36px; border-radius: 8px; }
.x:hover { background: var(--empty); color: var(--ink); }

.searchbox { display: flex; align-items: center; gap: 10px; margin: 4px 16px 10px; padding: 0 14px; border-radius: 12px; border: 2px solid var(--board-edge); background: var(--empty); }
.searchbox:focus-within { border-color: var(--accent2); }
.searchbox svg { color: var(--muted); font-size: 18px; }
.searchbox input { flex: 1; min-width: 0; height: 48px; border: 0; background: none; outline: none; color: var(--ink); font: 500 17px "Space Grotesk", sans-serif; }
.searchbox input::-webkit-search-cancel-button { display: none; }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--muted); border-top-color: var(--accent); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.results { overflow-y: auto; padding: 0 10px 10px; min-height: 120px; flex: 1; overscroll-behavior: contain; }
.res {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 8px; border-radius: 12px;
  border: 2px solid transparent; background: none; cursor: pointer; animation: resin .25s ease-out backwards;
}
.res:hover, .res.sel { background: var(--empty); border-color: color-mix(in srgb, var(--accent2) 60%, transparent); }
.res .thumb { width: 46px; height: 61px; border-radius: 6px; background: var(--tile); flex: none; overflow: hidden; display: grid; place-items: center; font-size: 20px; }
.res .thumb img { width: 100%; height: 100%; object-fit: cover; }
.res .meta { min-width: 0; flex: 1; }
.res .name { font-weight: 700; font-size: 15px; }
.res .desc { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res .badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--accent); color: #fff; margin-left: 6px; vertical-align: 2px; }
.res.custom .thumb { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
@keyframes resin { from { opacity: 0; transform: translateY(6px); } }
.empty-state { color: var(--muted); padding: 12px 10px; font-size: 14px; line-height: 1.5; }
.dlgfoot { padding: 10px 20px 14px; border-top: 1px solid color-mix(in srgb, var(--muted) 30%, transparent); font-size: 13px; color: var(--muted); }
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; }
.toggle span { width: 34px; height: 20px; border-radius: 99px; background: color-mix(in srgb, var(--muted) 40%, transparent); position: relative; transition: background .2s; flex: none; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(14px); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent2); outline-offset: 2px; }

.editbody { display: flex; gap: 18px; padding: 6px 20px 20px; flex-wrap: wrap; }
.editcover { width: 150px; aspect-ratio: 3/4; border-radius: 12px; overflow: hidden; background: var(--tile); flex: none; }
.editcover img { width: 100%; height: 100%; object-fit: cover; }
.editside { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field input { height: 42px; border-radius: 10px; border: 2px solid var(--board-edge); background: var(--empty); color: var(--ink); padding: 0 12px; font: 500 15px "Space Grotesk", sans-serif; outline: none; }
.field input:focus { border-color: var(--accent2); }
.editdesc { margin: 0; font-size: 13px; color: var(--muted); }
.editbtns { display: flex; flex-wrap: wrap; gap: 8px; }
.editbtns .btn[hidden] { display: none; }
.tiny { font-size: 12px; color: var(--muted); margin: 0; }

.exportwrap { position: relative; padding: 0 16px; overflow: auto; flex: 1; min-height: 200px; display: grid; place-items: center; }
.exportwrap img { max-width: 100%; max-height: 60dvh; border-radius: 10px; display: block; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.rendering { position: absolute; inset: 0; display: grid; place-items: center; font-family: "Press Start 2P", monospace; font-size: 12px; color: var(--muted); }
.rendering[hidden] { display: none; }
.exportbtns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; padding: 16px; }
.exportbtns .btn[hidden] { display: none; }

/* ---------- toasts & particles ---------- */
.toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 12px; align-items: center;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35); animation: toastin .3s cubic-bezier(.2,.9,.3,1.3);
}
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; padding: 0; text-decoration: underline; }
.toast.out { animation: toastout .25s ease-in forwards; }
@keyframes toastin { from { opacity: 0; transform: translateY(-12px) scale(.9); } }
@keyframes toastout { to { opacity: 0; transform: translateY(-10px); } }
.px { position: fixed; z-index: 1500; width: 8px; height: 8px; pointer-events: none; }

@media (max-width: 560px) {
  .topbar { justify-content: center; }
  .btn { min-height: 38px; padding: 6px 10px; font-size: 13px; }
  .btn.icon { width: 38px; }
  .btn.big { min-height: 46px; flex: 1 1 40%; }
  .board { border-radius: 16px; border-width: 2px; }
  .hint { font-size: 12px; }
  .board { --strip: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
