
@font-face { font-family: 'Cabin Sketch'; font-weight: 400; font-style: normal; font-display: swap; src: url('fonts/cabin-sketch/CabinSketch-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Cabin Sketch'; font-weight: 700; font-style: normal; font-display: swap; src: url('fonts/cabin-sketch/CabinSketch-Bold.woff2') format('woff2'); }
@font-face { font-family: 'Nunito'; font-weight: 200 1000; font-style: normal; font-display: swap; src: url('fonts/nunito/Nunito-VF.woff2') format('woff2'); }

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --deep: #364B49;
  --canvas: #E8DFC9;
  --coral: #D98573;
  --mustard: #E8BA70;
  --mint: #7BA69A;
  --denim: #8191B8;
  --mauve: #A37D91;
  --thread: #493E42;
  --ink: #2E2427;
  --wood: #B98B5E;
  --wood-d: #8A6240;
  --tan: #C4A075;
  --paper: #F3ECD8;
  --felt: url('assets/felt.webp');
  --f-title: 'Cabin Sketch', 'Chalkboard SE', 'Marker Felt', 'Comic Sans MS', cursive;
  --f-body: 'Nunito', 'Avenir Next Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --soft: 0 2px 4px rgba(58, 38, 20, 0.38), 0 1px 1px rgba(58, 38, 20, 0.3);
  --soft-up: 0 7px 12px rgba(58, 38, 20, 0.38), 0 3px 4px rgba(58, 38, 20, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --vvh: 100dvh;
  --vvw: 100%;
  --tray-w: clamp(272px, 31vw, 392px);
  --tray-h: clamp(212px, 35dvh, 340px);
  --cell: 88px;
}

html, body {
  font-variant-numeric: tabular-nums;
  width: 100%;
  height: 100%;
  height: 100dvh;
  height: var(--vvh);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  background: var(--wood);
}
body {
  position: fixed;
  inset: 0;
  width: var(--vvw);
  height: var(--vvh);
  font-family: var(--f-body);
  font-weight: 700;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
svg.ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; flex: none; pointer-events: none; }


#table {
  position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
  background: var(--wood) url('assets/table.webp') center / cover no-repeat;
}
#table img { position: absolute; display: block; filter: drop-shadow(0 5px 6px rgba(58, 38, 20, 0.38)); }
#table .p-yarn { width: clamp(70px, 11vmin, 150px); left: -1%; top: 24%; transform: rotate(-12deg); }
#table .p-scissors { width: clamp(90px, 14vmin, 190px); right: -2%; top: 8%; transform: rotate(18deg); }
#table .p-felts { width: clamp(80px, 12vmin, 160px); left: -2%; bottom: 20%; transform: rotate(8deg); }
#table .p-bowl { width: clamp(70px, 11vmin, 150px); right: -1%; top: 47%; transform: rotate(10deg); }
#table .p-pins { width: clamp(56px, 8vmin, 110px); left: 1%; top: 6%; transform: rotate(0deg); }
#table .p-spool { width: clamp(64px, 9.5vmin, 130px); right: 3%; bottom: 22%; transform: rotate(-25deg); }

#app {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) var(--tray-h);
  grid-template-areas: "top" "stage" "tray";
  padding-bottom: var(--safe-bottom);
}
@media (orientation: landscape) and (min-aspect-ratio: 11/10) {
  #app {
    grid-template-columns: minmax(0, 1fr) calc(var(--tray-w) + var(--safe-right));
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "top top" "stage tray";
  }
}


.chip, .act, .sb, .btn, .tab, #nameInput {
  --r: 14px;
  border-radius: var(--r);
}
.chip, .act, .sb, .btn { position: relative; }
.chip::before, .act::before, .sb::before, .btn::before, .tab::before {
  content: ''; position: absolute; inset: 3px; border-radius: calc(var(--r) - 3px);
  border: 1.6px dashed var(--stc, rgba(46, 36, 39, 0.55)); pointer-events: none;
}
.chip:focus-visible, .act:focus-visible, .sb:focus-visible, .btn:focus-visible, .tab:focus-visible, .sw:focus-visible, #nameInput:focus-visible, .thumb:focus-visible, #banner:focus-visible {
  outline: 3px dashed var(--deep); outline-offset: 3px;
}


#topbar {
  grid-area: top;
  display: grid;
  align-items: center;
  gap: 8px;
  padding: calc(7px + var(--safe-top)) calc(8px + var(--safe-right)) 8px calc(8px + var(--safe-left));
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  grid-template-areas: "home name mute" "acts acts acts";
  position: relative;
  z-index: 5;
}
@media (orientation: landscape) and (min-aspect-ratio: 11/10) {
  #topbar {
    grid-template-columns: 44px minmax(150px, 290px) minmax(0, 1fr) 44px;
    grid-template-areas: "home name acts mute";
  }
}

