:root {
  --bg: #17110d;
  --ink: #f7ecd9;
  --muted: #bba78e;
  --panel: #241912;
  --panel-2: #33241a;
  --line: #4a3627;
  --accent: #ff8a2a;
  --accent-ink: #2a1405;
  --danger: #ff6a52;
  --goo: #a8c43a;
  --tape: #efe4c2;
  --tape-ink: #33241a;
  --wood: #6b4423;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Rubik, system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100dvh; }
#app.shake { animation: screenshake 0.5s cubic-bezier(.36,.07,.19,.97); }
@keyframes screenshake {
  10%, 90% { transform: translate(-2px, 1px); }
  20%, 80% { transform: translate(5px, -3px); }
  30%, 50%, 70% { transform: translate(-9px, 4px); }
  40%, 60% { transform: translate(9px, -4px); }
}

/* ---------- header ---------- */
header.top {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: #100a07; border-bottom: 2px solid var(--line);
  position: relative; z-index: 5;
}
.logo { font-family: Bungee, sans-serif; font-size: 22px; color: var(--accent); line-height: 1; text-shadow: 2px 2px 0 #5a1f05; }
.logo small { display: block; font-family: Rubik, sans-serif; font-size: 11px; color: var(--muted); margin-top: 4px; text-shadow: none; }
nav.tabs { margin-left: auto; display: flex; gap: 6px; }
nav.tabs button {
  background: var(--panel-2); border: 2px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-weight: 500; display: flex; align-items: center; gap: 6px;
}
nav.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pill { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.icon-btn { background: none; border: 0; font-size: 20px; padding: 4px; }

.view { flex: 1; min-height: 0; display: none; }
.view.on { display: flex; }

/* ---------- kitchen / build ---------- */
#build { flex-direction: column; }
.kitchen {
  flex: 1; min-height: 0; position: relative; overflow: hidden;
  background-color: #d4e2d8;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40'%3E%3Crect width='80' height='40' fill='%23d4e2d8'/%3E%3Cpath d='M0 1H80M0 21H80M1 0V20M41 20V40' stroke='%23aebfb3' stroke-width='2'/%3E%3C/svg%3E");
}
.kitchen::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 30% 20% at 18% 30%, rgba(140,110,40,.25), transparent 70%),
    radial-gradient(ellipse 12% 9% at 80% 18%, rgba(110,130,40,.25), transparent 70%),
    radial-gradient(ellipse at 50% 35%, transparent 35%, rgba(30,18,8,.55));
}
.stage-box { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; }
#stage { display: block; touch-action: none; }
.hint {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  margin: 0; background: rgba(20,12,8,.75); padding: 6px 14px; border-radius: 999px;
  font-size: 13px; pointer-events: none; transition: opacity .4s; white-space: nowrap;
}
.hint.gone { opacity: 0; }

.card {
  position: absolute; top: 14px; right: 14px; width: 250px; z-index: 2;
  background: #fbf5e6; color: #33241a; border-radius: 6px; padding: 14px 14px 12px;
  box-shadow: 0 10px 24px rgba(0,0,0,.35); transform: rotate(1.2deg);
  background-image: repeating-linear-gradient(#fbf5e6 0 23px, #d9e4ef 23px 24px);
}
.card::before {
  content: ''; position: absolute; top: -10px; left: 50%; width: 80px; height: 22px; margin-left: -40px;
  background: rgba(240,225,170,.85); transform: rotate(-3deg); box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.fill-head { display: flex; justify-content: space-between; align-items: baseline; font-family: 'Permanent Marker', cursive; font-size: 18px; }
.fill-head b { font-weight: 400; font-size: 22px; color: #b3261e; }
.meter { position: relative; height: 12px; background: #e6dcc6; border-radius: 6px; overflow: hidden; margin: 6px 0 8px; border: 1.5px solid #33241a; }
.meter i { display: block; height: 100%; width: 0; background: #7fb34a; transition: width .3s, background .3s; }
.meter i.over { background: #e0442f; }
.meter .hs { position: absolute; top: -2px; bottom: -2px; left: calc(0.9 / 1.15 * 100%); width: 2px; background: #b3261e; }
.note { margin: 0 0 8px; font-size: 13px; line-height: 1.35; min-height: 2.7em; }
.tally { list-style: none; margin: 0 0 10px; padding: 0; max-height: 170px; overflow-y: auto; font-size: 13px; }
.tally li { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.tally .dot { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid #33241a; flex: none; }
.tally em { margin-left: auto; font-style: normal; color: #7a6450; }
.actions { display: flex; gap: 8px; }
.btn { border-radius: 10px; padding: 9px 12px; font-weight: 700; border: 2px solid #33241a; flex: 1; }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 0 #33241a; }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #33241a; }
.btn.btn-ghost { background: transparent; color: inherit; }
.btn:disabled { opacity: .6; }

/* ---------- carousel ---------- */
.carousel {
  flex: none; background: #2b1c12; border-top: 5px solid #5a3a22;
  box-shadow: inset 0 6px 10px rgba(0,0,0,.4); padding: 8px 0 calc(10px + env(safe-area-inset-bottom));
}
.chips { display: flex; gap: 6px; padding: 0 16px 6px; overflow-x: auto; scrollbar-width: none; }
.chip { flex: none; background: transparent; border: 1.5px solid var(--line); border-radius: 999px; padding: 3px 11px; font-size: 12px; color: var(--muted); }
.chip.on { background: var(--tape); color: var(--tape-ink); border-color: var(--tape); }
.rail { display: flex; align-items: center; gap: 4px; padding: 0 6px; }
.arrow { flex: none; width: 32px; height: 96px; border-radius: 10px; background: var(--panel-2); border: 2px solid var(--line); font-size: 26px; line-height: 1; }
.track {
  flex: 1; display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x proximity;
  padding: 8px 4px 6px; scrollbar-width: thin; scrollbar-color: #5a3a22 transparent; touch-action: pan-x;
}
.tile {
  flex: 0 0 96px; height: 104px; scroll-snap-align: start; position: relative;
  background: #3b291d; border: 2px solid #5a3f2b; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  cursor: grab; user-select: none; -webkit-user-select: none; touch-action: pan-x;
  transition: transform .15s, border-color .15s; box-shadow: 0 3px 0 #1b110b;
}
.tile:hover { transform: translateY(-4px); border-color: var(--accent); }
.tile:active { cursor: grabbing; }
.tile .art { width: 70px; height: 58px; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.tile .art svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 0 rgba(0,0,0,.35)); }
.tile .nm { font-size: 11.5px; line-height: 1.15; text-align: center; padding: 0 4px; pointer-events: none; }
.tile .tag {
  position: absolute; top: -7px; right: -5px; font-size: 9.5px; font-weight: 700; text-transform: uppercase;
  background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 2px 6px; pointer-events: none;
  transform: rotate(4deg);
}
.tile .tag-crack { background: #f3e1c2; }
.tile .tag-dump { background: #fbf2cf; }
.tile .tag-pour { background: #8fc6e8; }
.tile .tag-handful { background: #7fb34a; }
.ghost { position: fixed; left: 0; top: 0; z-index: 100; pointer-events: none; filter: drop-shadow(0 12px 10px rgba(0,0,0,.45)); }
.ghost svg { width: 100%; height: 100%; }

/* ---------- dialog ---------- */
dialog {
  border: 0; border-radius: 10px; padding: 20px; width: min(380px, calc(100vw - 32px));
  background: #fbf5e6; color: #33241a; box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
dialog::backdrop { background: rgba(10,6,3,.6); }
dialog h2 { margin: 0 0 12px; font-family: Bungee, sans-serif; font-weight: 400; font-size: 22px; color: #b3261e; }
dialog label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 10px; }
dialog input {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-size: 16px;
  border: 2px solid #33241a; border-radius: 8px; background: #fff; color: #33241a;
}
.err { color: #b3261e; font-size: 13px; min-height: 1.2em; margin: 0 0 8px; }

/* ---------- shelf ---------- */
#shelf { flex-direction: row; --night: 0; }
.room {
  flex: 1; min-width: 0; overflow-y: auto; position: relative; padding: 14px 16px 40px;
  background-color: color-mix(in srgb, #3a2a1f, #0b0d1c calc(var(--night) * 100%));
  transition: background-color 1s linear;
}
.room-head { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.window {
  width: 130px; height: 48px; border: 5px solid #5a3f2b; border-radius: 6px; position: relative; overflow: hidden; flex: none;
  background: color-mix(in srgb, #8fc6e8, #141a3a calc(var(--night) * 100%));
  box-shadow: inset 0 0 0 2px #2b1c12;
}
.window::after { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 4px; margin-left: -2px; background: #5a3f2b; }
.sun, .moon { position: absolute; top: 12px; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%; transition: left 1s linear, opacity 1s; }
.sun { background: #ffd34d; box-shadow: 0 0 12px #ffd34d; left: var(--sunx, 50%); opacity: calc(1.2 - var(--night) * 1.6); }
.moon { background: #e8e6da; left: var(--moonx, -20%); opacity: calc(var(--night) * 1.6 - 0.4); }
.daycount { font-family: Bungee, sans-serif; font-size: 30px; line-height: 1; }
.speed { color: var(--muted); font-size: 12px; margin-top: 4px; }
.empty-shelf { color: var(--muted); margin: 40px 0; text-align: center; }

.shelf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); row-gap: 18px; }
.cell { position: relative; display: flex; flex-direction: column; align-items: center; }
.lamp { position: relative; width: 100%; height: 66px; z-index: 3; pointer-events: none; }
.cord { position: absolute; left: 50%; top: 0; width: 2px; height: 22px; background: #0c0c0c; margin-left: -1px; }
.hood { position: absolute; left: 50%; top: 20px; width: 60px; height: 25px; margin-left: -30px; background: linear-gradient(#585858, #262626); border-radius: 30px 30px 4px 4px; border-bottom: 3px solid #888; }
.bulb { position: absolute; left: 50%; top: 45px; width: 24px; height: 11px; margin-left: -12px; background: #ff9d3c; border-radius: 0 0 12px 12px; box-shadow: 0 0 18px 7px rgba(255,120,30,.7); animation: flicker 5s infinite; }
.cone {
  position: absolute; left: 50%; top: 52px; width: 180px; height: 230px; margin-left: -90px;
  background: radial-gradient(ellipse 50% 95% at 50% 0, rgba(255,140,40,.33), transparent 78%);
  clip-path: polygon(42% 0, 58% 0, 100% 100%, 0 100%); mix-blend-mode: screen;
}
@keyframes flicker { 0%, 100% { opacity: 1; } 47% { opacity: 1; } 48% { opacity: .55; } 49% { opacity: 1; } 73% { opacity: .85; } }

.jar-wrap { position: relative; width: 120px; height: 202px; --p: 0; z-index: 2; transform-origin: 50% 100%; }
.jar-wrap canvas {
  display: block; transform-origin: 50% 96%;
  transform: scale(calc(1 + var(--p) * .14), calc(1 + var(--p) * .05));
  filter: sepia(calc(var(--p) * .75)) hue-rotate(calc(var(--p) * 45deg)) saturate(calc(1 + var(--p) * .6)) brightness(calc(1 - var(--p) * .2));
  transition: transform 1s linear, filter 1s linear;
}
.lid {
  position: absolute; left: 50%; top: 6px; width: 86px; height: 15px; margin-left: -43px;
  background: repeating-linear-gradient(90deg, #d9ab3a 0 3px, #b88a22 3px 6px);
  border: 2px solid #5e400f; border-radius: 3px;
  transform: translateY(calc(var(--p) * -12px)) rotate(calc(var(--p) * -8deg)) scaleX(calc(1 + var(--p) * .1));
  transition: transform 1s linear;
}
.lid::before { content: ''; position: absolute; left: 2px; right: 2px; top: -7px; height: 6px; background: #e8c25a; border: 2px solid #5e400f; border-bottom: 0; border-radius: 3px 3px 0 0; }
.shaking .lid::before { background: #e0442f; }
.bubbles i { position: absolute; bottom: 30px; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid rgba(210,240,140,.9); opacity: 0; }
.bubbles i:nth-child(1) { left: 30%; animation-delay: 0s; }
.bubbles i:nth-child(2) { left: 52%; animation-delay: .5s; }
.bubbles i:nth-child(3) { left: 67%; animation-delay: 1.1s; }
.bubbles i:nth-child(4) { left: 40%; animation-delay: 1.5s; }
.bubbles i:nth-child(5) { left: 60%; animation-delay: .8s; }
.bubbling .bubbles i { animation: rise 1.8s infinite ease-in; }
@keyframes rise { 0% { transform: translateY(0) scale(.6); opacity: 0; } 20% { opacity: .9; } 100% { transform: translateY(-120px) scale(1.2); opacity: 0; } }
.flies i { position: absolute; width: 4px; height: 4px; background: #111; border-radius: 50%; opacity: 0; top: 10px; left: 50%; }
.flyzone .flies i { opacity: 1; animation: buzz 2.3s infinite linear; }
.flyzone .flies i:nth-child(2) { animation-duration: 1.7s; animation-direction: reverse; }
@keyframes buzz {
  0% { transform: translate(-30px, 0); } 25% { transform: translate(10px, -22px); } 50% { transform: translate(34px, 4px); }
  75% { transform: translate(0, -10px); } 100% { transform: translate(-30px, 0); }
}
.wobble .jar-wrap { animation: wobble 1.3s ease-in-out infinite; }
.shaking .jar-wrap { animation: shakejar .14s linear infinite; }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-2.5deg); } 75% { transform: rotate(2.5deg); } }
@keyframes shakejar { 0% { transform: translate(0, 0) rotate(0); } 25% { transform: translate(-2px, 1px) rotate(-1deg); } 50% { transform: translate(2px, -1px) rotate(1deg); } 75% { transform: translate(-1px, -1px); } }

.boomed .lid, .boomed .bubbles, .boomed .flies { display: none; }
.splat {
  position: absolute; left: -36px; right: -36px; bottom: -6px; height: 150px; z-index: -1;
  background:
    radial-gradient(circle at 18% 78%, var(--c1) 0 16px, transparent 17px),
    radial-gradient(circle at 78% 70%, var(--c2) 0 22px, transparent 23px),
    radial-gradient(circle at 50% 92%, var(--c3) 0 34px, transparent 35px),
    radial-gradient(circle at 92% 90%, var(--c1) 0 10px, transparent 11px),
    radial-gradient(circle at 6% 92%, var(--c2) 0 8px, transparent 9px),
    radial-gradient(circle at 36% 30%, var(--c1) 0 9px, transparent 10px),
    radial-gradient(circle at 70% 18%, var(--c3) 0 12px, transparent 13px),
    radial-gradient(circle at 58% 48%, var(--c2) 0 6px, transparent 7px);
  opacity: .9;
}

.plank {
  width: 100%; height: 18px; position: relative; z-index: 2; margin-top: -6px;
  background: linear-gradient(#7a4e2b, #5a3519); border-top: 3px solid #9a6a3e; box-shadow: 0 10px 14px rgba(0,0,0,.5);
}
.label {
  margin-top: 10px; background: var(--tape); color: var(--tape-ink); font-family: 'Permanent Marker', cursive;
  padding: 5px 9px; transform: rotate(-2deg); max-width: calc(100% - 12px); text-align: center;
  box-shadow: 0 2px 4px rgba(0,0,0,.4); line-height: 1.15;
}
.cell:nth-child(even) .label { transform: rotate(1.5deg); }
.label b { display: block; font-weight: 400; font-size: 14px; word-break: break-word; }
.label span { font-size: 12px; opacity: .75; }
.label em { display: block; font-style: normal; font-family: Rubik, sans-serif; font-size: 11px; opacity: .7; margin-top: 2px; }
.mine .label { background: #ffd9a0; outline: 2px dashed #b3261e; outline-offset: 2px; }
.crown { display: block; background: #ffcf3a; color: #5a3500; font-family: Bungee, sans-serif; font-size: 10px; padding: 2px 4px; margin: -5px -9px 4px; }

.shame { width: 310px; flex: none; background: var(--panel); border-left: 2px solid var(--line); padding: 16px; overflow-y: auto; }
.shame h2 { margin: 0; font-family: Bungee, sans-serif; font-weight: 400; color: var(--accent); font-size: 22px; }
.shame .sub { margin: 2px 0 12px; color: var(--muted); font-size: 13px; }
.shame ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.shame li { display: flex; gap: 10px; background: var(--panel-2); border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 10px; font-size: 14px; }
.shame li.gold { border-color: #ffcf3a; background: #3d2e12; }
.shame li.me { outline: 2px dashed var(--accent); outline-offset: 1px; }
.shame li.none { color: var(--muted); font-size: 13px; }
.shame .rk { font-family: Bungee, sans-serif; font-size: 18px; color: var(--accent); min-width: 32px; }
.shame li.gold .rk { color: #ffcf3a; }
.shame small { color: var(--muted); }
.shame .meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.shame .meta strong { color: var(--danger); }
.combos { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.combos span { background: #4b3a12; color: #ffd98a; font-size: 11px; border-radius: 6px; padding: 2px 6px; }
.cooking { color: var(--muted); font-size: 13px; margin-top: 12px; }

/* ---------- toasts, fx, admin ---------- */
#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 50; }
#toasts { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: center; width: min(92vw, 460px); pointer-events: none; }
.toast { background: #fbf5e6; color: #33241a; padding: 9px 14px; border-radius: 10px; font-weight: 500; font-size: 14px; box-shadow: 0 8px 20px rgba(0,0,0,.4); animation: toastin .3s ease-out; transition: opacity .5s, transform .5s; text-align: center; }
.toast.gold { background: #ffcf3a; color: #3a2400; font-weight: 700; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes toastin { from { opacity: 0; transform: translateY(-10px); } }
.admin { position: fixed; left: 10px; bottom: 10px; z-index: 70; background: #000c; border: 1px solid #555; border-radius: 10px; padding: 8px 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; max-width: calc(100vw - 20px); }
.admin input { width: 64px; background: #222; color: #fff; border: 1px solid #555; border-radius: 4px; padding: 3px 5px; }
.admin button { background: #333; border: 1px solid #666; border-radius: 6px; padding: 4px 8px; font-size: 12px; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  header.top { padding: 8px 12px; gap: 8px; }
  .logo { font-size: 17px; }
  .logo small { display: none; }
  nav.tabs button { padding: 6px 10px; font-size: 13px; }
  .card { top: 8px; right: 8px; left: auto; width: 168px; padding: 10px; transform: none; }
  .card .note, .card .tally { display: none; }
  .card .actions { flex-direction: column; gap: 6px; }
  .btn { padding: 7px 8px; font-size: 13px; }
  .hint { top: auto; bottom: 10px; font-size: 12px; }
  .arrow { display: none; }
  .tile { flex-basis: 84px; height: 96px; }
  .tile .art { width: 60px; height: 50px; }
  #shelf { flex-direction: column; overflow-y: auto; }
  .room { overflow: visible; flex: none; }
  .shame { width: auto; border-left: 0; border-top: 2px solid var(--line); overflow: visible; }
  .shelf-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
.boomed .jar-wrap canvas { filter: none; transform: none; }

.recipe-row { display: flex; gap: 8px; align-items: stretch; margin: 4px 0 10px; }
.recipe-row input { margin-top: 0; flex: 1; min-width: 0; }
.recipe-row .suggest { flex: none; padding: 0 12px; font-size: 14px; white-space: nowrap; }

.shake-btn {
  position: absolute; left: 14px; bottom: 14px; z-index: 2;
  background: rgba(20,12,8,.82); color: var(--ink); border: 2px solid var(--accent);
  padding: 7px 14px; border-radius: 999px; font: 500 13px Rubik, sans-serif; cursor: pointer;
  transition: opacity .5s;
}
.shake-btn.on { border-color: var(--goo); cursor: default; }
.shake-btn.gone { opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
  .shake-btn { top: 8px; bottom: auto; left: 8px; max-width: calc(100% - 196px); padding: 6px 10px; font-size: 12px; white-space: normal; text-align: left; }
}

/* awards */
.awards { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.awards li { display: flex; gap: 10px; align-items: flex-start; background: var(--panel-2); border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.awards li.me { outline: 2px dashed var(--accent); outline-offset: 1px; }
.awards li.open { opacity: .55; border-style: dashed; }
.awards .ic { font-size: 22px; line-height: 1; width: 26px; text-align: center; flex: none; }
.awards b { font-family: Bungee, sans-serif; font-weight: 400; font-size: 13px; color: #ffcf3a; }
.awards li.open b { color: var(--muted); }
.awards .who { margin-top: 1px; }
.awards .meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.shame h2 + .sub + .awards + h2 { margin-top: 4px; }
.badges { font-style: normal; }
.badges i { font-style: normal; cursor: help; }
.label .badges { display: block; font-size: 14px; line-height: 1; min-height: 0; margin-bottom: 2px; }
.label .badges:empty { display: none; }
.shame li .badges { font-size: 13px; white-space: nowrap; }
