:root {
  color-scheme: light dark;
  --bg: #f4ede3;
  --surface: #fffdf8;
  --sunken: #ebe1d3;
  --ink: #2b1e16;
  --muted: #716155;
  --line: #e0d3c2;
  --accent: #a4481f;
  --accent-ink: #fffaf4;
  --accent-soft: #f2dccb;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgb(60 35 15 / 6%), 0 6px 20px rgb(60 35 15 / 7%);
  --radius: 18px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16110e;
    --surface: #221a15;
    --sunken: #2c221b;
    --ink: #f3e9de;
    --muted: #ab9a8c;
    --line: #3b2e25;
    --accent: #e8935e;
    --accent-ink: #1d120b;
    --accent-soft: #40291c;
    --danger: #f28b82;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3, p, ul, dl, dd { margin: 0; }
ul { padding: 0; list-style: none; }
img { display: block; max-width: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
code { font-size: 0.9em; background: var(--sunken); padding: 1px 5px; border-radius: 6px; overflow-wrap: anywhere; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.icon { flex: none; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }

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

.app { max-width: 560px; margin: 0 auto; }

.view {
  min-height: 100dvh;
  padding: 0 16px calc(120px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -16px;
  padding: calc(10px + env(safe-area-inset-top)) 8px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.bar-title {
  flex: 1;
  min-width: 0;
  font: 600 1.6rem/1.2 var(--serif);
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-mark { display: grid; place-items: center; width: 44px; height: 44px; color: var(--accent); }
.bar-spacer { width: 44px; }

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
}
.icon-btn:active { background: var(--sunken); }

.fab {
  position: fixed;
  right: max(16px, calc(50vw - 264px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 58px;
  padding: 0 24px 0 20px;
  border: 0;
  border-radius: 29px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  font-size: 1.05rem;
  box-shadow: 0 4px 14px rgb(120 50 15 / 35%);
}
.fab:active { transform: scale(0.97); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.cards { display: flex; flex-direction: column; gap: 12px; }

.coffee-card { display: flex; align-items: center; gap: 14px; padding: 12px 14px 12px 12px; }
.coffee-card:active { background: var(--sunken); }

.thumb {
  flex: none;
  width: 68px;
  height: 68px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--sunken);
}
.thumb.placeholder { display: grid; place-items: center; color: var(--muted); }

.coffee-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.coffee-card-name { font: 600 1.15rem/1.25 var(--serif); overflow-wrap: anywhere; }
.coffee-card-sub { color: var(--muted); font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coffee-card-meta { color: var(--muted); font-size: 0.82rem; margin-top: 3px; }
.chev { color: var(--muted); display: grid; }

.empty { margin: 12vh auto 0; max-width: 320px; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.empty h2 { font: 600 1.5rem/1.2 var(--serif); }
.empty p { color: var(--muted); }
.empty-mark { display: grid; place-items: center; width: 88px; height: 88px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); margin-bottom: 6px; }
.empty-line { color: var(--muted); padding: 8px 2px; }

/* ---------- rating badge ---------- */

.rating {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  background: var(--sunken);
  color: var(--muted);
}
.rating.r5, .rating.r6 { background: var(--accent-soft); color: var(--ink); }
.rating.r7, .rating.r8 { background: color-mix(in srgb, var(--accent) 45%, var(--accent-soft)); color: var(--ink); }
.rating.r9, .rating.r10 { background: var(--accent); color: var(--accent-ink); }

/* ---------- coffee detail ---------- */

.hero { display: flex; gap: 16px; align-items: flex-start; }

.hero-photos { flex: none; display: flex; gap: 6px; padding: 0; border: 0; background: none; }
.hero-photos img { width: 64px; height: 88px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); background: var(--sunken); }

.hero-text { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.eyebrow { color: var(--accent); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.hero-name { font: 600 1.75rem/1.15 var(--serif); letter-spacing: -0.01em; overflow-wrap: anywhere; }
.notes { font: italic 1.02rem/1.35 var(--serif); color: var(--muted); }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; padding: 14px 2px 0; border-top: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; }
.facts dd { overflow-wrap: anywhere; }

.best { padding: 14px 16px 16px; }
.best-head { display: flex; align-items: center; justify-content: space-between; font-weight: 650; }
.best-head .rating { width: 36px; height: 36px; font-size: 0.95rem; }

.recipe { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.recipe-cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.recipe-value { font: 600 1.5rem/1.1 var(--serif); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.recipe-value small { font: 500 0.8rem var(--sans); color: var(--muted); margin-left: 2px; }
.recipe-label { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 6px; }
.section-head h3 { font: 600 1.25rem var(--serif); }

.brews { display: flex; flex-direction: column; border-top: 1px solid var(--line); margin-top: -8px; }
.brew {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
}
.brew:active { background: var(--sunken); }
.brew-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.brew-main { font-weight: 600; font-variant-numeric: tabular-nums; }
.brew-sub { color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.brew-note { font: italic 0.95rem/1.35 var(--serif); margin-top: 4px; overflow-wrap: anywhere; }
.brew-date { flex: none; color: var(--muted); font-size: 0.82rem; padding-top: 2px; }

/* ---------- add a coffee ---------- */

.lead { color: var(--muted); }

.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.slot {
  position: relative;
  aspect-ratio: 3 / 4;
  display: grid;
  place-items: center;
  padding: 0;
  overflow: hidden;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
}
.slot.filled { border-style: solid; }
.slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.slot-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.reading { margin-top: 8vh; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.reading h2 { font: 600 1.4rem var(--serif); }
.reading-photos { display: flex; gap: 10px; margin-bottom: 12px; }
.reading-photos img { width: 96px; height: 128px; object-fit: cover; border-radius: 14px; border: 1px solid var(--line); }

.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.form-photos { display: flex; align-items: center; gap: 10px; }
.form-photos img { width: 54px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.form-photos .link { margin-left: 4px; }

.notice { padding: 12px 14px; border-radius: 14px; background: var(--accent-soft); font-size: 0.95rem; display: flex; flex-direction: column; gap: 4px; }
.notice.warn { background: var(--sunken); border: 1px solid var(--line); }

/* ---------- forms ---------- */

.form { display: flex; flex-direction: column; gap: 20px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field-label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.field-hint { font-size: 0.78rem; color: var(--muted); }
.field-error { color: var(--danger); font-size: 0.88rem; font-weight: 600; }

input, textarea {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px; /* below 16px iOS zooms the page on focus */
  appearance: none;
  -webkit-appearance: none;
}
textarea { height: auto; padding: 10px 12px; resize: none; line-height: 1.4; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 60%, transparent); }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button { display: none; }

.stepper { display: flex; align-items: stretch; height: 48px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.stepper:focus-within { outline: 2px solid var(--accent); border-color: transparent; }
.stepper input { flex: 1; height: auto; border: 0; border-radius: 0; background: none; padding: 0 2px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper input:focus { outline: none; }
.stepper button { flex: none; width: 42px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); }
.stepper button:active { background: var(--sunken); color: var(--ink); }

.rates { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.rate {
  height: 46px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.rate[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.rates-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.78rem; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions.stack { flex-direction: column; }

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-weight: 650;
}
.btn:active { background: var(--sunken); }
.btn:disabled { opacity: 0.6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn.danger-ghost { flex: none; background: transparent; border-color: transparent; color: var(--danger); }

.link { padding: 0; border: 0; background: none; color: var(--accent); font-weight: 650; text-decoration: underline; text-underline-offset: 3px; }

.danger-zone { display: flex; justify-content: center; padding-top: 8px; border-top: 1px solid var(--line); }

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

.setting { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.setting h3 { font: 600 1.15rem var(--serif); }

/* ---------- sheets ---------- */

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--bg);
  color: var(--ink);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet::backdrop { background: rgb(20 12 6 / 55%); }
.sheet[open] { animation: rise 0.22s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } }

.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 14px 8px 6px 20px; background: var(--bg); }
.sheet-head h2 { font: 600 1.4rem var(--serif); }
.sheet-body { display: flex; flex-direction: column; gap: 18px; padding: 4px 20px calc(24px + env(safe-area-inset-bottom)); }
.sheet-sub { margin-top: -6px; }

.photo-viewer img { width: 100%; border-radius: 14px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateX(-50%);
  max-width: min(92vw, 480px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.95rem;
  box-shadow: var(--shadow);
}

@media (max-width: 359px) {
  .rates { grid-template-columns: repeat(5, 1fr); }
  .recipe-value { font-size: 1.25rem; }
}
