:root {
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --hand: 'Bradley Hand', 'Segoe Print', 'Marker Felt', 'Comic Sans MS', cursive;
  --thick: 6px;
}

body.ta {
  --page: #eaf4fb; --panel: #ffffff; --ptx: #12324a; --pmuted: #4c6d86; --pbd: #c4dcee;
  --door: #bfddf2; --bd: #7fa9cb; --inn: #f6fbfe; --shelf: #cfe6f7; --edge: #9fc6e2; --handle: #6fa0c6; --frame: #cfe6f7;
  --tx: #12324a; --chip: #ffffff; --chipbd: #7fa9cb; --warn: #ffe9a3; --warnbd: #e3c24b; --warntx: #3b2f00;
  --selbd: #2f6f9f; --lbl: #3f6785; --cartbg: #ffe9a3; --cartbd: #e3c24b; --carttx: #4a3b00;
  --n1: #ffe9a3; --n2: #d6ebfa; --n3: #a9d2ee; --m1: #9ccbea; --m2: #ffe9a3; --m3: #9ccbea; --sw: #cfe6f7;
}
body.tb {
  --page: #fff8dc; --panel: #ffffff; --ptx: #3b2f00; --pmuted: #7a6410; --pbd: #ecd98c;
  --door: #ffe9a3; --bd: #d2ab2e; --inn: #fffbea; --shelf: #fff0b8; --edge: #ebcb5a; --handle: #c9a22c; --frame: #fff0b8;
  --tx: #3b2f00; --chip: #ffffff; --chipbd: #d2ab2e; --warn: #ffce6b; --warnbd: #e9ae2b; --warntx: #3b2600;
  --selbd: #946b00; --lbl: #7a5f0d; --cartbg: #cfe6f7; --cartbd: #7fa9cb; --carttx: #12324a;
  --n1: #cfe6f7; --n2: #fff1bd; --n3: #ffdf85; --m1: #ffd966; --m2: #9ccbea; --m3: #ffd966; --sw: #fff0b8;
}
@media (prefers-color-scheme: dark) {
  body.ta { --page: #101c26; --panel: #1a2b39; --ptx: #e6f2fb; --pmuted: #9db8cc; --pbd: #2c4357; }
  body.tb { --page: #25200c; --panel: #352d12; --ptx: #fff2c4; --pmuted: #d9c27a; --pbd: #55481a; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--ptx);
  min-height: 100vh;
  overflow-x: hidden;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 40px);
  transition: background 0.3s;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.banner { background: var(--warn); color: var(--warntx); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin: 0 auto 12px; max-width: 960px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 960px; margin: 0 auto 16px; }
.ttlwrap h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.ttlwrap p { margin: 2px 0 0; font-size: 13px; color: var(--pmuted); }
.topbtns { display: flex; align-items: center; gap: 8px; flex: none; }

.pill { border-radius: 999px; border: 1.5px solid var(--bd); background: var(--frame); color: var(--tx); padding: 10px 16px; font-size: 15px; font-weight: 500; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.pill:active { transform: scale(0.98); }
.pill i { font-size: 20px; }
.swbtn { background: var(--sw); }
.cartbtn { background: var(--cartbg); border-color: var(--cartbd); color: var(--carttx); }
.framebtn { background: var(--frame); border-color: var(--bd); color: var(--tx); }
.wide { width: 100%; margin-top: 10px; }
.iconbtn { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--pbd); background: var(--panel); color: var(--ptx); display: inline-flex; align-items: center; justify-content: center; font-size: 20px; }
.textbtn { background: none; border: none; color: var(--ptx); text-decoration: underline; font-size: 14px; padding: 8px; }
:focus-visible { outline: 3px solid var(--selbd); outline-offset: 2px; }

.layout { max-width: 960px; margin: 0 auto; display: block; }
.stagecol { display: flex; flex-direction: column; align-items: center; }
.stage { position: relative; perspective: 4000px; margin-top: 14px; width: min(310px, calc(100vw - 96px)); min-height: 480px; }
.body { background: var(--frame); border: 3px solid var(--bd); border-radius: 22px; padding: 12px; min-height: 480px; display: flex; }
.inner { background: var(--inn); border-radius: 12px; padding: 2px 12px 6px; color: var(--tx); flex: 1; }

.dw { position: absolute; inset: 0; transform-style: preserve-3d; transform-origin: left center; transition: transform 0.9s ease; }
.stage.open .dw { transform: rotateY(-90deg); pointer-events: none; }
.face { position: absolute; inset: 0; border-radius: 22px; backface-visibility: hidden; -webkit-backface-visibility: hidden; border: 3px solid var(--bd); background: var(--door); }
.face.front { transform: translateZ(calc(var(--thick) / 2)); cursor: pointer; }
.face.back { transform: translateZ(calc(var(--thick) / -2)) rotateY(180deg); background: var(--inn); }
.edge { position: absolute; background: var(--edge); opacity: 0; transition: opacity 0.12s; }
.stage.open .edge { opacity: 1; }
.e-right { top: 3px; bottom: 3px; right: calc(var(--thick) / -2); width: var(--thick); transform: rotateY(90deg); }
.e-top { left: 12px; right: 12px; top: calc(var(--thick) / -2); height: var(--thick); transform: rotateX(90deg); }
.e-bottom { left: 12px; right: 12px; bottom: calc(var(--thick) / -2); height: var(--thick); transform: rotateX(90deg); }
.bin { position: absolute; left: 12%; right: 12%; height: 14%; border: 3px solid var(--bd); border-radius: 10px; background: var(--door); }

.seam { position: absolute; left: 0; right: 0; top: 20%; border-top: 3px solid var(--bd); }
.hd { position: absolute; right: 6px; width: 34px; display: flex; justify-content: flex-end; align-items: stretch; background: none; border: none; padding: 0; }
.hd i { display: block; width: 10px; border-radius: 5px; background: var(--handle); }

.note { position: absolute; padding: 18px 10px 10px; color: #3a3520; font-family: var(--hand); line-height: 1.25; border-radius: 3px; width: 38%; }
.note b { display: block; font-size: 17px; font-weight: 700; }
.note span { font-size: 13px; }
.mag { position: absolute; width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 15px; border: 2px solid #fff; color: #26435c; }
.paper { position: absolute; left: 50%; top: 44%; width: 32%; background: #fff; color: #3a3a3a; padding: 16px 8px 8px; transform: rotate(2deg); font-size: 13px; font-family: var(--hand); line-height: 1.5; border-radius: 2px; }
.polaroid { position: absolute; left: 9%; top: 72%; width: 84px; background: #fff; padding: 6px 6px 20px; transform: rotate(-5deg); border-radius: 2px; }
.polaroid .pic { height: 62px; background: var(--n3); display: flex; align-items: center; justify-content: center; font-size: 28px; color: var(--tx); }

.lbl { font-size: 12px; font-weight: 600; color: var(--lbl); margin: 0 0 6px; letter-spacing: 0.04em; text-transform: uppercase; }
.shelf { padding: 10px 0 4px; border-bottom: 4px solid var(--shelf); }
.shelf:last-child { border-bottom: none; padding-bottom: 8px; }
.empty { font-size: 14px; color: var(--lbl); margin: 0 0 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; font-size: 15px; font-weight: 600; border: 1.5px solid var(--chipbd); margin: 0 6px 6px 0; background: var(--chip); color: var(--tx); min-height: 36px; text-align: left; }
.chip .age { font-size: 12px; font-weight: 500; opacity: 0.85; }
.chip.warn { background: var(--warn); border-color: var(--warnbd); color: var(--warntx); }
.chip.old { background: #f9d2cd; border-color: #e0968c; color: #4a1510; }
.chip.sel { border: 3px solid var(--selbd); padding: 5px 10px; }
.restbadge { font-size: 10px; font-weight: 700; letter-spacing: 0.04em; background: var(--tx); color: var(--chip); padding: 1px 6px; border-radius: 4px; }
.chip.warn .restbadge { background: var(--warntx); color: var(--warn); }
.chip.old .restbadge { background: #4a1510; color: #f9d2cd; }
.fridge-empty { font-size: 14px; color: var(--lbl); padding: 12px 0 4px; line-height: 1.4; }

.actions { display: flex; gap: 8px; margin-top: 16px; width: min(340px, calc(100vw - 32px)); }
.actions .pill { white-space: nowrap; padding: 10px 12px; font-size: 14px; }
.actions .cartbtn { flex: 1; }
.listbtn { position: relative; padding: 10px 14px; }
.count { position: absolute; top: -6px; right: -4px; background: var(--ptx); color: var(--page); font-size: 12px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; }

.side { margin: 16px auto 0; width: min(420px, 100%); }
.panel { background: var(--panel); border: 1.5px solid var(--pbd); border-radius: 18px; padding: 16px; margin-bottom: 14px; }
.panel h2, .dlg h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.phead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.hint { font-size: 13px; color: var(--pmuted); margin: 4px 0 10px; line-height: 1.4; }
.err { font-size: 13px; color: #b3261e; margin: 4px 0 8px; }
@media (prefers-color-scheme: dark) { .err { color: #ffb4ab; } }
.fld { display: block; font-size: 13px; color: var(--pmuted); margin: 10px 0 0; }
.fld input, .fld select, .row-add input { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; border-radius: 12px; border: 1.5px solid var(--pbd); background: var(--page); color: var(--ptx); font-size: 16px; min-height: 46px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.restchk { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; font-size: 15px; }
.restchk input { width: 22px; height: 22px; accent-color: var(--selbd); }
.sug { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sug button { border: 1.5px solid var(--pbd); background: var(--page); color: var(--ptx); border-radius: 999px; padding: 6px 12px; font-size: 14px; min-height: 34px; }

.row-add { display: flex; gap: 8px; margin: 10px 0; }
.row-add input { margin: 0; flex: 1; }
.shoplist { list-style: none; margin: 0; padding: 0; }
.shoplist li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--pbd); }
.shoplist li:last-child { border-bottom: none; }
.shoplist .nm { flex: 1; font-size: 16px; text-align: left; background: none; border: none; padding: 6px 0; display: flex; align-items: center; gap: 10px; }
.shoplist .box { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--selbd); display: inline-flex; align-items: center; justify-content: center; font-size: 15px; flex: none; }
.shoplist li.done .nm { text-decoration: line-through; color: var(--pmuted); }
.shoplist li.done .box { background: var(--selbd); color: var(--panel); }
.shoplist .small { width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--pbd); background: var(--page); color: var(--ptx); font-size: 18px; display: inline-flex; align-items: center; justify-content: center; }
.shop-empty { font-size: 14px; color: var(--pmuted); padding: 8px 0 2px; }

.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--panel); border-top: 1.5px solid var(--pbd); border-radius: 20px 20px 0 0; padding: 12px 16px calc(env(safe-area-inset-bottom) + 14px); max-width: 520px; margin: 0 auto; }
.bar-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.bar-head strong { font-size: 17px; }
.bar-head span { font-size: 13px; color: var(--pmuted); margin-left: 8px; }
.bar-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bar-grid .pill { padding: 10px 8px; font-size: 14px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 20px); background: var(--ptx); color: var(--page); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 40; display: flex; align-items: center; gap: 8px; max-width: calc(100vw - 32px); width: max-content; }
.toast .textbtn { color: var(--page); padding: 2px 4px; }
body.has-bar { padding-bottom: calc(env(safe-area-inset-bottom) + 220px); }
body.has-bar .toast { bottom: calc(env(safe-area-inset-bottom) + 170px); }

.dlg { border: 1.5px solid var(--pbd); border-radius: 20px; background: var(--panel); color: var(--ptx); width: min(420px, calc(100vw - 32px)); padding: 20px; }
.dlg::backdrop { background: rgba(10, 20, 30, 0.45); }
.codebox { font-family: ui-monospace, Menlo, monospace; font-size: 22px; letter-spacing: 0.06em; text-align: center; background: var(--page); border: 1.5px dashed var(--bd); border-radius: 12px; padding: 12px 8px; margin: 6px 0 10px; user-select: all; }

@media (min-width: 900px) {
  body { padding-top: 28px; }
  .layout { display: grid; grid-template-columns: 420px 1fr; gap: 48px; align-items: start; }
  .stage { width: 340px; }
  .actions { width: 340px; }
  .side { margin: 0; width: auto; max-width: 420px; }
  .side .panel[hidden] { display: block !important; }
  #cart, #listbtn { }
  .listbtn { display: none; }
  #p-add .row2 .framebtn { display: none; }
  #p-add[data-mode="edit"] .row2 .framebtn { display: inline-flex; }
  .actionbar { left: auto; right: 24px; bottom: 24px; border: 1.5px solid var(--pbd); border-radius: 20px; width: 380px; }
body.has-bar .toast { bottom: 24px; left: 40%; }
}
@media (prefers-reduced-motion: reduce) {
  .dw { transition: none; }
}