.chip {
  width: 44px; height: 44px; min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(#cfa377, #b58655);
  border: 2px solid var(--wood-d);
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--soft), inset 0 1px 0 rgba(255, 240, 215, 0.45);
  --stc: rgba(70, 44, 22, 0.55);
  transition: transform .08s, box-shadow .08s;
}
.chip:active { transform: translateY(2px) scale(0.97); box-shadow: 0 1px 2px rgba(58, 38, 20, 0.4), inset 0 2px 4px rgba(58, 38, 20, 0.25); }
#homeChip { grid-area: home; }
#muteBtn { grid-area: mute; }
#nameWrap { grid-area: name; display: flex; gap: 6px; align-items: center; min-width: 0; }

#nameInput {
  flex: 1; min-width: 0; height: 44px;
  --r: 10px;
  border: 0;
  background: var(--felt), var(--canvas); background-blend-mode: soft-light, normal;
  color: var(--ink);
  font: 700 20px/1 var(--f-title);
  padding: 0 10px; text-align: center; letter-spacing: 0;
  user-select: text; -webkit-user-select: text;
  box-shadow: var(--soft), inset 0 0 0 3px var(--canvas), inset 0 0 0 4.5px rgba(73, 62, 66, 0.5);
  outline: none;
}
#nameInput:focus { box-shadow: var(--soft), inset 0 0 0 3px var(--canvas), inset 0 0 0 4.5px var(--coral); }
#nameDice { flex: none; }

#actions { grid-area: acts; display: flex; gap: 7px; justify-content: center; align-items: stretch; min-width: 0; }
@media (orientation: landscape) and (min-aspect-ratio: 11/10) { #actions { justify-content: flex-end; } }

.act {
  --c: var(--canvas);
  min-width: 44px; min-height: 44px;
  flex: 1 1 0; max-width: 72px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  padding: 3px 2px 2px;
  background: var(--felt), var(--c); background-blend-mode: soft-light, normal;
  color: var(--ink);
  box-shadow: var(--soft);
  font: 800 12px/1 var(--f-body); letter-spacing: 0;
  transition: transform .08s, box-shadow .08s;
}
.act .ic { width: 22px; height: 22px; stroke-width: 2.4; }
.act:active { transform: translateY(2px) scale(0.96); box-shadow: 0 1px 1px rgba(58, 38, 20, 0.4); }
#btnUndo, #btnRedo { --c: var(--canvas); }
#btnSurprise { --c: var(--mustard); max-width: 92px; flex-grow: 1.45; }
#btnSave { --c: var(--coral); }
#btnShelf { --c: var(--mint); }
#btnCard { --c: var(--denim); }
#btnBook { --c: var(--mauve); }
.act[disabled] { filter: saturate(0.35) brightness(0.96); opacity: 0.55; box-shadow: 0 1px 1px rgba(58, 38, 20, 0.3); }
.act .count {
  position: absolute; top: -9px; right: -7px; min-width: 24px; height: 24px; padding: 0 5px;
  border-radius: 12px; background: var(--canvas); color: var(--ink);
  box-shadow: var(--soft), inset 0 0 0 2px var(--canvas), inset 0 0 0 3.2px rgba(73, 62, 66, 0.6);
  font: 800 12px/24px var(--f-body); text-align: center; z-index: 1;
}
@media (orientation: landscape) and (min-aspect-ratio: 11/10) {
  .act { flex: 0 0 auto; width: 66px; max-width: none; }
  #btnSurprise { width: 84px; }
}


#stageWrap {
  grid-area: stage;
  position: relative;
  min-height: 0;
  overflow: hidden;
}
#board {
  position: absolute; z-index: 0; pointer-events: none;
  inset: 4px clamp(8px, 2vw, 18px) 8px;
  border-radius: 7px;
  background: var(--felt), var(--canvas); background-blend-mode: soft-light, normal;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 3px 3px rgba(58, 38, 20, 0.35), 0 12px 22px rgba(58, 38, 20, 0.34);
}
#board svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#board svg rect { fill: none; stroke: var(--thread); stroke-opacity: 0.55; stroke-width: 2.2; stroke-linecap: round; stroke-dasharray: 9 7; }
@media (min-width: 900px) and (orientation: landscape) {
  #board { inset: 14px clamp(30px, 4.5vw, 70px) 20px; }
}
#stage { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#stage.grabbing { cursor: grabbing; }


