/* Bacchus — mobile-first, one-hand friendly. */
:root {
  --bg: #f7f2ea;
  --surface: #fffdf9;
  --surface-2: #f1e9de;
  --text: #2a1d1a;
  --muted: #7b6a62;
  --line: #e4d8ca;
  --wine: #6b1d2f;
  --wine-2: #8c2a40;
  --wine-soft: #f3e1e3;
  --gold: #b8892f;
  --ok: #2f7a4f;
  --ok-soft: #e1f1e6;
  --red: #c0262d;
  --red-soft: #fbe3e2;
  --warn: #a8620a;
  --warn-soft: #fbefd9;
  --radius: 14px;
  --tap: 48px;
  --shadow: 0 1px 2px rgb(60 30 20 / 6%), 0 4px 14px rgb(60 30 20 / 6%);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1414;
    --surface: #241c1c;
    --surface-2: #2e2424;
    --text: #f2e9e4;
    --muted: #b3a29a;
    --line: #3d3131;
    --wine: #d0607a;
    --wine-2: #e07a92;
    --wine-soft: #3d2229;
    --ok: #6cc28f;
    --ok-soft: #1f3327;
    --red: #ff6b6b;
    --red-soft: #3d1f1f;
    --warn: #f0b354;
    --warn-soft: #3a2c16;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--wine); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[hidden] { display: none !important; }

.narrow { max-width: 680px; margin: 0 auto; padding: 16px; }
.page-center { min-height: 100vh; display: grid; place-items: center; }
.page-center .narrow { width: 100%; }

/* ---------------------------------------------------------------- brand */
.brand { text-align: center; margin: 8px 0 24px; }
.brand h1 { font-family: Georgia, "Times New Roman", serif; font-size: 2rem; letter-spacing: 0.02em; margin-top: 10px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 50%;
  background: var(--wine); color: #fff; font: 700 1.7rem/1 Georgia, serif;
}
.brand-mark.sm { width: 28px; height: 28px; font-size: 0.95rem; }
.brand-mini { display: flex; align-items: center; gap: 8px; font-family: Georgia, serif; font-weight: 700; }

/* ---------------------------------------------------------------- cards & forms */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 1.15rem; margin-bottom: 14px; }
.card-title { font-size: 1.05rem; margin-bottom: 4px; }
.field { display: block; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.label { display: block; font-weight: 600; font-size: 0.92rem; margin-bottom: 6px; }
.hint { display: block; color: var(--muted); font-size: 0.85rem; margin: -2px 0 8px; }
input, textarea {
  width: 100%; min-height: var(--tap); padding: 11px 13px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 10px;
  font-size: 16px; /* no iOS zoom */
}
textarea { resize: vertical; line-height: 1.4; overflow: hidden; }
input:focus, textarea:focus { outline: none; border-color: var(--wine); box-shadow: 0 0 0 3px var(--wine-soft); }
input[type="date"] { appearance: none; -webkit-appearance: none; }
.grid-2 { display: grid; gap: 0 14px; }
@media (min-width: 560px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.row-form { display: flex; gap: 10px; }
.row-form input { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); font-weight: 600; text-decoration: none; color: var(--text); cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--wine); border-color: var(--wine); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { min-height: 56px; font-size: 1.08rem; }
.btn.block { width: 100%; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 0.9rem; }
.btn + .btn.block { margin-top: 10px; }
.link { background: none; border: 0; padding: 6px 0; color: var(--wine); text-align: left; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------------------------------------------------------------- top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.topbar-inner { max-width: 680px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 16px; min-height: 56px; }
.chip {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; font-size: 0.9rem; cursor: pointer;
}
.whoami { display: flex; align-items: center; gap: 10px; min-width: 0; }
.whoami-name { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; text-decoration: none; color: var(--text); font-size: 1.4rem; }
.icon-btn:active { background: var(--surface-2); }

/* ---------------------------------------------------------------- reports list */
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.report-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.report-card {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.report-main { text-decoration: none; color: inherit; min-width: 0; }
.report-title { font-weight: 700; font-size: 1.08rem; overflow-wrap: anywhere; }
.report-meta { color: var(--muted); font-size: 0.88rem; margin-top: 2px; }
.report-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.score-pill { font-size: 0.95rem; color: var(--muted); white-space: nowrap; }
.score-pill b { color: var(--text); font-size: 1.25rem; }
.badge { font-size: 0.75rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.report-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: flex-start; }
.confirm { position: relative; }
.confirm summary { list-style: none; }
.confirm summary::-webkit-details-marker { display: none; }
.confirm-box { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; padding: 10px; border-radius: 10px; background: var(--red-soft); font-size: 0.9rem; }

/* ---------------------------------------------------------------- wizard chrome */
.wizard { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.wiz-title { flex: 1; min-width: 0; font-weight: 700; }
.save-state { font-size: 0.8rem; font-weight: 600; color: var(--ok); white-space: nowrap; }
.save-state[data-state="dirty"], .save-state[data-state="saving"] { color: var(--muted); }
.save-state[data-state="offline"], .save-state[data-state="stale"] { color: var(--warn); }
.steps {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px 16px 10px; max-width: 680px; margin: 0 auto;
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.steps::-webkit-scrollbar { display: none; }
.step-tab {
  flex: 0 0 auto; display: flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 12px;
  border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface);
  font-size: 0.88rem; font-weight: 600; cursor: pointer; scroll-snap-align: center; color: var(--muted);
}
.step-tab[aria-current="step"] { background: var(--wine); border-color: var(--wine); color: #fff; }
.step-progress { font-size: 0.75rem; opacity: 0.85; font-variant-numeric: tabular-nums; }
.step-tab.complete:not([aria-current="step"]) { border-color: var(--ok); color: var(--ok); }

.wiz-main { max-width: 680px; margin: 0 auto; padding: 14px 16px; }
.step-title { font-size: 1.2rem; margin: 6px 0 14px; }
.step-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.subtotal { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.subtotal b { color: var(--wine); font-size: 1.3rem; }

.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.bottombar #next { justify-self: end; padding: 0 14px; }
.bottombar #prev { padding: 0 14px; }
.bottombar #prev { justify-self: start; }
.live-total { text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; }
.live-total b { font-size: 1.35rem; color: var(--wine); }

/* ---------------------------------------------------------------- segmented, stepper, money */
.seg { display: flex; gap: 6px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.seg button {
  flex: 1; min-height: 44px; border: 0; border-radius: 9px; background: transparent;
  font-weight: 600; cursor: pointer; color: var(--muted);
}
.seg button[aria-checked="true"] { background: var(--wine); color: #fff; box-shadow: var(--shadow); }
.stepper { display: flex; align-items: stretch; gap: 6px; }
.stepper button { width: var(--tap); border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface-2); font-size: 1.4rem; cursor: pointer; }
.stepper input { text-align: center; font-weight: 700; -moz-appearance: textfield; appearance: textfield; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.money { display: flex; gap: 10px; }
.money input { flex: 1; font-weight: 600; font-variant-numeric: tabular-nums; }
.money .unit { display: inline-grid; place-items: center; padding: 0 16px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-weight: 700; }

/* ---------------------------------------------------------------- criterion card */
.crit { scroll-margin-top: 130px; transition: border-color 0.2s; }
.crit.done { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.crit-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.crit-head h3 { flex: 1; font-size: 1.02rem; }
.crit-code {
  flex: 0 0 auto; font-weight: 700; font-size: 0.8rem; padding: 3px 8px; border-radius: 6px;
  background: var(--wine-soft); color: var(--wine); font-variant-numeric: tabular-nums;
}
.crit-check { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 0.8rem; opacity: 0; transform: scale(0.5); transition: 0.2s; }
.crit.done .crit-check { opacity: 1; transform: none; }

.bands { display: grid; gap: 8px; margin-bottom: 12px; }
@media (min-width: 760px) { .bands { grid-template-columns: repeat(4, 1fr); } }
.band {
  display: block; width: 100%; text-align: left; padding: 9px 11px; border-radius: 10px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--surface-2); font-size: 0.88rem; line-height: 1.4;
}
.band-label { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.band-text { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); }
.band[aria-expanded="true"] .band-text { display: block; -webkit-line-clamp: unset; color: var(--text); }
.band.red { border-left: 4px solid var(--red); }
.band.red .band-text { color: color-mix(in srgb, var(--red) 75%, var(--muted)); }
.red-tag { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--red); }
.band.match { border-color: var(--wine); background: var(--wine-soft); }

.scores { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.crit[data-max="4"] .scores { grid-template-columns: repeat(5, 1fr); }
.score {
  min-height: 52px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface);
  font-size: 1.2rem; font-weight: 700; cursor: pointer; font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent; transition: background 0.12s, transform 0.08s;
}
.score:active { transform: scale(0.94); }
.score.hint { border-color: var(--wine); background: var(--wine-soft); }
.score[aria-checked="true"] { background: var(--wine); border-color: var(--wine); color: #fff; }
.red-warn { margin: 10px 0 0; padding: 9px 12px; border-radius: 10px; background: var(--red-soft); color: var(--red); font-size: 0.88rem; font-weight: 600; }
.remark { margin-top: 12px; }

.rule { font-size: 0.88rem; color: var(--muted); margin: 0 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip.warn { border-color: var(--warn); color: var(--warn); }
.chip.danger { border-color: var(--red); color: var(--red); }

/* ---------------------------------------------------------------- review */
.total-card { text-align: center; }
.big-total { font-variant-numeric: tabular-nums; margin: 4px 0 12px; }
.big-total b { font: 700 3.2rem/1 Georgia, serif; color: var(--wine); }
.big-total span { font-size: 1.3rem; color: var(--muted); margin-left: 4px; }
.sub-table { width: 100%; border-collapse: collapse; text-align: left; }
.sub-table td { padding: 8px 2px; border-top: 1px solid var(--line); }
.sub-table .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.sub-table .num b { color: var(--text); }
.missing { margin: 8px 0 0; padding-left: 20px; color: var(--red); }
.missing li { padding: 2px 0; }
.missing .link { display: inline; padding: 0; line-height: 1.5; }
.ok-text { color: var(--ok); font-weight: 600; margin: 8px 0 0; }
.error-text { color: var(--red); text-align: center; }
.generate-card .muted { margin: 10px 0 0; }

/* ---------------------------------------------------------------- AI assist */
.url-row { display: flex; gap: 8px; }
.url-row input { flex: 1; min-width: 0; }
.ai-btn { border-color: color-mix(in srgb, var(--gold) 55%, var(--line)); }
.ai-btn:disabled, .ai-btn.disabled { opacity: 0.5; pointer-events: none; }
.receipt-box { margin: 10px 0 12px; }
.receipt-btn { cursor: pointer; }
.receipt-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.ai-status { margin: 8px 0 0; padding: 9px 12px; border-radius: 10px; font-size: 0.88rem; background: var(--surface-2); }
.ai-status[data-kind="busy"] { color: var(--muted); animation: ai-pulse 1.6s ease-in-out infinite; }
.ai-status[data-kind="ok"] { background: var(--ok-soft); color: var(--ok); }
.ai-status[data-kind="error"] { background: var(--red-soft); color: var(--red); }
.ai-status .link { padding: 0; font-weight: 600; }
@keyframes ai-pulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .ai-status[data-kind="busy"] { animation: none; } }
.ai-filled { border-color: var(--gold) !important; box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 22%, transparent); }
.ai-suggest { margin-top: 8px; padding: 10px 12px; border-radius: 10px; border: 1.5px dashed var(--gold); background: color-mix(in srgb, var(--gold) 8%, var(--surface)); }
.ai-suggest-head { font-size: 0.8rem; font-weight: 700; color: var(--gold); margin-bottom: 4px; }
.ai-suggest-text { white-space: pre-line; font-size: 0.92rem; }
.ai-suggest-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ---------------------------------------------------------------- admin */
.section-title { font-size: 1.15rem; margin: 22px 0 12px; }
.flash { margin: 0 0 14px; padding: 10px 13px; border-radius: 10px; font-weight: 600; font-size: 0.92rem; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--red-soft); color: var(--red); }
.add-juror { display: grid; gap: 0 12px; align-items: end; }
.add-juror .btn { margin-bottom: 14px; }
@media (min-width: 560px) { .add-juror { grid-template-columns: 1fr 1.4fr auto; } }
.juror-rows { list-style: none; padding: 0; margin: 0; display: grid; }
.juror-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.juror-row:first-child { border-top: 0; padding-top: 0; }
.juror-row.removed .juror-info { opacity: 0.6; }
.juror-info { min-width: 0; overflow-wrap: anywhere; }
.juror-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.juror-side .confirm-box { max-width: 260px; }
.topbar.with-tabs .topbar-inner { min-height: 52px; padding-bottom: 0; }
.admin-tabs { max-width: 680px; margin: 0 auto; display: flex; gap: 4px; padding: 0 16px; }
.admin-tab {
  flex: 1 1 0; display: flex; align-items: center; justify-content: center; min-height: 46px; padding: 0 6px;
  border-bottom: 3px solid transparent; color: var(--muted); font-weight: 700; text-decoration: none; text-align: center;
}
.admin-tab[aria-current="page"] { color: var(--wine); border-bottom-color: var(--wine); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 0; }
.stat { padding: 12px 14px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat b { display: block; font-size: 1.4rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 0.82rem; }
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 7px; }
.status-line .report-meta { margin: 0; }
.rename { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.rename input { width: auto; flex: 1 1 170px; min-width: 0; min-height: 40px; padding: 7px 11px; }
.rename .err { flex-basis: 100%; color: var(--red); font-size: 0.85rem; font-weight: 600; }
.zip-card { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.zip-card h2 { margin-bottom: 2px; }
.zip-card .hint { margin: 0; }
.zip-card details { grid-column: 1 / -1; }
.tree {
  font: 0.84rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2);
  border-radius: 10px; padding: 10px 12px; margin: 6px 0 0; overflow-x: auto; white-space: pre;
}
.why { color: var(--muted); font-size: 0.82rem; align-self: center; }
@media (max-width: 440px) { .zip-card { grid-template-columns: 1fr; } }
.btn:focus-visible, .chip:focus-visible, .link:focus-visible, .admin-tab:focus-visible, summary:focus-visible {
  outline: 2px solid var(--wine); outline-offset: 2px;
}
