/* Recall — design tokens and layout.
   Every colour is a token in the blocks below; no colour literal appears in JS
   or anywhere under the token blocks (a test checks, as in Cardigan).
   Light and dark follow the phone. */

:root {
  --bg: #fbf7f2; --surface: #ffffff; --surface-2: #f2ebe3; --line: #e3d8cc;
  --text: #2b1d21; --muted: #6f6166; --accent: #5c1a2e; --accent-text: #ffffff; --focus: #c4862a;
  --good: #2f7a4a; --good-bg: #e3f3e8; --bad: #b23a2e; --bad-bg: #fbe6e3; --warn: #7a5200; --warn-bg: #fdf1d8;
  --star: #c48a12; --star-off: #d9cfc4; --low: #b23a2e;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px; --tap: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171214; --surface: #221a1d; --surface-2: #2d2327; --line: #3d3135;
    --text: #f3ecee; --muted: #b3a6ab; --accent: #e7a3b6; --accent-text: #22131a; --focus: #f2c14e;
    --good: #7fd19b; --good-bg: #1d3325; --bad: #ff9d90; --bad-bg: #3d1f1b; --warn: #f2c14e; --warn-bg: #3a2e12;
    --star: #f2c14e; --star-off: #4a3d42; --low: #ff9d90;
  }
}

/* ---------------------------------------------------------------- base ---- */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 17px; line-height: 1.45; -webkit-text-size-adjust: 100%;
  min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2 { line-height: 1.2; }
.wrap { max-width: 720px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.help { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }

/* -------------------------------------------------------------- header ---- */

header.top {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  display: flex; align-items: center; gap: 8px;
}
header.top h1 { font-size: 22px; margin: 0 0 0 4px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  min-width: var(--tap); min-height: var(--tap); border: 0; border-radius: 999px;
  background: transparent; font-size: 26px; line-height: 1; display: inline-grid; place-items: center;
}
.icon-btn.small { min-width: 36px; min-height: 36px; font-size: 20px; }
.icon-btn:active { background: var(--surface-2); }

/* ------------------------------------------------------------- buttons ---- */

.btn {
  min-height: var(--tap); padding: 10px 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; width: 100%; margin-top: 24px; }
.btn.small { min-height: 40px; padding: 6px 14px; font-size: 15px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.add { width: 100%; margin: 20px 0 8px; }
.btn.add.big { min-height: 56px; font-size: 18px; max-width: 360px; }
.link-btn { border: 0; background: none; padding: 4px; color: var(--accent); font-weight: 600; text-decoration: underline; }

.add-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 20px 0 8px; }
.add-row .btn { flex: 1 1 160px; }

/* -------------------------------------------------------------- notice ---- */

.notice {
  display: flex; align-items: center; gap: 8px; margin: 8px 16px 0; padding: 6px 6px 6px 14px;
  border-radius: var(--radius); background: var(--surface-2); max-width: 688px;
}
.notice span { flex: 1; }
.notice.good { background: var(--good-bg); color: var(--good); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
@media (min-width: 720px) { .notice { margin: 8px auto 0; } }

/* ---------------------------------------------------------------- list ---- */

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.search {
  flex: 1 1 200px; min-height: var(--tap); padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); width: 100%;
}
.segs { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg { border: 0; background: transparent; min-height: 40px; padding: 6px 14px; font-size: 15px; }
.seg.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.wrap-segs { flex-wrap: wrap; border-radius: 20px; }

.filters {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: end;
  background: var(--surface-2); border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
}
.filter span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.filter select { width: 100%; min-height: 44px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }

.count { color: var(--muted); font-size: 14px; margin: 4px 0 6px; }
.items { list-style: none; margin: 0; padding: 0; }
.items li { border-bottom: 1px solid var(--line); }
.items li:last-child { border-bottom: 0; }
.nothing { padding: 16px 0; }
.item-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 72px;
  padding: 8px 2px; border: 0; background: transparent; text-align: left;
}
.item-row:active { background: var(--surface-2); }
.item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.thumb {
  width: 56px; height: 56px; flex: none; border-radius: 10px; object-fit: cover;
  background: var(--surface-2); display: inline-grid; place-items: center; font-size: 26px;
}
.thumb.big { width: 120px; height: 120px; }

.empty-state { text-align: center; padding-top: 48px; }
.empty-state p { color: var(--muted); max-width: 420px; margin: 8px auto; }
.hello-icon { font-size: 56px; }

/* --------------------------------------------------------------- stars ---- */

.stars { flex: none; letter-spacing: 1px; font-size: 16px; white-space: nowrap; }
.stars .on { color: var(--star); }
.stars .off { color: var(--star-off); }
.stars.s1 .on, .stars.s2 .on { color: var(--low); }
.stars.none { color: var(--muted); font-size: 13px; }
.stars.big { font-size: 30px; }
.stars.big.none { font-size: 16px; }

.star-pick { display: flex; gap: 4px; }
.star-pick button {
  min-width: var(--tap); min-height: var(--tap); border: 0; background: transparent; font-size: 34px; line-height: 1;
  color: var(--star-off); border-radius: 10px; padding: 0;
}
.star-pick button.on { color: var(--star); }
.star-pick button:active { background: var(--surface-2); }

/* ------------------------------------------------------------ one wine ---- */

.wine .photo { display: block; width: 100%; max-height: 60vh; object-fit: contain; border-radius: var(--radius); background: var(--surface-2); }
.verdict-row { margin: 14px 0 4px; }
.verdict { font-size: 18px; margin: 8px 0 12px; white-space: pre-wrap; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 12px 0; }
.facts dt { font-weight: 600; }
.facts dd { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.others h2 { font-size: 18px; margin: 20px 0 4px; }

/* -------------------------------------------------------------- form ---- */

.form label, .form .label { display: block; font-weight: 600; margin: 16px 0 6px; }
.form input, .form textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
}
.form textarea { resize: vertical; }
.field-error { color: var(--bad); font-size: 15px; margin: 4px 0 0; }
.field-error:empty { display: none; }
.warn { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 8px 12px; margin: 8px 0 0; }
.photo-block { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.photo-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.form-actions { display: flex; gap: 10px; margin-top: 28px; }
.form-actions .btn { flex: 1; }

/* ----------------------------------------------------------- settings ---- */

.settings section { border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.settings section:last-child { border-bottom: 0; }
.settings h2 { font-size: 19px; margin: 18px 0 6px; }
@media (max-width: 420px) { .facts { grid-template-columns: 1fr; gap: 2px; } .facts dd { margin-bottom: 8px; } }