#hint {
  position: absolute; left: 50%; top: 9%; transform: translateX(-50%);
  max-width: 82%; padding: 9px 16px;
  background: var(--felt), var(--paper); background-blend-mode: soft-light, normal;
  color: var(--ink); border-radius: 9px;
  font: 700 clamp(17px, 2.8vmin, 24px)/1.15 var(--f-title); text-align: center;
  box-shadow: var(--soft), inset 0 0 0 3px var(--paper), inset 0 0 0 4.4px rgba(73, 62, 66, 0.5);
  pointer-events: none;
  animation: hintBob 1.6s ease-in-out infinite;
  z-index: 3;
}
#hint::after {
  content: ''; position: absolute; left: 50%; bottom: -11px; margin-left: -10px;
  border: 10px solid transparent; border-top: 12px solid var(--paper); border-bottom: 0;
  filter: drop-shadow(0 2px 1px rgba(58, 38, 20, 0.3));
}
#hint[hidden] { display: none; }
@keyframes hintBob { 0%, 100% { transform: translate(-50%, 0) rotate(-1deg); } 50% { transform: translate(-50%, -6px) rotate(1deg); } }


#bubbles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 4; }
.bubble {
  position: absolute; transform: translate(-50%, -100%);
  padding: 6px 14px 7px; border-radius: 8px; background: var(--felt), var(--paper); background-blend-mode: soft-light, normal; color: var(--ink);
  font: 700 clamp(18px, 3.2vmin, 28px)/1 var(--f-title); white-space: nowrap;
  animation: bubblePop 1.5s cubic-bezier(.2,1.4,.4,1) forwards;
  box-shadow: var(--soft), inset 0 0 0 2.5px var(--paper), inset 0 0 0 3.8px rgba(73, 62, 66, 0.5);
}
.bubble.big { font-size: clamp(24px, 4.6vmin, 40px); background-color: var(--mustard); box-shadow: var(--soft), inset 0 0 0 2.5px var(--mustard), inset 0 0 0 3.8px rgba(73, 62, 66, 0.55); }
@keyframes bubblePop {
  0% { opacity: 0; transform: translate(-50%, -60%) scale(0.3) rotate(-6deg); }
  14% { opacity: 1; transform: translate(-50%, -100%) scale(1.12) rotate(2deg); }
  24% { transform: translate(-50%, -100%) scale(1) rotate(-1deg); }
  80% { opacity: 1; transform: translate(-50%, -125%) scale(1) rotate(1deg); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(0.95) rotate(0); }
}


#toast {
  position: absolute; left: 30px; top: 22px; transform-origin: 22px 0;
  max-width: min(300px, calc(100% - 64px)); padding: 19px 14px 7px 14px; border-radius: 4px 14px 14px 14px;
  background: var(--felt), var(--paper); background-blend-mode: soft-light, normal; color: var(--ink);
  font: 700 15px/1.25 var(--f-body); text-align: left;
  box-shadow: var(--soft-up), inset 0 0 0 2.5px var(--paper), inset 0 0 0 3.8px rgba(73, 62, 66, 0.4);
  opacity: 0; pointer-events: none; transform: translateY(-130%) rotate(-6deg);
  transition: transform .32s cubic-bezier(.6, 0, .9, .6), opacity .2s .1s;
  z-index: 8;
}
#toast::before { 
  content: ''; position: absolute; left: 15px; top: 7px; width: 13px; height: 13px; border-radius: 50%;
  background: var(--mint); box-shadow: inset 0 0 0 2.5px var(--canvas), inset 0 0 0 3.6px rgba(73, 62, 66, 0.5);
  border: 1.5px solid var(--thread); background-clip: padding-box;
}
#toast::after { 
  content: ''; position: absolute; left: 20px; top: -22px; width: 2.5px; height: 30px; background: var(--coral); border-radius: 2px;
}
#toast.show { opacity: 1; transform: translateY(0) rotate(0); animation: tagSwing 1s cubic-bezier(.3, .6, .4, 1) both; transition: none; }
@keyframes tagSwing {
  0% { transform: translateY(-120%) rotate(-9deg); }
  28% { transform: translateY(0) rotate(6deg); }
  48% { transform: rotate(-3.5deg); }
  68% { transform: rotate(2deg); }
  100% { transform: rotate(0); }
}
#banner {
  position: absolute; left: 50%; bottom: 8px; transform-origin: 16px 50%; transform: translate(-50%, 28px) rotate(-8deg) scale(0.85);
  width: min(390px, calc(100% - 16px)); padding: 6px 16px 6px 44px;
  display: flex; align-items: center; gap: 10px; isolation: isolate;
  color: var(--ink);
  opacity: 0; pointer-events: none; z-index: 9; cursor: pointer;
  filter: drop-shadow(0 6px 5px rgba(58, 38, 20, 0.36)) drop-shadow(0 2px 2px rgba(58, 38, 20, 0.3));
  transition: transform .3s cubic-bezier(.2,1.5,.4,1), opacity .22s;
}
#banner::after { 
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: var(--felt), var(--paper); background-blend-mode: soft-light, normal;
  clip-path: polygon(24px 0, calc(100% - 9px) 0, 100% 9px, 100% calc(100% - 9px), calc(100% - 9px) 100%, 24px 100%, 0 50%);
  box-shadow: inset 0 0 0 3px var(--paper), inset 0 0 0 4.4px rgba(217, 133, 115, 0.9);
}
#banner::before { 
  content: ''; position: absolute; left: 13px; top: 50%; margin-top: -40px; width: 24px; height: 52px; z-index: 1; pointer-events: none;
  background:
    radial-gradient(circle at 12px 40px, var(--mint) 0 3.6px, var(--thread) 3.6px 5.2px, var(--canvas) 5.2px 7.6px, transparent 8px),
    radial-gradient(circle at 12px 6px, transparent 0 3.4px, var(--coral) 3.6px 5.8px, transparent 6.2px),
    repeating-linear-gradient(0deg, var(--coral) 0 3px, #B96A59 3px 5px) 10.5px 10px / 3px 31px no-repeat;
}

