:root {
  --red: #d7322a; --red-dk: #9e1d18; --cream: #fbf3df; --ink: #2b1a14; --yellow: #ffd23a; --mint: #a9d6c0;
  --table: #2b1d16; --display: 'Luckiest Guy', 'Arial Black', Impact, sans-serif; --text: 'Karla', system-ui, sans-serif;
  --ab-fg: var(--ink); --ab-muted: #6d5a50; --ab-accent: var(--red);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--table); color: var(--cream); font-family: var(--text); overflow: hidden;
  background-image: radial-gradient(120% 90% at 50% 40%, #4a3326 0%, #2b1d16 60%, #1c120d 100%);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ------------------------------------------------ loading */
.loader { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--table); transition: opacity .5s; pointer-events: none; }
.loader.done { opacity: 0; }
.loader-card { width: 132px; height: 180px; border-radius: 6px; background: var(--mint); border: 9px solid var(--red); display: grid; place-items: center; align-content: center; gap: 26px; box-shadow: 0 16px 40px rgba(0,0,0,.5); }
.loader-nose { width: 34px; height: 32px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff6e0 0 8%, #ff6a4a 30%, #c51d14 100%); animation: nose 1s ease-in-out infinite; }
@keyframes nose { 50% { filter: brightness(1.6) drop-shadow(0 0 12px #ff3b25); } }
.loader-bar { width: 80px; height: 6px; border-radius: 3px; background: rgba(0,0,0,.18); overflow: hidden; }
.loader-bar i { display: block; height: 100%; width: 0; background: var(--red); transition: width .2s; }

/* ------------------------------------------------ the table: lid, board, tray */
.table { height: 100%; height: 100dvh; display: grid; grid-template-columns: minmax(200px, 270px) minmax(0, auto) minmax(150px, 230px); justify-content: center; align-items: center; gap: clamp(14px, 2.4vw, 36px); padding: 16px clamp(12px, 2vw, 28px); }
.lid-strip { display: none; }
.board-area { height: calc(100dvh - 32px); min-width: 0; display: grid; place-items: center; aspect-ratio: 2 / 3; max-width: 100%; }
@supports not (height: 100dvh) { .table { height: 100vh; } .board-area { height: calc(100vh - 32px); } }
.board-wrap { position: relative; border-radius: 6px; box-shadow: 0 2px 0 #7d140f, 0 4px 0 #5e0f0b, 0 24px 50px rgba(0,0,0,.55); touch-action: none; overflow: hidden; background: var(--mint); }
.board-wrap canvas { display: block; touch-action: none; cursor: none; user-select: none; -webkit-user-select: none; }
@media (pointer: coarse) { .board-wrap canvas { cursor: default; } }
.board-wrap.shake { animation: shake .5s cubic-bezier(.36,.07,.19,.97); }
@keyframes shake { 10%, 90% { transform: translate(-1px, 0) rotate(-.15deg); } 20%, 80% { transform: translate(2px, 0) rotate(.2deg); } 30%, 50%, 70% { transform: translate(-3px, 1px) rotate(-.3deg); } 40%, 60% { transform: translate(3px, -1px) rotate(.3deg); } }
@media (prefers-reduced-motion: reduce) { .board-wrap.shake { animation: none; } }

.cavity-keys { position: absolute; inset: 0; pointer-events: none; }
.cavity-key { position: absolute; padding: 0; border: 0; border-radius: 50%; background: transparent; pointer-events: none; opacity: 1; }
.cavity-key:focus { outline: none; }
.cavity-key:focus-visible { outline: 3px dashed var(--yellow); outline-offset: 0; box-shadow: 0 0 0 9999px rgba(0,0,0,.12); }

.tag { position: absolute; left: 0; top: 0; pointer-events: none; padding: 5px 10px 3px; background: var(--cream); color: var(--red); font: 17px/1 var(--display); letter-spacing: .02em; border-radius: 3px; box-shadow: 0 2px 0 rgba(0,0,0,.25), 0 6px 14px rgba(0,0,0,.3); white-space: nowrap; opacity: 0; transition: opacity .15s; border: 2px solid var(--red); }
.tag.on { opacity: 1; }

.zoom-out { position: absolute; left: 10px; top: 10px; width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--cream); background: var(--red); color: var(--cream); display: grid; place-items: center; box-shadow: 0 3px 0 var(--red-dk), 0 6px 14px rgba(0,0,0,.35); cursor: pointer; }
.zoom-out svg { width: 22px; height: 22px; }
.zoom-out[hidden] { display: none; }

/* the box lid */
.lid { align-self: stretch; display: flex; flex-direction: column; gap: 16px; min-height: 0; max-height: calc(100dvh - 32px); }
.lid-face { flex: none; padding: 18px 16px 16px; border-radius: 8px; background: linear-gradient(160deg, #e2402f, var(--red) 50%, #b8261f); border: 4px solid var(--yellow); box-shadow: inset 0 0 0 3px var(--red-dk), 0 10px 24px rgba(0,0,0,.45); transform: rotate(-1.5deg); }
.brand { margin: 0; font: clamp(30px, 3vw, 44px)/.92 var(--display); color: var(--yellow); text-shadow: 3px 3px 0 var(--red-dk), 5px 5px 0 rgba(0,0,0,.25); letter-spacing: .01em; }
.spare { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--cream); color: var(--ink); border-radius: 4px; padding: 14px 6px 10px 14px; box-shadow: 0 10px 24px rgba(0,0,0,.4); transform: rotate(.6deg); }
.spare-h { margin: 0 0 8px; font: 22px/1 var(--display); color: var(--red); letter-spacing: .02em; }
.spare-list { list-style: none; margin: 0; padding: 0 8px 0 0; overflow: auto; flex: 1; min-height: 0; }
.spare-list li + li { border-top: 1px dashed rgba(43,26,20,.25); }
.spare-list button { display: block; width: 100%; text-align: left; padding: 4px 4px 3px; border: 0; background: none; font: 700 13px/1.2 var(--text); text-transform: uppercase; letter-spacing: .04em; color: var(--ink); cursor: pointer; border-radius: 3px; }
.spare-list button:hover { background: rgba(215,50,42,.1); color: var(--red-dk); }

/* the tray */
.tray { align-self: stretch; display: flex; flex-direction: column; gap: 10px; min-height: 0; max-height: calc(100dvh - 32px); }
.tray-list { list-style: none; margin: 0; padding: 12px; flex: 1; min-height: 120px; overflow: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: max-content; gap: 10px; align-content: start;
  background: radial-gradient(circle at 50% 50%, rgba(0,0,0,.07) 0 26px, transparent 28px) 0 0 / 50% 96px, linear-gradient(180deg, #f2f2ee, #dcdcd6); border-radius: 14px; box-shadow: inset 0 3px 8px rgba(0,0,0,.25), inset 0 -2px 0 rgba(255,255,255,.7), 0 10px 24px rgba(0,0,0,.4); }
.tray-list li { min-width: 0; }
.tray-list li.arriving .tray-piece img { opacity: 0; }
.tray-piece { display: grid; justify-items: center; gap: 4px; width: 100%; padding: 6px 4px; border: 0; border-radius: 10px; background: rgba(0,0,0,.06); box-shadow: inset 0 2px 5px rgba(0,0,0,.18); cursor: pointer; }
.tray-piece:hover { background: rgba(215,50,42,.12); }
.tray-piece img { width: 100%; height: 70px; object-fit: contain; filter: drop-shadow(2px 3px 2px rgba(0,0,0,.4)); }
.tray-cap { font: 11px/1.1 var(--display); color: var(--red-dk); letter-spacing: .03em; text-align: center; overflow-wrap: anywhere; }
.tray-tools { display: flex; gap: 10px; justify-content: flex-end; }
.tool { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(251,243,223,.12); color: var(--cream); display: grid; place-items: center; cursor: pointer; }
.tool:hover { background: rgba(251,243,223,.22); }
.tool svg { width: 22px; height: 22px; }
.tool[hidden] { display: none; }
#sound[aria-pressed="true"] .off, #sound[aria-pressed="false"] .on { display: none; }
.flyer { position: fixed; z-index: 5; pointer-events: none; object-fit: contain; filter: drop-shadow(6px 10px 8px rgba(0,0,0,.45)); }

/* ------------------------------------------------ dialogs */
dialog { padding: 0; border: 0; background: transparent; color: var(--ink); max-width: none; max-height: none; }
dialog::backdrop { background: rgba(20,10,6,.62); }
.close { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--cream); background: var(--red); color: var(--cream); font: 30px/1 var(--text); display: grid; place-items: center; padding: 0 0 3px; cursor: pointer; box-shadow: 0 3px 0 var(--red-dk); z-index: 2; }

.case { width: 100vw; height: 100vh; height: 100dvh; margin: 0; }
.case-scroll { width: 100%; height: 100%; overflow: auto; overscroll-behavior: contain; padding: clamp(12px, 4vh, 40px) 12px 40px; -webkit-overflow-scrolling: touch; }
.card { position: relative; width: min(900px, 100%); margin: 0 auto; background: var(--cream); border: clamp(8px, 1.4vw, 14px) solid var(--red); border-radius: 10px; padding: clamp(16px, 3vw, 34px); box-shadow: 0 30px 60px rgba(0,0,0,.5); --ab-chrome: 140px; }
.card-head { display: flex; align-items: center; gap: clamp(12px, 2.6vw, 26px); margin: 0 50px 18px 0; }
.card-piece { width: clamp(84px, 16vw, 150px); height: clamp(84px, 16vw, 150px); object-fit: contain; flex: none; filter: drop-shadow(4px 6px 4px rgba(0,0,0,.35)); }
.card-titles { min-width: 0; }
.card-title { margin: 0; font: clamp(30px, 5vw, 54px)/.95 var(--display); color: var(--red); letter-spacing: .01em; overflow-wrap: anywhere; }
.card-client { margin: 6px 0 0; font: 800 13px/1.2 var(--text); letter-spacing: .14em; text-transform: uppercase; color: #6d5a50; }
.card-body { font: 17px/1.5 var(--text); }
.card-body .ab-lede { font-size: 1.12em; }
.card-body .ab-heading { font: 22px/1.1 var(--display); color: var(--red-dk); letter-spacing: .02em; }
.card-body .ab-credits { white-space: pre-line; }

.sheet { width: min(420px, 100vw); height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto; }
.sheet-card { position: relative; height: 100%; display: flex; flex-direction: column; background: var(--cream); padding: 22px 10px 16px 20px; box-shadow: -10px 0 30px rgba(0,0,0,.4); }
.sheet-card .spare-h { font-size: 26px; margin-bottom: 12px; }
.sheet-card .spare-list button { font-size: 16px; padding: 11px 4px 10px; }

/* ------------------------------------------------ narrow and portrait screens */
@media (max-width: 900px), (max-aspect-ratio: 1/1) {
  body { overflow: hidden; }
  .table { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; align-content: center; align-items: stretch; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .lid { display: none; }
  .lid-strip { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 6px 6px 12px; background: var(--red); border: 3px solid var(--yellow); border-radius: 8px; box-shadow: inset 0 0 0 2px var(--red-dk); }
  .brand-sm { font: 24px/1 var(--display); color: var(--yellow); text-shadow: 2px 2px 0 var(--red-dk); padding-top: 3px; }
  .strip-btn { min-height: 40px; padding: 6px 14px 3px; border: 2px solid var(--red-dk); border-radius: 6px; background: var(--cream); color: var(--red); font: 17px/1 var(--display); letter-spacing: .02em; cursor: pointer; }
  .board-area { height: auto; aspect-ratio: auto; min-height: 0; }
  .tray { flex-direction: row; align-items: center; max-height: none; gap: 6px; }
  .tray-list { background: radial-gradient(circle at 50% 50%, rgba(0,0,0,.07) 0 24px, transparent 26px) 0 0 / 68px 100%, linear-gradient(180deg, #f2f2ee, #dcdcd6); flex: 1; min-height: 76px; height: 76px; padding: 6px; grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 64px; grid-template-rows: 1fr; overflow-x: auto; overflow-y: hidden; border-radius: 12px; }
  .tray-piece { padding: 3px; height: 100%; }
  .tray-piece img { height: 100%; max-height: 58px; }
  .tray-cap { display: none; }
  .tray-tools { flex-direction: column; gap: 4px; }
  .tool { width: 40px; height: 34px; border-radius: 10px; }
  .tray-tools .tool[hidden] { display: none; }
}
@media (max-width: 900px) and (min-width: 600px) { .tray-list { grid-auto-columns: 80px; } }
