:root {
  --bg: #f7f3ea;
  --surface: #ffffff;
  --surface-2: #f1ebdf;
  --text: #1f1c17;
  --muted: #6e665a;
  --border: #e3dccd;
  --accent: #1f1c17;
  --accent-text: #ffffff;
  --gold: #c99a1e;
  --gold-soft: #f6ead0;
  --silver: #8d949c;
  --silver-soft: #eceef0;
  --empty: #d9d2c4;
  --danger: #b3261e;
  --focus: #c99a1e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 28, 23, .06), 0 4px 14px rgba(31, 28, 23, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14120f;
    --surface: #1f1c18;
    --surface-2: #2a2620;
    --text: #f3eee4;
    --muted: #a99f8f;
    --border: #36312a;
    --accent: #e6c35c;
    --accent-text: #1c1a17;
    --gold: #e6c35c;
    --gold-soft: #3a3020;
    --silver: #b9c0c7;
    --silver-soft: #2c2f33;
    --empty: #4a443b;
    --danger: #ff8a80;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14120f; --surface: #1f1c18; --surface-2: #2a2620; --text: #f3eee4; --muted: #a99f8f;
  --border: #36312a; --accent: #e6c35c; --accent-text: #1c1a17; --gold: #e6c35c; --gold-soft: #3a3020;
  --silver: #b9c0c7; --silver-soft: #2c2f33; --empty: #4a443b; --danger: #ff8a80; --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 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: #1c1a17; color: #f3eee4;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.brand-icon { width: 22px; height: 22px; background: url(/icons/icon.svg) center/cover; border-radius: 6px; }
.topnav { display: flex; gap: 4px; }
.topnav a { text-decoration: none; padding: 6px 12px; border-radius: 999px; font-size: .95rem; color: #d9d2c4; }
.topnav a.active { background: #3a352d; color: #fff; }

.app { max-width: 640px; margin: 0 auto; padding: 16px; }
.loading { color: var(--muted); text-align: center; padding: 48px 0; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: .95rem; margin-bottom: 10px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Buttons & inputs */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: 12px;
  background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 600; padding: 12px 18px; min-height: 48px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.ms { background: #fff; color: #1f1c17; border-color: #c9c2b3; }
.btn.ms svg { width: 20px; height: 20px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field + .field { margin-top: 14px; }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=search], textarea, select {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; min-height: 48px;
}
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 22px; height: 22px; accent-color: var(--gold); }
.hint { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.error { color: var(--danger); font-size: .9rem; margin-top: 10px; }

/* Forks */
.forks { display: inline-flex; gap: 2px; vertical-align: middle; }
.forks svg { width: 18px; height: 26px; }
.forks.lg svg { width: 26px; height: 38px; }
.fork.golden { color: var(--gold); }
.fork.silver { color: var(--silver); }
.fork.empty { color: var(--empty); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px;
}
.badge.golden { background: var(--gold-soft); color: var(--gold); }
.badge.silver { background: var(--silver-soft); color: var(--silver); }
.badge.unrated { background: var(--surface-2); color: var(--muted); }
:root .badge.golden { color: #8a6610; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.golden { color: var(--gold); } }
:root[data-theme="dark"] .badge.golden { color: var(--gold); }

/* Restaurant list */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input { flex: 1; min-width: 0; }
.toolbar select { width: auto; flex: 0 0 auto; }
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { margin-top: 10px; }
.r-card { display: block; text-decoration: none; }
.r-card .name { font-weight: 700; font-size: 1.05rem; }
.r-card .meta { color: var(--muted); font-size: .875rem; margin-top: 2px; }
.r-card .todo { font-size: .8rem; font-weight: 600; color: var(--gold); margin-top: 2px; }
:root:not([data-theme="dark"]) .r-card .todo { color: #8a6610; }
.list { padding-bottom: 8px; }
.r-card .score-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.score { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.15rem; }
.rank { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; min-width: 1.6em; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }
.fab { position: sticky; bottom: calc(env(safe-area-inset-bottom) + 16px); margin-top: 16px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }

/* Restaurant detail */
.hero { text-align: center; padding: 22px 16px; }
.hero .big-score { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin-top: 6px; }
.hero .label { font-weight: 600; margin-top: 4px; }
.cat-bars { display: grid; gap: 10px; }
.cat-bar .top { display: flex; justify-content: space-between; font-size: .9rem; }
.cat-bar .track { height: 8px; border-radius: 4px; background: var(--surface-2); margin-top: 4px; overflow: hidden; }
.cat-bar .fill { height: 100%; background: var(--gold); border-radius: 4px; }
.review { border-top: 1px solid var(--border); padding-top: 12px; }
.review:first-child { border-top: 0; padding-top: 0; }
.review .ratings { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 2px 12px; font-size: .85rem; color: var(--muted); margin-top: 6px; }
.notice { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; font-size: .9rem; color: var(--muted); }

/* Rating entry */
.cat { padding: 14px 0; border-top: 1px solid var(--border); }
.cat:first-of-type { border-top: 0; padding-top: 0; }
.cat .cat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cat .weight { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.cat .desc { font-size: .85rem; color: var(--muted); margin: 2px 0 10px; }
.scale { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.scale button {
  appearance: none; font: inherit; font-weight: 700; font-variant-numeric: tabular-nums;
  min-height: 44px; padding: 0; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.scale button[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: #1c1a17; }
.cat .chosen { font-size: .85rem; margin-top: 6px; min-height: 1.3em; font-weight: 600; }
.live-score { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); margin: 16px -16px -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-radius: 0 0 var(--radius) var(--radius); }

/* Admin */
.user-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--border); }
.user-row:first-child { border-top: 0; }
.user-row .who { min-width: 0; }
.user-row .who div { overflow-wrap: anywhere; }
.inactive { opacity: .5; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translate(-50%, 20px);
  background: #1c1a17; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: .95rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Login */
.login { max-width: 400px; margin: 0 auto; padding-top: calc(env(safe-area-inset-top) + 36px); }
.login .logo { width: 88px; height: 88px; border-radius: 22px; margin: 0 auto 16px; display: block; }
.login h1 { text-align: center; }
.login .tagline { text-align: center; color: var(--muted); margin: 6px 0 24px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.legend { display: grid; gap: 6px; font-size: .9rem; }
.legend div { display: flex; align-items: center; gap: 10px; }

/* Possible duplicates on the Add restaurant form */
.dupes { margin: 10px 0 14px; border: 1px solid var(--gold); background: var(--gold-soft); border-radius: 12px; padding: 12px; }
.dupes-title { margin: 0 0 8px; font-weight: 700; font-size: .9rem; }
.dupe { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-decoration: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.dupe + .dupe { margin-top: 6px; }
.dupe-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }

/* Recent reviews feed */
.feed { margin-bottom: 20px; }
.feed h2 { font-size: 1rem; }
.feed .spread a { color: var(--muted); }
.feed-item { display: block; text-decoration: none; padding: 12px 0; border-top: 1px solid var(--border); }
.feed > .spread + .feed-item { margin-top: 8px; }
.feed-item:first-child { border-top: 0; padding-top: 0; }
.feed-who { min-width: 0; }
.feed-notes { margin: 6px 0 0; font-size: .9rem; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Google Places search results */
.results { list-style: none; margin: 10px 0 0; padding: 0; }
.result {
  appearance: none; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--surface); border: 0; border-top: 1px solid var(--border); padding: 12px 2px; min-height: 56px;
}
.results li:first-child .result { border-top: 0; }
.result-text { min-width: 0; overflow-wrap: anywhere; }
.result-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.place-preview { padding-bottom: 4px; }
