/* holypuzzle.com's jigsaw player, on /jigsaw-puzzle and /my-jigsaw-puzzle: color tokens, buttons and
   the game. The navbar's styles live in jigsawfun/navbar.css, the picker's (picture box, link box,
   preview) in my-pictures/picker.css; both use the color tokens defined here. */
:root {
  --bg: #f4f1ec;
  --panel: #ffffff;
  --text: #1f1d1a;
  --muted: #6d675f;
  --line: #e0dbd3;
  --accent: #c2410c;
  --accent-soft: #fde7da;
  --table: #e9e4dc;
  --shadow: 0 10px 30px rgba(31, 29, 26, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --panel: #211f1c;
    --text: #f1ede7;
    --muted: #a39c92;
    --line: #36322d;
    --accent: #fb923c;
    --accent-soft: #3a2518;
    --table: #1d1b19;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px 32px;
  min-height: 100vh;
}
.sub { color: var(--muted); margin: 0 0 18px; text-align: center; }

/* Toolbar */
#game { display: none; flex-direction: column; align-items: center; width: 100%; }
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 12px; margin-bottom: 14px; max-width: 100%;
}
.toolbar label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
select, button {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
button:hover, select:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.stats { display: flex; gap: 16px; font-variant-numeric: tabular-nums; font-size: 14px; }
.stats b { font-weight: 600; }
.sep { width: 1px; height: 22px; background: var(--line); }

/* Table. isolation keeps the pieces' ever-growing z-indexes (and the preview's/win card's) in the
   table's own stacking context, so they never rise above the sticky navbar. touch-action: none on
   the whole table (it's sized to fit the window, so nothing needs scrolling) stops a touch that
   lands just beside a piece - which puzzle.ts still picks up - from scrolling or zooming the page
   instead, which would cancel the drag. */
#table {
  position: relative;
  isolation: isolate;
  background: var(--table);
  border-radius: 14px;
  border: 1px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.board-img {
  position: absolute; inset: 0; background-size: 100% 100%;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
#preview { z-index: 5000; }
#preview.show { opacity: 1; }
#table.solved #preview { opacity: 1; transition: opacity .8s .25s; z-index: 2; }

.piece {
  position: absolute; left: 0; top: 0;
  touch-action: none;
  cursor: grab;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .35));
}
.piece.dragging { cursor: grabbing; filter: drop-shadow(0 10px 12px rgba(0, 0, 0, .4)); }
.piece.placed { cursor: default; filter: none; }
.piece.snap { transition: transform .15s ease-out; }

/* Win */
#win {
  position: absolute; display: none;
  pointer-events: none; z-index: 6000;
}
#win.show { display: block; }
/* Sits just above the finished picture as a wide, square-cornered bar */
.win-card {
  position: absolute; left: 50%; bottom: calc(100% + 14px); translate: -50% 0;
  width: max-content; max-width: calc(100vw - 32px);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 20px;
  pointer-events: auto; background: var(--panel); border-radius: 0; padding: 12px 20px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
  animation: pop .35s cubic-bezier(.2,1.4,.4,1) 1s both;
}
.win-card h2 { margin: 0; font-size: 20px; }
.win-card p { margin: 0; color: var(--muted); }
.win-card .row { display: flex; gap: 8px; justify-content: center; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.help { color: var(--muted); font-size: 13px; margin-top: 14px; text-align: center; }

/* Short messages, e.g. after Copy link */
#toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 200;
  max-width: calc(100% - 32px); text-align: center;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 600;
  padding: 9px 18px; border-radius: 999px; box-shadow: var(--shadow);
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
button:disabled { cursor: default; opacity: .5; }
button:disabled:hover { border-color: var(--line); }

/* A gallery picture's description (puzzlefun.html) keeps the admin's line breaks */
#pictureDescription { white-space: pre-line; }