#banner.show { opacity: 1; transform: translate(-50%, 0) rotate(0) scale(1); pointer-events: auto; animation: bannerSwing .9s cubic-bezier(.3, .6, .4, 1) both; }
@keyframes bannerSwing {
  0% { transform: translate(-50%, 28px) rotate(-14deg) scale(0.85); }
  30% { transform: translate(-50%, 0) rotate(7deg) scale(1.02); }
  52% { transform: translate(-50%, 0) rotate(-4deg) scale(1); }
  74% { transform: translate(-50%, 0) rotate(2deg) scale(1); }
  100% { transform: translate(-50%, 0) rotate(0) scale(1); }
}
#banner .bt { min-width: 0; flex: 1; text-align: left; }
#banner .b1 { font: 700 12px var(--f-title); color: var(--coral); letter-spacing: 1.4px; }
#banner .b2 { font: 700 clamp(21px, 4.2vmin, 28px)/1.05 var(--f-title); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#banner .b3 { font: 700 14px/1.15 var(--f-body); }
#banner img { width: 48px; height: 48px; flex: none; object-fit: contain; filter: drop-shadow(0 2px 2px rgba(58, 38, 20, 0.4)); }
#stageWrap.ban #selwrap { visibility: hidden; }


#selwrap {
  position: absolute; left: 0; right: 0; bottom: 14px; z-index: 6;
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
  padding: 0 8px;
}
#selwrap[hidden] { display: none; }
#selwrap.atTop { bottom: auto; top: 14px; flex-direction: column-reverse; }
#selname { font: 700 15px var(--f-title); padding: 2px 12px 3px; border-radius: 7px; background: var(--paper); color: var(--ink); box-shadow: var(--soft); }
#selbar, #swatches {
  display: flex; gap: 6px; padding: 6px; pointer-events: auto;
  background: var(--felt), var(--deep); background-blend-mode: soft-light, normal; border-radius: 16px;
  box-shadow: var(--soft-up), inset 0 0 0 3px var(--deep), inset 0 0 0 4.4px rgba(232, 223, 201, 0.5);
  max-width: 100%;
}
#selbar { padding: 8px; }
#swatches { overflow-x: auto; scrollbar-width: none; touch-action: pan-x; padding: 8px 10px; }
#swatches::-webkit-scrollbar { display: none; }
#swatches[hidden] { display: none; }
.sb {
  width: 48px; height: 48px; min-width: 44px; flex: none;
  --r: 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--felt), var(--canvas); background-blend-mode: soft-light, normal; color: var(--ink);
  box-shadow: var(--soft);
  transition: transform .08s, box-shadow .08s;
}
.sb:active { transform: translateY(2px) scale(0.95); box-shadow: 0 1px 1px rgba(0, 0, 0, 0.4); }
.sb.on { background-color: var(--mustard); }
.sb.danger { background-color: var(--coral); }
.sb[hidden] { display: none; }
.sw {
  width: 44px; height: 44px; flex: none; border-radius: 50%; padding: 4px;
  display: flex; align-items: center; justify-content: center;
}

