:root {
  color-scheme: dark;
  --canvas: #24241e;
  --ivory: #f5e9d5;
  --muted: #c8b99e;
  --accent: #e4ab65;
  --grain: repeating-linear-gradient(3deg, #43230c12 0 1px, transparent 2px 6px, #fff8e46b 7px, transparent 9px 14px);
}
* { box-sizing: border-box }
body {
  margin: 0;
  min-height: 100svh;
  color: var(--ivory);
  background: radial-gradient(ellipse at 50% 28%, #44392a, var(--canvas) 70%);
  font-family: system-ui, sans-serif;
}
button, select { font: inherit }
a { color: inherit; text-decoration: none }
button, select { cursor: pointer }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 2px solid #fff4bc; outline-offset: 3px }
button[disabled] { opacity: .46; cursor: default }
[hidden] { display: none !important }
.top {
  max-width: 760px;
  margin: auto;
  padding: 22px 24px 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f8d4a322;
}
.brand { font: bold 24px Georgia, serif; letter-spacing: -.05em }
.brand span, .catalog span { color: var(--accent) }
.catalog { color: var(--muted); font-size: 13px }
main { width: min(100% - 28px,620px); margin: 23px auto 38px }
.intro { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin: 0 4px 17px }
h1 { margin: 0; font: 500 clamp(54px, 10vw, 82px)/.92 Georgia,serif; letter-spacing: -.065em }
.intro p { margin: 10px 0 0; color: var(--muted); font-size: 14px }
.picker { color: var(--muted); font-size: 11px; display: grid; gap: 5px }
select { padding: 8px; border: 1px solid #a68b6766; border-radius: 6px; background: #2e2a21; color: var(--ivory) }
.workspace {
  padding: 15px 19px 13px;
  border: 1px solid #dfa875;
  border-radius: 18px;
  color: #372014;
  background: var(--grain), repeating-radial-gradient(ellipse at 7% 117%, #65402213 0 1px, transparent 4px 15px),
    linear-gradient(126deg, #eac597, #c68954);
  box-shadow: inset 0 0 0 3px #ffdba65d, 0 8px 0 #825736, 0 17px 30px #170e0a7d;
}
.frame-head, .frame-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px }
.frame-head { border-bottom: 1px solid #4d2d2447; padding: 0 0 8px }
h2 { font: 700 22px Georgia, serif; margin: 0 }
#counter { font-size: 12px; font-weight: 650 }
#board {
  --tile: clamp(32px, 9.5vw, 55px);
  display: grid;
  width: max-content;
  max-width: 100%;
  margin: 16px auto;
  grid-template-columns: repeat(var(--columns), var(--tile));
  grid-auto-rows: var(--tile);
  user-select: none;
  touch-action: manipulation;
}
.square { width: 100%; height: 100%; min-width: 0; padding: 0; border: 0; position: relative }
.square.target {
  background: var(--grain), linear-gradient(135deg,#673d25,#4a2d21);
  border: 1px solid #2e21186a;
  box-shadow: inset 1px 3px 4px #271610a8;
  color: #ffdfa7;
}
.square.target:hover { filter: brightness(1.17) }
.square.fitted, .mini-cell, .ghost-cell {
  background: var(--grain), radial-gradient(ellipse at 64% 85%, transparent 25%, #492c2425 27%, transparent 30%),
    linear-gradient(145deg,var(--light),var(--dark));
  border: 1px solid #5530196b;
  border-top-color: #fff1cdaa;
  border-left-color: #fff1cd90;
  box-shadow: inset 0 -3px 0 #45251338;
}
.square.mark { box-shadow: inset 0 0 0 2px #fff3a7,inset 0 0 0 5px #84a881; z-index: 1 }
.square.bad { box-shadow: inset 0 0 0 2px #ffe4d5,inset 0 0 0 5px #c3694b; z-index: 1 }
.frame-foot { min-height: 32px }
progress { accent-color: #634e34; width: min(100%,160px); height: 9px }
#next { border: 0; border-radius: 6px; padding: 8px 10px; background: #352a20; color: #fff2cf; font-size: 12px }
.workbench { margin-top: 21px }
#tray { display: grid; grid-template-columns: repeat(var(--count),minmax(0,1fr)); gap: 5px; padding: 0 0 10px }
.piece {
  position: relative; display: grid; place-items: center; min-height: 72px; min-width: 0;
  border: 1px solid #aa97703d; border-radius: 8px; background: #241e19b8;
  color: var(--muted); touch-action: none; user-select: none;
}
.piece:not(:disabled) { cursor: grab }
.piece.active { border-color: #f3c485; background: #5a452f; box-shadow: inset 0 0 0 1px #e6a6586b }
.mini { display: grid; grid-auto-rows: var(--mini); grid-template-columns: repeat(var(--pc),var(--mini)); --mini: clamp(11px,3.8vw,22px); filter: drop-shadow(0 3px 2px #100a07) }
.mini-cell { align-self: stretch }
.piece.done .mini { opacity: .28 }
.tools { display: grid; grid-template-columns: repeat(4,1fr); gap: 5px }
.tools button {
  min-height: 40px; padding: 5px 2px; border: 1px solid #aa97704a; border-radius: 6px;
  background: #3a3227; color: var(--ivory); font-size: clamp(10px,2.9vw,13px);
}
.tools button span { color: #ebbc78; margin-right: 1px; font-size: 1.15em }
.status { min-height: 40px; color: var(--muted); margin: 10px 1px 0; font-size: 13px }
#ghost { position: fixed; top: 0; left: 0; pointer-events: none; z-index: 5; opacity: .88; filter: drop-shadow(1px 5px 4px #20150e80) }
.ghost-cell { position: absolute }
@media (max-width: 380px) {
  .workspace { padding-inline: 12px }
  .piece { min-height: 60px }
}
.square.pin::after { content: ''; position: absolute; inset: 36%; border-radius: 50%; background: #fff3a7; }
