:root {
  color-scheme: light;
  -webkit-text-size-adjust: 100%;
  font-family: system-ui, -apple-system, 'Hiragino Kaku Gothic ProN', sans-serif;
  color: #2a2328;
  background: #fff;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  height: 100svh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  border: 0;
  border-radius: 8px;
  background: #f3f4f6;
  min-height: 44px;
  padding: 9px 13px;
}
button:disabled { opacity: .4; }
button:focus-visible { outline: 2px solid #886749; outline-offset: 2px; }
[hidden] { display: none !important; }
.shell {
  width: 100%;
  max-width: 450px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  padding: 0 12px max(4px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.hud strong { font-size: 22px; }
.hud button { width: 44px; font-size: 18px; }
.recipe { padding: 12px 0 4px; }
.recipe-caption {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
  font-size: 12px;
  margin-bottom: 8px;
}
.recipe-caption span { font-size: 11px; color: #6e626a; }
#recipe { display: flex; gap: 4px; }
.recipe-piece {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.swatch { height: 12px; border-radius: 3px; background: var(--food); }
.board-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px 0;
  container-type: size;
}
.board {
  width: min(100%, 100cqh, 366px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 6px 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  background: #faf8f4;
  border: 1px solid #e4ddd1;
  border-radius: 8px;
  touch-action: none;
  overflow: visible;
  transition: transform .16s, background .16s;
}
.cell.empty { background: #fafafa; border-color: transparent; pointer-events: none; }
.layer {
  flex: 0 1 10px;
  min-height: 5px;
  border: 1px solid #54381726;
  border-radius: 4px;
  background: var(--food);
  position: relative;
  pointer-events: none;
}
.layer.bread { flex-basis: 18px; border-radius: 8px 8px 4px 4px; border: 2px solid #d5a765; }
.layer.lettuce { border-radius: 7px 3px 7px 3px; }
.layer.tomato { border-radius: 40%; border-color: #c7554b; }
.layer.cheese { clip-path: polygon(0 0,100% 0,100% 80%,80% 65%,65% 100%,0 80%); }
.layer.ham { border-radius: 8px; }
.layer.has-art, .swatch.has-art {
  border: 0;
  border-radius: 0;
  background-color: transparent;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  clip-path: none;
}
.cell[data-count='1'] .layer { height: 24px; flex: none; }
.cell[data-count='1'] .layer.bread { height: 28px; }
.food-label { font-size: 11px; margin-top: 5px; line-height: 16px; pointer-events: none; color: #594738; white-space: nowrap; }
.cell.active { background: #eee5d5; transform: scale(.97); }
.cell.hint:after {
  content: '→';
  position: absolute;
  z-index: 3;
  font-size: 26px;
  color: #715039;
  right: -13px;
  top: 34%;
  pointer-events: none;
}
.cell.hint[data-dir='down']:after { content: '↓'; right: 40%; top: auto; bottom: -22px; }
.cell.hint[data-dir='left']:after { content: '←'; left: -13px; right: auto; }
.cell.hint[data-dir='up']:after { content: '↑'; right: 40%; top: -22px; }
.instruction { text-align: center; padding: 6px 0; min-height: 30px; font-size: 12px; color: #6e626a; line-height: 1.5; }
.tools { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; gap: 8px; }
.tools button { font-size: 12px; white-space: nowrap; }
.tools small { color: #6e626a; }
.tools span { font-size: 11px; color: #6e626a; }
.buddy { display: flex; align-items: center; gap: 8px; flex: none; min-height: 60px; }
.buddy img { width: 52px; height: 52px; object-fit: contain; flex: none; }
.buddy b, .cast-name { font-size: 11px; color: #6e626a; }
.buddy p { font-size: 13px; line-height: 1.5; margin: 3px 0; }
.shell:has(.overlay:not([hidden])) .buddy { visibility: hidden; }
.overlay { position: absolute; inset: 0; z-index: 5; background: #fff; display: flex; align-items: center; justify-content: center; overflow-y: auto; padding: 12px 0; text-align: center; }
.panel { width: 100%; max-width: 310px; margin: auto; }
.hero { width: 72px; height: 72px; display: block; margin: 0 auto 4px; object-fit: contain; }
.panel h2 { font-size: 21px; line-height: 1.4; margin: 12px 0 8px; }
.panel p { font-size: 13px; line-height: 1.65; margin: 10px 0; }
.panel #panel-copy { color: #6e626a; }
#howto { margin: 18px 0; }
.primary { font-weight: 700; font-size: 15px; min-height: 48px; width: 100%; margin-top: 10px; }
.primary:focus-visible { outline-offset: -3px; }
.panel .best { font-size: 12px; margin-bottom: 0; color: #6e626a; }
#save-note { font-size: 11px; color: #8b554e; }
#result { white-space: pre-line; font-variant-numeric: tabular-nums; font-size: 16px; margin: 18px 0; }
.board.bump { animation: bump .22s; }
.board.solved { animation: solved .65s; }
.urgent { color: #b24e47; }
@keyframes bump { 50% { transform: translateX(4px); } }
@keyframes solved { 50% { transform: scale(1.025); } }
@media (max-height: 620px) {
  .recipe { padding-top: 8px; }
  .hero { width: 56px; height: 56px; }
  .panel h2 { margin-top: 8px; font-size: 20px; }
  .panel p { margin: 7px 0; }
  #howto { margin: 12px 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *:before, *:after { animation: none !important; transition: none !important; }
}