.sw i { position: relative; width: 100%; height: 100%; border-radius: 50%; background: var(--felt), var(--c); background-blend-mode: soft-light, normal; box-shadow: 0 2px 3px rgba(0, 0, 0, 0.45), inset 0 0 0 2.5px var(--c), inset 0 0 0 3.8px rgba(232, 223, 201, 0.75); }
.sw.orig i { --c: var(--canvas); background: conic-gradient(var(--coral), var(--mustard), var(--mint), var(--denim), var(--mauve), var(--coral)); }
.sw.on { outline: 3px dashed var(--mustard); outline-offset: 0; }


#tray {
  grid-area: tray;
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  margin: 0 calc(8px + var(--safe-right)) 8px calc(8px + var(--safe-left));
  padding: 0 8px 8px;
  border-radius: 14px;
  background: linear-gradient(rgba(255, 232, 196, 0.34), rgba(255, 232, 196, 0.22)), var(--wood) url('assets/table.webp') 30% 20% / 900px auto;
  border: 2px solid var(--wood-d);
  box-shadow: 0 10px 18px rgba(58, 38, 20, 0.4), 0 2px 3px rgba(58, 38, 20, 0.4), inset 0 2px 0 rgba(255, 244, 222, 0.5), inset 0 -3px 0 rgba(120, 80, 40, 0.35);
  position: relative;
  z-index: 4;
}
#tray.trash::after {
  content: 'Let go to remove'; position: absolute; inset: 0; z-index: 3; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(217, 133, 115, 0.9); color: var(--ink); font: 700 24px var(--f-title);
}

#tabs {
  display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; padding: 7px 0 6px; flex: none;
  overflow: visible;
}
.tab {
  --r: 9px;
  min-width: 0; min-height: 52px; padding: 3px 1px 5px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 1px;
  background: var(--felt), var(--canvas); background-blend-mode: soft-light, normal;
  color: var(--ink);
  font: 700 13px/1 var(--f-title); position: relative;
  box-shadow: 0 1px 2px rgba(58, 38, 20, 0.45);
  transition: transform .14s cubic-bezier(.3, 1.5, .5, 1), box-shadow .14s;
  --stc: rgba(46, 36, 39, 0.45);
}
.tab span { max-width: 100%; overflow: hidden; text-overflow: clip; white-space: nowrap; }
.tab img { width: 30px; height: 30px; flex: none; object-fit: contain; pointer-events: none; -webkit-user-drag: none; filter: drop-shadow(0 1px 1px rgba(58, 38, 20, 0.4)); }
.tab:active { transform: translateY(1px) scale(0.97); }
.tab.on { transform: translateY(-4px) rotate(-1.2deg); box-shadow: var(--soft-up); background-color: #F2E9CF; --stc: var(--coral); }
.tab.on::before { border-width: 2.2px; }
.tab .dot { position: absolute; top: -7px; right: -5px; width: 17px; height: 17px; border-radius: 50%; background: var(--coral); box-shadow: var(--soft), inset 0 0 0 2px var(--coral), inset 0 0 0 3.2px rgba(255, 244, 222, 0.8); z-index: 1; }

@media (max-width: 599px) {
  :root { --tray-h: clamp(212px, 38dvh, 340px); }
  #tabs { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px 5px; padding: 8px 0 6px; }
  .tab { min-height: 47px; padding-bottom: 5px; }
  .tab img { width: 26px; height: 26px; }
}


#grid {
  flex: 1; min-height: 0; padding: 8px; gap: 8px; position: relative;
  overflow-x: auto; overflow-y: hidden; touch-action: pan-x;
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(var(--rows, 2), var(--cell)); grid-auto-columns: var(--cell);
  align-content: start; justify-content: start;
  scrollbar-width: none;
  border-radius: 8px;
  background: var(--felt), var(--tan); background-blend-mode: soft-light, normal; background-attachment: local, local;
  box-shadow: inset 0 3px 7px rgba(58, 38, 20, 0.5), inset 0 -1px 0 rgba(255, 240, 215, 0.4), inset 3px 0 5px rgba(58, 38, 20, 0.2);
}
#grid::-webkit-scrollbar { display: none; }

#grid.still, #grid.still .tile { touch-action: none; }

