:root {
  --bg: #f7f3ee;
  --surface: #ffffff;
  --text: #2a2622;
  --muted: #8a8178;
  --border: #e8e1d8;
  --accent: #c2562f;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 2px 8px rgba(60, 40, 20, .04);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1917;
    --surface: #262320;
    --text: #f1ebe4;
    --muted: #a39a90;
    --border: #3a3531;
    --accent: #e0774f;
    --accent-text: #1b1917;
    --danger: #f2827a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2 {
  font-family: Fraunces, Georgia, serif;
  font-weight: 600;
  letter-spacing: -.01em;
  margin: 0;
}

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 14px; margin: 0; min-height: 0; }
.error:empty { display: none; }

/* ---------- buttons & inputs ---------- */

.btn {
  font: inherit;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); background: transparent; border-color: transparent; padding-left: 0; }
.btn.link { border: 0; background: none; padding: 4px 0; color: var(--muted); text-decoration: underline; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; padding: 11px; }
.btn:disabled { opacity: .6; cursor: default; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { resize: vertical; }

.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.field > span { font-size: 13px; font-weight: 500; color: var(--muted); }

/* ---------- login ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-card h1 { font-size: 30px; }
.login-card p { margin: -8px 0 0; }

.who { display: flex; gap: 8px; }
.who label { flex: 1; }
.who input { position: absolute; opacity: 0; pointer-events: none; }
.who span {
  display: block;
  text-align: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
}
.who input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.who input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- layout ---------- */

#app-view {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px calc(40px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 0 14px;
}
.top h1 { font-size: 26px; }
.account { display: flex; align-items: center; gap: 10px; font-size: 14px; }

.tabs {
  display: flex;
  gap: 4px;
  background: color-mix(in srgb, var(--border) 60%, transparent);
  padding: 4px;
  border-radius: 12px;
}
.tabs button {
  flex: 1;
  font: inherit;
  font-weight: 500;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 8px 6px;
  border-radius: 9px;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.toolbar { display: flex; gap: 8px; margin: 14px 0; }
.toolbar #search { flex: 1; }
.toolbar #sort { width: auto; flex: 0 0 auto; }

@media (max-width: 520px) {
  .toolbar { flex-wrap: wrap; }
  .toolbar #search { flex-basis: 100%; }
  .toolbar #sort { flex: 1; }
}

/* ---------- cards ---------- */

.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
}
.card:hover { border-color: color-mix(in srgb, var(--muted) 50%, var(--border)); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-name { font-family: Fraunces, Georgia, serif; font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 1px; }
.card-sub a { color: inherit; }
.card-body { display: flex; gap: 14px; }
.card-main { flex: 1; min-width: 0; }
.card-photo { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; flex: none; background: var(--border); }
@media (max-width: 520px) { .card-photo { width: 64px; height: 64px; } }
.card-notes { margin: 6px 0 0; font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; }
.avg { font-family: Fraunces, Georgia, serif; font-weight: 600; white-space: nowrap; font-size: 20px; color: var(--accent); }
.avg .muted { font-size: 13px; font-family: Inter, system-ui, sans-serif; font-weight: 500; }
.num { font-weight: 600; font-variant-numeric: tabular-nums; }

.scores { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.score { display: grid; grid-template-columns: 58px 36px 1fr; gap: 10px; align-items: baseline; font-size: 14px; }
.score .who-name { color: var(--muted); font-weight: 500; font-size: 13px; }
.score .note { color: var(--text); opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score .pending { grid-column: 2 / -1; color: var(--muted); font-style: italic; }
.score .pending.me { color: var(--accent); font-style: normal; font-weight: 500; }


.wish-notes { margin: 8px 0 0; font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; }
.wish-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.wish-foot .muted { font-size: 13px; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- dialogs ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(20, 14, 8, .45); }
dialog form { padding: 22px 20px 18px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { font-size: 22px; }

.row { display: flex; gap: 12px; }
@media (max-width: 520px) { .row { flex-direction: column; } }

.rating { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin: 0; }
.rating legend { font-size: 13px; font-weight: 600; padding: 0 4px; }
.rating.mine { display: flex; flex-direction: column; gap: 10px; }
.rating.partner { background: color-mix(in srgb, var(--border) 35%, transparent); border-color: transparent; font-size: 14px; }
.rating.partner .label { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.rating.partner p { margin: 4px 0 0; white-space: pre-line; }

.score-input { display: flex; align-items: baseline; gap: 8px; }
.score-input input { width: 90px; font-size: 20px; font-weight: 600; text-align: center; }

.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.photo { position: relative; width: 76px; height: 76px; }
.photo img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; display: block; }
.photo .remove {
  position: absolute; top: -6px; right: -6px;
  width: 22px; height: 22px; border-radius: 50%;
  border: 0; background: var(--text); color: var(--bg);
  font-size: 15px; line-height: 22px; padding: 0; cursor: pointer;
}
.photo.add {
  font: inherit; font-size: 13px; font-weight: 500;
  border: 1px dashed var(--border); border-radius: 10px;
  background: none; color: var(--muted); cursor: pointer;
}
.photo.add:hover { border-color: var(--muted); color: var(--text); }

.meta { font-size: 12px; color: var(--muted); margin: 0; }
.meta:empty { display: none; }
.actions { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }

/* ---------- slideshow ---------- */

.slideshow {
  position: relative;
  aspect-ratio: 16 / 9;
  max-height: 340px;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--border);
  margin-bottom: 14px;
}
.slideshow .slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .8s ease;
}
.slideshow .slide.show { opacity: 1; }
.slide-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 28px 16px 12px;
  border: 0;
  text-align: left;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, .55));
  cursor: pointer;
}
.slide-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 34px; height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .35);
  color: #fff;
  font-size: 22px;
  line-height: 34px;
  padding: 0;
  cursor: pointer;
}
.slide-nav.prev { left: 10px; }
.slide-nav.next { right: 10px; }
@media (prefers-reduced-motion: reduce) { .slideshow .slide { transition: none; } }

