/* ============================================================================
   Bean Book — modern, warm coffee styling. Light & dark via prefers-color-scheme
   with a manual [data-theme] override. Zero dependencies.
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Warm coffee palette */
  --bg: #f7f3ee;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --text: #2b2018;
  --text-muted: #7a6a5c;
  --border: #e7ddd2;
  --accent: #b5651d;         /* roasted amber */
  --accent-strong: #8a4a12;
  --accent-contrast: #ffffff;
  --link: #8a4a12;           /* readable link on light bg */
  --star: #e0a326;
  --star-empty: #d9ccbe;
  --shadow: 0 1px 2px rgba(43, 32, 24, 0.06), 0 8px 24px rgba(43, 32, 24, 0.08);
  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 1080px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #1a1410;
  --bg-elev: #241b15;
  --surface: #241b15;
  --text: #f3ebe2;
  --text-muted: #b3a293;
  --border: #38291f;
  --accent: #e0994f;
  --accent-strong: #f0b878;
  --accent-contrast: #241b15;
  --link: #e0994f;           /* brighter link on dark bg */
  --star: #f0b64a;
  --star-empty: #46372c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #1a1410;
    --bg-elev: #241b15;
    --surface: #241b15;
    --text: #f3ebe2;
    --text-muted: #b3a293;
    --border: #38291f;
    --accent: #e0994f;
    --accent-strong: #f0b878;
    --accent-contrast: #241b15;
    --link: #e0994f;
    --star: #f0b64a;
    --star-empty: #46372c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); }

code, .build { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.app { min-height: 100dvh; display: flex; flex-direction: column; }

.content {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.25rem clamp(1rem, 4vw, 2rem) 3rem;
  /* Respect iOS notch / Dynamic Island in landscape (installed PWA). */
  padding-left: max(clamp(1rem, 4vw, 2rem), env(safe-area-inset-left));
  padding-right: max(clamp(1rem, 4vw, 2rem), env(safe-area-inset-right));
  flex: 1;
  outline: none;
}

/* ---------- Header / footer ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem clamp(1rem, 4vw, 2rem);
  /* When installed on iOS the status bar / Dynamic Island overlays the web
     view (viewport-fit=cover + translucent status bar), so pad by the safe
     area to keep the header clear of the time, notch and battery icons. */
  padding-top: calc(0.75rem + env(safe-area-inset-top));
  padding-left: max(clamp(1rem, 4vw, 2rem), env(safe-area-inset-left));
  padding-right: max(clamp(1rem, 4vw, 2rem), env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 0.5rem; text-decoration: none; color: var(--text); font-weight: 700; }
.brand-mark { font-size: 1.5rem; }
.brand-name { font-size: 1.2rem; letter-spacing: -0.01em; }
.site-nav { display: flex; align-items: center; gap: 0.5rem; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem;
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.site-footer p { margin: 0.25rem 0; }
.build {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.05rem 0.4rem;
  font-size: 0.8rem;
  text-decoration: none;
  color: var(--text-muted);
  transition: border-color 0.15s ease, color 0.15s ease;
}
a.build:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; }

.theme-toggle {
  font: inherit;
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ---------- Hero ---------- */
.hero { padding: 1.5rem 0 1rem; }
.hero h1 { font-size: clamp(2rem, 6vw, 3rem); margin: 0 0 0.25rem; letter-spacing: -0.03em; }
.tagline { color: var(--text-muted); max-width: 46ch; margin: 0 0 1rem; font-size: 1.05rem; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: grid; gap: 0.75rem; margin: 0.5rem 0 1rem; }
.search {
  width: 100%;
  font: inherit;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.search:focus-visible, select:focus-visible, .btn:focus-visible, .theme-toggle:focus-visible,
input:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.controls { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: end; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
select {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.checks { display: flex; gap: 1rem; align-items: center; }
.check { display: inline-flex; gap: 0.4rem; align-items: center; cursor: pointer; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

.result-count { margin: 0 0 1rem; font-size: 0.9rem; }

/* ---------- Grid & cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 1rem;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: transform 0.08s ease, border-color 0.15s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card-top { display: flex; align-items: center; gap: 0.6rem; }
.card-title { font-size: 1.2rem; margin: 0.1rem 0 0; letter-spacing: -0.01em; }
.card-roaster { margin: 0; color: var(--text-muted); font-weight: 600; }
.card-origin { margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.card-foot { margin-top: auto; padding-top: 0.4rem; display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.value-hint { font-variant-numeric: tabular-nums; }

.rating-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.6rem;
  padding: 0.15rem 0.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  color: var(--link);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.rating-badge.big { font-size: 1.5rem; min-width: 3.4rem; padding: 0.3rem 0.7rem; }
.rating-badge.small { min-width: 2.2rem; font-size: 0.85rem; }

/* ---------- Star bar ---------- */
.stars { position: relative; display: inline-block; font-size: 1rem; line-height: 1; letter-spacing: 2px; white-space: nowrap; }
.stars-empty { color: var(--star-empty); }
.stars-full { position: absolute; top: 0; left: 0; color: var(--star); overflow: hidden; white-space: nowrap; }

/* ---------- Badges & tags ---------- */
.badges, .tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.tag {
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--link);
}

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

/* ---------- Bean detail ---------- */
.back { display: inline-block; margin: 0.5rem 0 1rem; text-decoration: none; font-weight: 600; }
.bean-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.bean-title h1 { margin: 0; font-size: clamp(1.6rem, 5vw, 2.4rem); letter-spacing: -0.02em; }
.bean-roaster { margin: 0.2rem 0 0; color: var(--text-muted); font-weight: 600; font-size: 1.1rem; }
.bean-score { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem 1.5rem;
  margin: 0 0 0.5rem;
}
.fact dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 700; }
.fact dd { margin: 0.1rem 0 0; font-weight: 600; }

.section-title { font-size: 1.25rem; margin: 1.5rem 0 0.75rem; letter-spacing: -0.01em; }
.flavour-block { margin-bottom: 1rem; }

/* ---------- Reviews ---------- */
.reviews { display: flex; flex-direction: column; gap: 1rem; }
.review {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
}
.review-head { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.avatar { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); object-fit: cover; }
.avatar-fallback {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-contrast); font-weight: 700; font-size: 0.9rem;
}
.review-who { display: flex; flex-direction: column; margin-right: auto; }
.author-name { font-weight: 700; text-decoration: none; }
.review-rating { display: flex; align-items: center; gap: 0.5rem; }
.review-notes { margin: 0.75rem 0 0.5rem; white-space: pre-wrap; }
.review-link { display: inline-block; margin-top: 0.5rem; text-decoration: none; }

/* ---------- Empty state ---------- */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty h1 { color: var(--text); }
.error { padding: 2rem; text-align: center; }

@media (max-width: 520px) {
  .bean-header { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