#grid.two::before {
  content: ''; position: absolute; left: 0; top: calc(8px + var(--cell) + 1px); height: 6px; width: var(--span, 100%); z-index: 0;
  background: linear-gradient(#cfa377, #a97b4c); border-top: 1px solid rgba(255, 240, 215, 0.5); border-bottom: 1px solid var(--wood-d);
  box-shadow: 0 1px 2px rgba(58, 38, 20, 0.4); pointer-events: none;
}
.tile {
  position: relative; width: var(--cell); height: var(--cell); z-index: 1;
  display: flex; align-items: center; justify-content: center;
  touch-action: pan-x; overflow: visible;
  border-radius: 12px;
}
.tile img { width: 82%; height: 72%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; transition: transform .15s; filter: drop-shadow(0 3px 2px rgba(58, 38, 20, 0.42)); margin-top: -8%; }
.tile:hover img { transform: scale(1.07) rotate(-2deg); }
.tile:active img { transform: scale(0.95); filter: drop-shadow(0 1px 1px rgba(58, 38, 20, 0.4)); }
.tile .nm { position: absolute; left: 0; right: 0; bottom: 1px; padding: 0 1px; font: 800 12.5px/1.1 var(--f-body); font-variant-numeric: tabular-nums; text-align: center; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.locked img { filter: brightness(0) opacity(0.34); }
.tile .lk { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; color: var(--ink); }
.tile .lk .ic { width: 24px; height: 24px; stroke-width: 2.6; }
.tile .nw { position: absolute; top: 3px; left: 3px; padding: 1px 6px 0; border-radius: 6px; background: var(--coral); color: var(--ink); font: 800 11px/17px var(--f-body); box-shadow: var(--soft), inset 0 0 0 1.5px var(--coral), inset 0 0 0 2.6px rgba(255, 244, 222, 0.75); }
.tile .ck { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; background: var(--mint); color: var(--ink); box-shadow: var(--soft), inset 0 0 0 2px var(--mint), inset 0 0 0 3.2px rgba(255, 244, 222, 0.75); display: flex; align-items: center; justify-content: center; }
.tile .ck .ic { width: 13px; height: 13px; stroke-width: 4; }
.tile.pulse::after { content: ''; position: absolute; inset: 1px; border-radius: 14px; border: 3px solid var(--coral); animation: tilePulse 1.2s ease-in-out infinite; pointer-events: none; }
@keyframes tilePulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.08); opacity: 0.45; } }

#more {
  position: absolute; right: 10px; top: 50%; width: 44px; height: 44px; margin-top: -22px; z-index: 3; pointer-events: none;
  display: none; align-items: center; justify-content: center; color: var(--ink); border-radius: 50%;
  background: var(--felt), var(--mustard); background-blend-mode: soft-light, normal;
  box-shadow: var(--soft-up), inset 0 0 0 2.5px var(--mustard), inset 0 0 0 3.8px rgba(46, 36, 39, 0.5);
  animation: nudge 1.3s ease-in-out infinite;
}
#more .ic { width: 26px; height: 26px; stroke-width: 3; }
#tray.more #more { display: flex; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(7px); } }

@media (orientation: landscape) and (min-aspect-ratio: 11/10) {
  #tray { flex-direction: row; padding: 8px 8px 8px 0; margin: 0 calc(8px + var(--safe-right)) 8px 0; border-radius: 14px; }
  #tabs {
    grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(12, minmax(0, 1fr)); gap: 4px;
    width: 76px; padding: 0 8px 0 8px;
  }
  .tab { min-height: 0; width: 100%; padding: 2px 1px 5px; }
  .tab.on { transform: translateX(-4px) rotate(-1.2deg); }
  .tab img { flex: 1 1 0; min-height: 0; height: auto; width: 100%; max-width: 32px; }
  #grid {
    overflow-x: hidden; overflow-y: auto; touch-action: pan-y;
    grid-auto-flow: row; grid-template-rows: none; grid-auto-rows: var(--cell);
    grid-template-columns: repeat(var(--cols, 2), var(--cell)); grid-auto-columns: var(--cell);
    align-content: start; justify-content: center; justify-items: center;
  }
  #grid.two::before { display: none; }
  
  #grid {
    background:
      repeating-linear-gradient(to right, transparent 0, transparent calc(var(--cell) + 1px), #d7ac80 calc(var(--cell) + 1px), #d7ac80 calc(var(--cell) + 2px), #a97b4c calc(var(--cell) + 2px), #a97b4c calc(var(--cell) + 6px), #7c5735 calc(var(--cell) + 6px), #7c5735 calc(var(--cell) + 7px), transparent calc(var(--cell) + 7px), transparent calc(var(--cell) + 8px)) 8px 0 / 100% 100% no-repeat,
      repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--cell) + 1px), #d7ac80 calc(var(--cell) + 1px), #d7ac80 calc(var(--cell) + 2px), #a97b4c calc(var(--cell) + 2px), #a97b4c calc(var(--cell) + 6px), #7c5735 calc(var(--cell) + 6px), #7c5735 calc(var(--cell) + 7px), transparent calc(var(--cell) + 7px), transparent calc(var(--cell) + 8px)) 0 8px / 100% 100% no-repeat,
      var(--felt), var(--tan);
    background-blend-mode: normal, normal, soft-light, normal; background-attachment: local, local, local, local;
  }
  #more { display: none !important; }
  .tile { touch-action: pan-y; }
}

