:root {
  --bg: #faf7f2;
  --panel: #ffffff;
  --ink: #1f1b16;
  --muted: #6f675d;
  --line: #e8e1d6;
  --accent: #e2482d;
  --accent-ink: #ffffff;
  --accent-soft: #fde9e4;
  --good: #1f8a4c;
  --good-soft: #e3f4ea;
  --warn: #b25b00;
  --warn-soft: #fdf0de;
  --shadow: 0 1px 2px rgba(31, 27, 22, .06), 0 4px 16px rgba(31, 27, 22, .06);
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #16130f; --panel: #211d18; --ink: #f3ede4; --muted: #a79d90; --line: #3a332b;
  --accent: #ff6a4d; --accent-soft: #3d221b; --good: #4cc983; --good-soft: #193425;
  --warn: #ffb15c; --warn-soft: #3a2a17; --shadow: none; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16130f; --panel: #211d18; --ink: #f3ede4; --muted: #a79d90; --line: #3a332b;
    --accent: #ff6a4d; --accent-soft: #3d221b; --good: #4cc983; --good-soft: #193425;
    --warn: #ffb15c; --warn-soft: #3a2a17; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.35rem; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .75rem; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .75rem; }
.logo { font-size: 2rem; }
.sub { margin: 0; color: var(--muted); font-size: .85rem; }
.budget-chip {
  display: flex; flex-direction: column; align-items: flex-end;
  background: var(--accent-soft); color: var(--accent); padding: .4rem .9rem; border-radius: 999px;
}
.budget-chip .label { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; }
.budget-chip strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.budget-chip .note { font-size: .7rem; opacity: .85; }
.budget-chip { border-radius: 14px; cursor: help; }

.layout {
  display: grid; grid-template-columns: 280px minmax(0, 1fr) 320px; gap: 1.25rem;
  padding: 1.25rem 1.5rem; max-width: 1400px; margin: 0 auto; align-items: start;
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; }
.settings, .order { position: sticky; top: 88px; max-height: calc(100vh - 104px); overflow: auto; }
.settings section + section { margin-top: 1.4rem; }

.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .9rem; font-size: .9rem; }
.field > span:first-child { display: flex; justify-content: space-between; color: var(--muted); }
.field output { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.money { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 0 .6rem; background: var(--bg); }
.money span { color: var(--muted); }
.money input { border: 0; background: transparent; padding: .5rem .35rem; width: 100%; outline: none; font-variant-numeric: tabular-nums; }
.money:focus-within { border-color: var(--accent); }
select, input[type="search"] { border: 1px solid var(--line); border-radius: 10px; padding: .5rem .6rem; background: var(--bg); }
input[type="range"] { accent-color: var(--accent); width: 100%; }
.check { display: flex; gap: .5rem; align-items: center; font-size: .9rem; }
.check input { accent-color: var(--accent); width: 1rem; height: 1rem; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button { border: 0; background: transparent; padding: .45rem .2rem; font-size: .8rem; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  padding: .55rem 1rem; cursor: pointer; font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.big { font-size: 1.15rem; padding: .8rem 2.4rem; border-radius: 999px; }
.btn:disabled { opacity: .55; cursor: progress; }

.top { margin-bottom: 1.25rem; }
.top-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.top-title { font-size: 1.2rem; text-transform: none; letter-spacing: -.01em; color: var(--ink); margin: 0; }
.top-sub { margin: .2rem 0 0; font-size: .88rem; }
.top-head .segmented { min-width: 300px; }
.top-over { margin: .9rem 0 0; max-width: 360px; }
.field.top-over > span:first-child { justify-content: flex-start; gap: .3rem; }
.top-list { list-style: none; margin: .9rem 0 0; padding: 0; counter-reset: rank; }
.top-list li {
  counter-increment: rank; display: grid; grid-template-columns: 2rem minmax(0, 1fr) auto auto auto;
  gap: .7rem; align-items: center; padding: .6rem 0; border-top: 1px dashed var(--line);
}
.top-list li::before {
  content: counter(rank); font-weight: 800; font-size: 1.05rem; color: var(--muted);
  text-align: center; font-variant-numeric: tabular-nums;
}
.top-list li:nth-child(1)::before { color: #c9a227; }
.top-list li:nth-child(2)::before { color: #9aa4ad; }
.top-list li:nth-child(3)::before { color: #b8733f; }
.top-list .dish { font-weight: 600; }
.top-list .where { color: var(--muted); font-size: .82rem; }
.top-list .cost { text-align: right; }
.top-list .cost .price { display: block; font-weight: 650; font-variant-numeric: tabular-nums; }
.top-note { margin: .6rem 0 0; font-size: .85rem; }
.top-empty { padding: 1rem 0 .2rem; color: var(--muted); }
.spinner { text-align: center; padding: 1.6rem 1.2rem; }
.reel { min-height: 118px; display: flex; flex-direction: column; justify-content: center; gap: .3rem; }
.reel-restaurant { font-size: 1.6rem; font-weight: 750; letter-spacing: -.02em; }
.reel-item { font-size: 1.05rem; color: var(--muted); }
.reel-meta { min-height: 1.6rem; }
.reel.spinning .reel-restaurant, .reel.spinning .reel-item { filter: blur(.6px); opacity: .75; }
.reel.landed { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(.96); } 60% { transform: scale(1.03); } 100% { transform: scale(1); } }
.spin-actions { display: flex; justify-content: center; gap: .6rem; margin-top: 1rem; flex-wrap: wrap; }

.list-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.5rem 0 .75rem; }
.list-head h2 { margin: 0; }
.list-head input { width: min(280px, 50%); }

.options { display: flex; flex-direction: column; gap: .9rem; }
.place { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.place-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .25rem 1rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.place-head h3 { margin: 0; font-size: 1.05rem; }
.place-head .meta { color: var(--muted); font-size: .82rem; }
.place-head a { color: var(--accent); text-decoration: none; }
.place-head .stale { color: var(--warn); }
.items { list-style: none; margin: 0; padding: 0; }
.items li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: .8rem; align-items: center; padding: .6rem 1rem; }
.items li + li { border-top: 1px dashed var(--line); }
.items .name { font-weight: 550; }
.items .desc { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.items .price { font-variant-numeric: tabular-nums; font-weight: 600; }
.add { border: 1px solid var(--line); background: transparent; border-radius: 999px; width: 2rem; height: 2rem; cursor: pointer; font-size: 1.1rem; line-height: 1; }
.add:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.vote {
  border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: .2rem .6rem;
  font-size: .8rem; font-weight: 650; cursor: pointer; font-variant-numeric: tabular-nums; color: var(--muted); min-width: 3.4rem;
}
.vote:hover { border-color: var(--accent); color: var(--accent); }
.vote.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.vote.busy { opacity: .6; cursor: progress; }
.place-votes { color: var(--accent); font-size: .85rem; font-weight: 650; margin-left: .35rem; }
.pill { display: inline-block; font-size: .75rem; font-weight: 650; padding: .15rem .55rem; border-radius: 999px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius); }

.lines { list-style: none; margin: 0 0 .8rem; padding: 0; }
.lines li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .5rem; align-items: center; padding: .4rem 0; border-bottom: 1px dashed var(--line); }
.qty { display: inline-flex; align-items: center; gap: .3rem; }
.qty button { width: 1.6rem; height: 1.6rem; border-radius: 999px; border: 1px solid var(--line); background: transparent; cursor: pointer; }
.breakdown { display: grid; grid-template-columns: 1fr auto; gap: .25rem .5rem; margin: 0 0 .8rem; font-size: .9rem; font-variant-numeric: tabular-nums; }
.breakdown dt { color: var(--muted); }
.breakdown dd { margin: 0; text-align: right; }
.breakdown .total { font-weight: 700; color: var(--ink); border-top: 1px solid var(--line); padding-top: .3rem; }
.verdict { border-radius: 10px; padding: .7rem .8rem; font-weight: 650; margin-bottom: .8rem; }
.verdict.good { background: var(--good-soft); color: var(--good); }
.verdict.warn { background: var(--warn-soft); color: var(--warn); }
.order-actions { display: flex; gap: .5rem; justify-content: flex-end; }
.history-title { margin-top: 1.6rem; }
.history { list-style: none; margin: 0; padding: 0; font-size: .88rem; }
.history li { padding: .45rem 0; border-bottom: 1px dashed var(--line); }
.history .when { color: var(--muted); font-size: .78rem; }

.foot { max-width: 1400px; margin: 0 auto; padding: 0 1.5rem 2rem; color: var(--muted); font-size: .8rem; }
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; box-shadow: var(--shadow); z-index: 20;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); }
  .order { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 760px) {
  .topbar { padding: .7rem 1rem; }
  .logo { font-size: 1.6rem; }
  .sub { font-size: .75rem; }
  .budget-chip { padding: .3rem .7rem; flex-shrink: 0; }
  .budget-chip .label { font-size: .6rem; white-space: nowrap; }
  .budget-chip strong { font-size: 1.05rem; }
  .budget-chip .note { font-size: .6rem; max-width: 9rem; text-align: right; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 1rem; }
  .settings { position: static; max-height: none; }
  .items li { grid-template-columns: minmax(0, 1fr) auto; }
  .items li .vote {
  border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: .2rem .6rem;
  font-size: .8rem; font-weight: 650; cursor: pointer; font-variant-numeric: tabular-nums; color: var(--muted); min-width: 3.4rem;
}
.vote:hover { border-color: var(--accent); color: var(--accent); }
.vote.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.vote.busy { opacity: .6; cursor: progress; }
.place-votes { color: var(--accent); font-size: .85rem; font-weight: 650; margin-left: .35rem; }
.pill { grid-column: 1; justify-self: start; }
  .list-head { flex-direction: column; align-items: stretch; }
  .top-head .segmented { min-width: 0; width: 100%; }
  .top-list li { grid-template-columns: 1.5rem minmax(0, 1fr) auto auto; row-gap: .35rem; }
  .top-list li::before { grid-row: 1 / span 2; }
  .top-list li > div:first-of-type { grid-column: 2 / span 3; }
  .top-list .cost { grid-column: 2; grid-row: 2; text-align: left; }
  .top-list .cost .price { display: inline; margin-right: .4rem; }
  .top-list .vote { grid-column: 3; grid-row: 2; }
  .top-list .add { grid-column: 4; grid-row: 2; }
  .list-head input { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .reel.landed { animation: none; }
}
