/* Fridge Stack */
html, body { height: 100%; }
body {
  min-height: 100dvh;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 20px 6px;
}
.back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--ink);
  text-decoration: none;
  font: 700 14px/1 var(--font-body);
  padding: 9px 14px 9px 8px;
  border-radius: 999px;
  border: 2px solid transparent;
  transition: background 0.2s, border-color 0.2s;
}
.back svg { width: 18px; height: 18px; }
.back:hover { background: #fff; border-color: var(--ink); }
.back:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
.title .wordmark { font-size: 24px; white-space: nowrap; text-shadow: 2px 2px 0 var(--ink); }
.actions { justify-self: end; display: flex; gap: 10px; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .i-play, .icon-btn .i-off { display: none; }
.icon-btn.off .i-on { display: none; }
.icon-btn.off .i-off { display: block; }
.icon-btn.off { color: var(--ink-faint); }
#pause { visibility: hidden; }
body[data-mode='playing'] #pause, body[data-mode='paused'] #pause { visibility: visible; }
body[data-mode='paused'] #pause .i-pause { display: none; }
body[data-mode='paused'] #pause .i-play { display: block; }

/* ---------- stage ---------- */
.stage {
  flex: 1;
  display: grid;
  grid-template-columns: 236px minmax(0, 640px);
  gap: 22px;
  justify-content: center;
  align-items: start;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px 20px;
}
.side { display: flex; flex-direction: column; gap: 14px; }
.side .card { padding: 14px 16px; }

.stop-line { display: flex; align-items: center; gap: 10px; }
.unit-name { font: 700 12px/1 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
.client { font: 800 21px/1.15 var(--font-display); margin: 12px 0 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer { height: 14px; border-radius: 99px; border: 2px solid var(--ink); background: var(--blush-2); overflow: hidden; }
.timer > i { display: block; height: 100%; width: 100%; background: var(--mint); border-right: 2px solid var(--ink); transition: background 0.3s; }
.timer.low > i { background: var(--danger); animation: blink 0.6s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.55; } }
.timer-row { display: flex; justify-content: space-between; margin-top: 7px; font: 500 12px/1 var(--font-body); color: var(--ink-muted); }
.timer-row b { font: 800 14px/1 var(--font-body); color: var(--ink); font-variant-numeric: tabular-nums; }

.score-card { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 10px; }
.score-card .stat:first-child { grid-column: 1 / -1; }
.stat-label { font: 700 11px/1 var(--font-body); letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-muted); }
.stat-value { font: 900 34px/1.05 var(--font-display); font-variant-numeric: tabular-nums; margin-top: 4px; color: var(--pink); text-shadow: 2px 2px 0 var(--ink); }
.stat-value.small { font-size: 20px; color: var(--ink); text-shadow: none; }
.tickets { display: flex; gap: 5px; margin-top: 6px; }
.tickets i {
  width: 22px; height: 16px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: #fff;
  position: relative;
}
.tickets i::after { content: ''; position: absolute; left: 3px; right: 3px; top: 4px; height: 2px; background: var(--ink-faint); box-shadow: 0 4px 0 var(--ink-faint); }
.tickets i.used { background: var(--danger); transform: rotate(-8deg); animation: ticket 0.5s var(--ease-spring); }
.tickets i.used::after { background: #fff; box-shadow: 0 4px 0 #fff; }
@keyframes ticket { from { transform: scale(1.8) rotate(-30deg); } }

.checklist h3 { margin: 0 0 10px; font: 800 16px/1 var(--font-display); }
.checklist ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.checklist li { display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; gap: 8px; font-size: 13px; }
.checklist li b { font-weight: 800; }
.checklist li span { color: var(--ink-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.checklist li em {
  font: 800 12px/1 var(--font-body);
  font-style: normal;
  min-width: 26px;
  text-align: center;
  padding: 4px 6px 3px;
  border-radius: 99px;
  border: 2px solid var(--ink);
  background: var(--sun);
}
.checklist li.done em { background: var(--mint); color: var(--ink); }
.checklist li.done em::before { content: '✓'; }
.checklist li.done em { font-size: 0; }
.checklist li.done em::before { font-size: 12px; }
.checklist li.bump em { animation: chip 0.35s var(--ease-spring); }
@keyframes chip { 40% { transform: scale(1.35) rotate(-6deg); } }
body[data-mode='title'] .side { opacity: 0.55; }

/* ---------- unit + tray ---------- */
.board-col { display: flex; flex-direction: column; align-items: center; gap: 14px; min-width: 0; }
.unit-wrap { position: relative; filter: drop-shadow(0 6px 0 rgba(45, 19, 69, 0.9)); }
#board { display: block; touch-action: none; cursor: pointer; }
.unit-wrap.bump { animation: bump 0.3s var(--ease-spring); }
@keyframes bump { 30% { transform: translateY(3px) rotate(0.4deg); } }

.tray { display: flex; align-items: center; gap: 12px; padding: 10px 12px; width: 100%; max-width: 640px; }
.tray-label { font: 800 13px/1.1 var(--font-display); writing-mode: vertical-rl; transform: rotate(180deg); color: var(--ink-muted); }
.crate { flex: 1; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; min-width: 0; }
.crate-item {
  appearance: none;
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 2px 5px;
  min-width: 0;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--blush-2);
  color: var(--ink);
  transition: transform 0.15s var(--ease-spring), background 0.15s, box-shadow 0.15s;
}
.crate-item canvas { width: 34px; height: 40px; display: block; }
.crate-item .name { font: 800 10px/1 var(--font-body); letter-spacing: 0.04em; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.crate-item .key {
  position: absolute; top: -8px; left: -6px;
  font: 800 10px/1 var(--font-body);
  background: #fff; border: 1.5px solid var(--ink); border-radius: 6px; padding: 3px 5px 2px;
}
.crate-item:hover { transform: translateY(-2px); }
.crate-item[aria-pressed='true'] { background: #fff; box-shadow: 0 0 0 3px var(--pink), 0 4px 0 var(--ink); transform: translateY(-3px) rotate(-2deg); }
.crate-item:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }

.photo-btn { flex: none; padding: 13px 18px 14px; font-size: 15px; }
.photo-btn.ready { animation: ready 1s var(--ease-out) infinite; background: var(--mint); color: var(--ink); }
@keyframes ready { 50% { transform: translateY(-3px) rotate(-2deg); box-shadow: 0 8px 0 var(--ink); } }
body:not([data-mode='playing']) .tray { opacity: 0.6; pointer-events: none; }

/* ---------- toasts ---------- */
.toasts { position: absolute; left: 0; right: 0; top: 34%; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  font: 900 20px/1 var(--font-display);
  color: #fff;
  background: var(--hue, var(--pink));
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  padding: 8px 14px 9px;
  box-shadow: 0 4px 0 var(--ink);
  animation: toast 1.3s var(--ease-out) forwards;
  white-space: nowrap;
  text-align: center;
}
.toast.dark { color: var(--ink); }
.toast small { display: block; margin-top: 3px; font: 700 12px/1.2 var(--font-body); }
@keyframes toast {
  0% { opacity: 0; transform: translateY(14px) scale(0.6) rotate(-6deg); }
  16% { opacity: 1; transform: translateY(0) scale(1.06) rotate(-2deg); }
  28% { transform: scale(1) rotate(-2deg); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-22px) rotate(-2deg); }
}

/* ---------- keyboard legend ---------- */
.keys { text-align: center; padding: 8px 16px 20px; color: var(--ink-muted); font-size: 12px; display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.keys span { display: inline-flex; gap: 4px; align-items: center; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  background: rgba(254, 218, 232, 0.72);
  overflow-y: auto;
}
body[data-mode='title'] .overlay[data-for='title'],
body[data-mode='paused'] .overlay[data-for='paused'],
body[data-mode='photo'] .overlay[data-for='photo'],
body[data-mode='over'] .overlay[data-for='over'] { display: flex; }
.overlay[data-for='title'] { background: rgba(254, 218, 232, 0.35); }

.sheet {
  width: 100%;
  max-width: 400px;
  margin: auto;
  padding: 26px 24px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  animation: pop 0.45s var(--ease-spring);
}
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(0.92) rotate(-2deg); } }
.sheet h1 { margin: 0; font-size: clamp(42px, 11vw, 56px); line-height: 0.95; }
.sheet h2 { margin: 0; font: 900 30px/1.05 var(--font-display); }
.lede { margin: 0; color: var(--ink-muted); font-size: 15px; line-height: 1.5; }
.lede b { color: var(--ink); }
.sheet .btn { min-width: 210px; }
.hint { font-size: 12px; color: var(--ink-faint); }

.rules { list-style: none; margin: 2px 0 4px; padding: 0; display: grid; gap: 10px; text-align: left; font-size: 14px; line-height: 1.4; color: var(--ink-muted); }
.rules li { display: flex; gap: 10px; align-items: flex-start; }
.rules b { color: var(--ink); }
.rules .num {
  flex: none;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  font: 900 14px/1 var(--font-display);
  color: #fff;
  background: var(--pink);
  border: 2px solid var(--ink);
  border-radius: 50%;
}
.rules li:nth-child(2) .num { background: var(--sky); }
.rules li:nth-child(3) .num { background: var(--sun); color: var(--ink); }

/* photo result */
.photo-sheet { gap: 10px; }
.polaroid {
  position: relative;
  margin: 0 0 6px;
  padding: 10px 10px 0;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 5px 0 var(--ink);
  transform: rotate(-2.5deg);
  animation: develop 0.6s var(--ease-spring);
}
@keyframes develop { from { transform: rotate(-10deg) scale(0.7); opacity: 0; } }
#snap { display: block; width: 200px; height: auto; border: 1.5px solid var(--ink); background: var(--blush-2); }
.polaroid figcaption { font: 700 13px/1 var(--font-display); padding: 10px 0 12px; }
.stamp {
  position: absolute;
  right: -22px;
  top: -14px;
  font: 900 24px/1 var(--font-display);
  color: #fff;
  background: var(--mint);
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  transform: rotate(12deg);
  box-shadow: 0 4px 0 var(--ink);
  animation: stamp 0.5s 0.35s var(--ease-spring) backwards;
}
.stamp.miss { background: var(--sun); color: var(--ink); }
.stamp.fail { background: var(--danger); }
@keyframes stamp { from { transform: scale(2.4) rotate(40deg); opacity: 0; } }
.quote { margin: -4px 0 0; font: 700 italic 15px/1.4 var(--font-body); color: var(--plum); }
.quote:empty { display: none; }
.breakdown { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.breakdown li { font: 700 12px/1 var(--font-body); padding: 6px 10px 5px; border: 2px solid var(--ink); border-radius: 99px; background: var(--blush-2); }
.breakdown li.ok { background: var(--mint); }
.breakdown li.ticket { background: var(--danger); color: #fff; }
.points { font: 900 28px/1 var(--font-display); color: var(--pink); text-shadow: 2px 2px 0 var(--ink); }

/* game over */
.final { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.big-score { display: flex; flex-direction: column; align-items: center; }
.big-score span { font: 900 clamp(48px, 13vw, 66px)/1 var(--font-display); font-variant-numeric: tabular-nums; color: var(--pink); text-shadow: 3px 3px 0 var(--ink); }
.big-score small { margin-top: 6px; font: 700 11px/1 var(--font-body); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-muted); }
.new-best { display: none; }
.final.best .new-best { display: inline-block; font: 800 14px/1 var(--font-display); padding: 7px 14px 8px; border-radius: 999px; border: 2px solid var(--ink); background: var(--sun); animation: wiggle 1.2s ease-in-out infinite; }
@keyframes wiggle { 50% { transform: rotate(-4deg) scale(1.05); } }
.final-row { display: flex; gap: 26px; }

.touch-only { display: none; }
@media (pointer: coarse) {
  .keys, .keyboard-only, .crate-item .key { display: none; }
  .touch-only { display: block; }
}

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .topbar { padding: max(6px, env(safe-area-inset-top)) 10px 2px; }
  .back span { display: none; }
  .back { padding: 9px; }
  .title .wordmark { font-size: 21px; }
  .actions { gap: 8px; }
  .icon-btn { width: 38px; height: 38px; }

  .stage { grid-template-columns: 1fr; gap: 8px; padding: 4px 10px; align-content: start; }
  .side { display: grid; grid-template-columns: 1.35fr 1fr; gap: 8px; }
  .side .card { padding: 8px 10px; border-radius: 14px; box-shadow: 0 3px 0 var(--ink); }
  .stop-line .sticker { font-size: 10px; padding: 4px 8px 3px; }
  .unit-name { font-size: 10px; }
  .client { font-size: 15px; margin: 6px 0 6px; }
  .timer { height: 10px; }
  .timer-row { display: none; }
  .score-card { grid-template-columns: 1fr; gap: 4px; align-content: center; }
  .score-card .best { display: none; }
  .stat-label { font-size: 9.5px; }
  .stat-value { font-size: 24px; margin-top: 2px; }
  .tickets { margin-top: 3px; }
  .tickets i { width: 18px; height: 13px; }
  .tickets i::after { top: 3px; box-shadow: 0 3px 0 var(--ink-faint); }
  .tickets-stat { display: flex; align-items: center; gap: 8px; }
  .tickets-stat .stat-label { display: none; }

  .checklist { grid-column: 1 / -1; padding: 6px 8px !important; }
  .checklist h3 { display: none; }
  .checklist ul { grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .checklist li { grid-template-columns: 1fr; justify-items: center; gap: 3px; font-size: 11px; }
  .checklist li span { display: none; }
  .checklist li em { min-width: 22px; padding: 3px 5px 2px; font-size: 11px; }
  body[data-mode='title'] .side { opacity: 0.4; }

  .board-col { gap: 8px; }
  .tray { padding: 7px 8px max(7px, env(safe-area-inset-bottom)); gap: 8px; border-radius: 16px; box-shadow: 0 3px 0 var(--ink); }
  .tray-label { display: none; }
  .crate { gap: 4px; }
  .crate-item { padding: 5px 1px 4px; border-radius: 10px; }
  .crate-item canvas { width: 26px; height: 32px; }
  .crate-item .name { font-size: 8.5px; }
  .photo-btn { padding: 11px 12px 12px; font-size: 13px; gap: 6px; }
  .photo-btn span { max-width: 52px; line-height: 1.05; white-space: normal; text-align: left; }
  .toast { font-size: 16px; }
  .sheet { padding: 22px 18px 18px; gap: 12px; }
  #snap { width: 170px; }
}