@media (orientation: landscape) and (min-aspect-ratio: 11/10) and (max-height: 660px) {
  :root { --tray-w: clamp(330px, 44vw, 440px); }
  #tabs { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(4, minmax(0, 1fr)); width: auto; padding: 0 6px 0 6px; }
  .tab { min-height: 44px; font-size: 10px; }
  .tab.on { transform: translateY(-2px) rotate(-1deg); }
  .tab img { max-width: 26px; }
}


#modal {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: rgba(54, 40, 28, 0.62); padding: calc(10px + var(--safe-top)) calc(10px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(10px + var(--safe-left));
}
#modal[hidden] { display: none; }
.sheet {
  width: min(760px, 100%); max-height: 100%; display: flex; flex-direction: column;
  background: var(--felt), var(--canvas); background-blend-mode: soft-light, normal; border: 7px solid var(--wood); border-radius: 18px;
  box-shadow: 0 0 0 2px var(--wood-d), 0 14px 26px rgba(30, 18, 8, 0.5), inset 0 0 0 2px rgba(138, 98, 64, 0.5);
  overflow: hidden; position: relative;
}
.sheet-h { display: flex; align-items: center; gap: 10px; padding: 9px 12px 8px; background: rgba(163, 125, 145, 0.0); border-bottom: 2px dashed rgba(73, 62, 66, 0.5); }
.sheet-h h2 { flex: 1; font: 700 clamp(24px, 3.8vmin, 32px)/1 var(--f-title); color: var(--ink); }
.sheet-b { padding: 12px; overflow-y: auto; min-height: 0; touch-action: pan-y; }
.btn {
  --c: var(--mustard);
  min-width: 44px; min-height: 44px; padding: 0 16px;
  background: var(--felt), var(--c); background-blend-mode: soft-light, normal; color: var(--ink);
  font: 800 16px var(--f-body); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: var(--soft);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(2px) scale(0.97); box-shadow: 0 1px 1px rgba(58, 38, 20, 0.4); }
.btn.alt { --c: var(--denim); }
.btn.red { --c: var(--coral); }
.btn.sm { min-height: 44px; padding: 0 12px; font-size: 14px; }
.btn[disabled] { opacity: 0.5; filter: saturate(0.4); }