/* ---------- toolbar extras ---------- */

.toolbar #cuisine { width: auto; flex: 0 0 auto; }
.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  flex: none;
}
.view-toggle button {
  font: inherit;
  font-weight: 500;
  border: 0;
  background: var(--surface);
  color: var(--muted);
  padding: 8px 12px;
  cursor: pointer;
}
.view-toggle button[aria-pressed="true"] { background: var(--text); color: var(--bg); }

@media (max-width: 520px) {
  .toolbar #cuisine, .toolbar #sort { flex: 1 1 40%; }
  .tabs button { font-size: 13.5px; padding: 8px 2px; }
}

/* ---------- maps ---------- */

.map {
  height: min(65vh, 560px);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--border);
}
#map-note { margin-top: 8px; }

.pin-anchor { background: none; border: 0; }
.pin {
  position: absolute;
  transform: translate(-50%, calc(-100% - 6px));
  background: var(--accent);
  color: var(--accent-text);
  font: 600 12px/1 Inter, system-ui, sans-serif;
  padding: 5px 7px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
.pin::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -5px;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom: 0;
  border-top-color: var(--accent);
}
.pin.wish { background: #2f6f8f; }
.pin.wish::after { border-top-color: #2f6f8f; }

.leaflet-container { font: inherit; }
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); }
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.popup { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; font-size: 14px; }
.popup .muted { font-size: 12px; }
.popup .btn { margin-top: 4px; }

.location .loc-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.loc-status { font-size: 14px; }
.loc-results { display: flex; flex-direction: column; gap: 4px; }
.loc-results:empty { display: none; }
.loc-hit {
  font: inherit;
  font-size: 13px;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 9px;
  cursor: pointer;
}
.loc-hit:hover { border-color: var(--accent); }
.loc-map { height: 200px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.hint { font-size: 12px; color: var(--muted); margin: 2px 0 0; }

/* ---------- cooks & suggestions ---------- */

.rating-note { margin: 0; font-size: 14px; color: var(--muted); }
.section-title { font: 600 14px/1.3 Inter, system-ui, sans-serif; margin: 10px 0 0; }
.section-title:first-child { margin-top: 0; }
.section-title .muted { font-weight: 400; }
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: #2f6f8f;
  background: color-mix(in srgb, #2f6f8f 12%, transparent);
  border-radius: 999px;
  padding: 3px 9px;
}
.card.suggested { border-style: dashed; box-shadow: none; }
.wish-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pin.wish.suggested { background: var(--surface); color: #2f6f8f; border: 2px solid #2f6f8f; padding: 3px 5px; }
.pin.wish.suggested::after { bottom: -7px; }
@media (prefers-color-scheme: dark) {
  .badge { color: #8cc7e3; background: color-mix(in srgb, #8cc7e3 15%, transparent); }
}
