/* Patchwork: denim board, quilt-scrap pieces */
@font-face { font-family: "Young Serif"; font-display: swap; src: url(../fonts/young-serif-latin-400-normal.woff2) format("woff2"); }

:root {
  --bg: #E9EEF5;
  --card: #FFFFFF;
  --ink: #22303F;
  --muted: #5E6B7A;
  --line: #CFD8E3;
  --empty: #F7F9FC;
  --seam: #22303F;
  --accent: #2F6FB3;
  --display: "Young Serif", Georgia, serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121A24; --card: #1B2532; --ink: #E9EEF5; --muted: #9AA8B8; --line: #2C3A4B; --empty: #243142; --seam: #0B1118; --accent: #6FA8E6; color-scheme: dark; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ui); line-height: 1.45; min-height: 100vh; }
a { color: inherit; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 560px; margin: 0 auto; padding: 0 14px; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 0 0; }
.back { text-decoration: none; color: var(--muted); font-size: 0.95rem; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; }
.icon-btn:hover { background: var(--card); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.title-row { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 0 10px; }
h1 { font-family: var(--display); font-weight: 400; font-size: 2.2rem; margin: 0; line-height: 1; }
.sub { margin: 0; color: var(--muted); font-size: 0.95rem; }

.hud { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.hud p { margin: 0; }
.hud b { font-family: var(--display); font-weight: 400; font-size: 1.6rem; }
.hud .of { color: var(--muted); }

.board-wrap { display: flex; justify-content: center; }
.board { display: grid; gap: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.cell { width: var(--cs); height: var(--cs); position: relative; }
.cell.in { background: var(--empty); box-shadow: inset 0 0 0 0.5px var(--line); cursor: pointer; }
.cell.in.p { box-shadow: none; }
.cell.draw { background: color-mix(in srgb, var(--accent) 45%, var(--empty)); }
.cell.bad { background: color-mix(in srgb, #D9483B 45%, var(--empty)); }
/* seams between different pieces and at the board edge */
.cell.t { border-top: 3px solid var(--seam); }
.cell.r { border-right: 3px solid var(--seam); }
.cell.b { border-bottom: 3px solid var(--seam); }
.cell.l { border-left: 3px solid var(--seam); }
.cell.in:not(.p).t { border-top-width: 2px; }
.cell.in:not(.p).r { border-right-width: 2px; }
.cell.in:not(.p).b { border-bottom-width: 2px; }
.cell.in:not(.p).l { border-left-width: 2px; }
.board.small .cell { --cs: 22px; cursor: default; }
.board.small .cell.t { border-top-width: 2px; } .board.small .cell.r { border-right-width: 2px; }
.board.small .cell.b { border-bottom-width: 2px; } .board.small .cell.l { border-left-width: 2px; }

/* quilt scraps: a solid colour with a faint woven texture */
.cell.in.p::after { content: ""; position: absolute; inset: 0; background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.12) 0 2px, transparent 2px 6px); pointer-events: none; }
.cell.p.c0 { background: #E07A5F; } .cell.p.c1 { background: #3D7EA6; } .cell.p.c2 { background: #F2CC8F; } .cell.p.c3 { background: #81B29A; }
.cell.p.c4 { background: #B56576; } .cell.p.c5 { background: #6D597A; } .cell.p.c6 { background: #E9A23B; } .cell.p.c7 { background: #4D908E; }
.cell.p.c8 { background: #C46D5E; } .cell.p.c9 { background: #90BE6D; } .cell.p.c10 { background: #577590; } .cell.p.c11 { background: #D4A5A5; }

.tray { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 12px 0 0; font-size: 0.82rem; color: var(--muted); }
.tray span { background: var(--card); border-radius: 8px; padding: 4px 8px; font-variant-numeric: tabular-nums; }
.tray span.full { color: var(--ink); font-weight: 700; }
.tools { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.tool { border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 9px 18px; font-weight: 700; cursor: pointer; }
.tool.wide { width: 100%; margin-bottom: 12px; }
.go { width: 100%; border: 0; border-radius: 16px; padding: 15px; background: var(--ink); color: var(--card); font-weight: 800; font-size: 1.15rem; cursor: pointer; }
.fine { color: var(--muted); font-size: 0.85rem; text-align: center; margin: 10px 0 0; }

.card { background: var(--card); border-radius: 20px; padding: 20px 18px; box-shadow: 0 1px 0 var(--line), 0 18px 40px -28px rgba(34, 48, 63, .5); }
.done { margin-top: 14px; }
.kicker { margin: 0; color: var(--muted); font-weight: 600; }
.big { font-family: var(--display); font-size: 3rem; line-height: 1; margin: 6px 0 6px; }
.big small { font-size: 1.1rem; color: var(--muted); }
.res-line { margin: 0 0 14px; }
#sol { margin: 0 auto 14px; width: max-content; }

/* ads */
.ad-inline { margin-top: 26px; }
.ad-slot { display: block; margin: 0 auto; overflow: hidden; }
.ad-banner { width: 100%; max-width: 728px; min-height: 100px; }
.ad-slot.placeholder { border: 1.5px dashed var(--line); border-radius: 12px; display: grid; place-items: center; color: var(--muted); font-size: 0.85rem; }
.ad-slot.placeholder::before { content: "Ad space " attr(data-size); }
.ad-slot.collapsed { min-height: 0; }
.ad-slot ins[data-ad-status="unfilled"] { display: none !important; }
.ad-label { font-size: 11px; color: var(--muted); text-align: center; margin: 0 0 4px; }

.foot { display: flex; justify-content: center; gap: 22px; padding: 26px 0 40px; color: var(--muted); font-size: 0.9rem; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.dlg { border: 0; border-radius: 16px; padding: 22px; width: min(420px, calc(100vw - 32px)); background: var(--card); color: var(--ink); }
.dlg::backdrop { background: rgba(10, 16, 24, .5); }
.dlg h2 { font-family: var(--display); font-weight: 400; margin: 0 0 10px; font-size: 1.6rem; }
.dlg p { color: var(--muted); }
.dlg .x { position: absolute; right: 10px; top: 8px; border: 0; background: transparent; font-size: 26px; cursor: pointer; color: var(--muted); width: 40px; height: 40px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 0; }
.stats div { display: flex; flex-direction: column-reverse; background: var(--bg); border-radius: 10px; padding: 10px; }
.stats dt { color: var(--muted); font-size: 0.85rem; }
.stats dd { margin: 0; font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