#shelfGrid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px 12px; padding: 14px 10px 12px;
  border-radius: 10px;
  background:
    radial-gradient(circle, rgba(58, 38, 20, 0.55) 0 3px, rgba(58, 38, 20, 0) 3.6px) 0 0 / 26px 26px,
    var(--felt), #D8BE98;
  background-blend-mode: normal, soft-light, normal;
  box-shadow: inset 0 3px 8px rgba(58, 38, 20, 0.45);
}
.card {
  background: none; padding: 0; display: flex; flex-direction: column; gap: 6px; position: relative;
}
.card .thumb {
  position: relative; width: 100%; aspect-ratio: 1; border-radius: 10px; overflow: visible; padding: 0; border: 0; margin-top: 12px;
  background: var(--felt), var(--canvas); background-blend-mode: soft-light, normal;
  box-shadow: var(--soft-up), inset 0 0 0 3px var(--canvas), inset 0 0 0 4.4px rgba(73, 62, 66, 0.5);
}
.card .thumb::before { 
  content: ''; position: absolute; left: 50%; top: -15px; width: 14px; height: 24px; margin-left: -7px; border-radius: 4px 4px 7px 7px;
  background: linear-gradient(90deg, #cfa377, #a97b4c); border: 1.5px solid var(--wood-d); box-shadow: 0 2px 2px rgba(58, 38, 20, 0.4);
}
.card .thumb canvas { width: 100%; height: 100%; display: block; position: relative; }
.card .thumb.cur { outline: 3px dashed var(--coral); outline-offset: 3px; }
.card .cn { font: 700 16px/1.1 var(--f-title); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); background: var(--paper); border-radius: 4px 10px 10px 4px; padding: 3px 8px 4px; box-shadow: var(--soft); margin: 0 6px; }
.card .row { display: flex; gap: 6px; }
.card .row .btn { flex: 1; padding: 0 6px; }
.empty { text-align: center; padding: 28px 12px; font: 700 18px/1.3 var(--f-body); color: var(--ink); }
.empty b { color: #B5604D; }

#bookList { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.disc { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 10px; background: var(--felt), var(--paper); background-blend-mode: soft-light, normal; box-shadow: var(--soft), inset 0 0 0 3px var(--paper), inset 0 0 0 4.4px rgba(73, 62, 66, 0.4); }
.disc img { width: 64px; height: 64px; object-fit: contain; flex: none; filter: drop-shadow(0 2px 2px rgba(58, 38, 20, 0.35)); }
.disc.lock > img { filter: brightness(0) opacity(0.3); }
.disc .dn { font: 700 21px/1.1 var(--f-title); }
.disc .dh { font: 700 15px/1.25 var(--f-body); opacity: 0.92; margin-top: 2px; }
.disc.got { box-shadow: var(--soft), inset 0 0 0 3px var(--paper), inset 0 0 0 4.6px var(--coral); }
.disc.got .dn { color: #B5604D; }
.snackrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.snackrow .sn { display: flex; align-items: center; gap: 6px; padding: 4px 12px 4px 6px; border-radius: 9px; background: var(--felt), var(--paper); background-blend-mode: soft-light, normal; box-shadow: var(--soft); font: 800 13px var(--f-body); }
.snackrow .sn img { width: 30px; height: 30px; object-fit: contain; }
.snackrow .sn.no img { filter: brightness(0) opacity(0.3); }
.sheet-b h3 { font: 700 21px var(--f-title); color: var(--ink); margin: 16px 0 6px; }

#cardPrev { display: flex; flex-direction: column; align-items: center; gap: 12px; }
#cardPrev img { max-width: 100%; max-height: calc(var(--vvh) - 230px); object-fit: contain; border-radius: 6px; box-shadow: var(--soft-up); -webkit-user-select: auto; user-select: auto; -webkit-touch-callout: default; }


#carry {
  position: fixed; left: 0; top: 0; width: 96px; height: 96px; margin: 0; pointer-events: none; z-index: 40;
  object-fit: contain; filter: drop-shadow(0 10px 8px rgba(58, 38, 20, 0.45)); transform-origin: center;
}
#carry[hidden] { display: none; }

@media (max-height: 420px) and (orientation: landscape) {
  #hint { top: 4%; padding: 6px 12px; }
}
@media (max-height: 480px) { #selname { display: none; } }
@media (prefers-reduced-motion: reduce) {
  #hint, .tile.pulse::after, #more { animation: none; }
  #toast.show, #banner.show { animation: none; }
}


.card .row { align-items: stretch; }
.card .row .btn { flex: 1 1 auto; min-width: 0; padding: 0 8px; gap: 5px; }
.card .row .btn:last-child { flex: 0 0 auto; min-width: 52px; }
.card .row .btn.alt span { overflow: hidden; text-overflow: clip; }


.rc { display: flex; align-items: center; flex-wrap: wrap; gap: 3px; margin-top: 6px; }
.rc img { width: 36px; height: 36px; object-fit: contain; flex: none; border-radius: 8px; padding: 2px; pointer-events: none; filter: drop-shadow(0 1px 1px rgba(58, 38, 20, 0.4)); }
.rc .pl { font: 700 20px/1 var(--f-title); color: #B5604D; padding: 0 1px; }
.rc.many img { width: 28px; height: 28px; }
#toast .rc { justify-content: flex-start; margin-top: 4px; }
#toast .rc img { width: 28px; height: 28px; }
@media (max-height: 340px) and (orientation: landscape) {
  #banner { padding: 3px 10px 3px 34px; width: min(340px, calc(100% - 16px)); }
  #banner img { width: 36px; height: 36px; }
  #banner .b1 { display: none; }
  #banner .b2 { font-size: 20px; }
  #banner .b3 { font-size: 12px; }
}

@media (max-width: 599px) {
  #btnUndo, #btnRedo { flex: 0 0 46px; min-width: 44px; }
  #table .p-scissors, #table .p-spool, #table .p-pins, #table .p-bowl { display: none; }
  #nameInput { font-size: 18px; }
}

@media (max-width: 599px) { .tile .nm { font-size: 11px; letter-spacing: -0.2px; } }

@media (max-width: 359px) {
  #tray { margin-left: calc(5px + var(--safe-left)); margin-right: calc(5px + var(--safe-right)); padding: 0 5px 6px; }
  #tabs { gap: 5px 4px; }
}

@media (orientation: landscape) and (min-aspect-ratio: 11/10) and (max-width: 940px) {
  #topbar { grid-template-columns: 44px minmax(110px, 210px) minmax(0, 1fr) 44px; gap: 6px; }
  #actions { gap: 5px; }
  .act { width: 58px; font-size: 11.5px; }
  #btnSurprise { width: 74px; }
  #nameInput { font-size: 17px; }
}


@media (max-height: 480px) and (orientation: landscape) {
  #toast { left: 16px; max-width: 132px; font-size: 12px; padding: 17px 10px 6px 10px; }
  #toast .rc img { width: 22px; height: 22px; }
}
