:root {
  /* tells the browser to render native chrome (select popups, scrollbars, form
     controls) with a dark palette — without this, <option> lists fall back to
     the OS default light listbox no matter what CSS is set on <select>/<option> */
  color-scheme: dark;
  --bg-1: #1b1410;
  --bg-2: #2a1e17;
  /* two-tone accent: gold is decorative (map, borders, links), amber is reserved
     for primary actions only — keeps CTAs legible instead of gold-everywhere */
  --accent: #c9a27a;
  --accent-strong: #e08a2e;
  --text: #f2e9e1;
  --text-dim: #b8a99b;
  --glass-bg: rgba(40, 30, 24, 0.4);
  --glass-border: rgba(201, 162, 122, 0.22);
  --glass-border-hi: rgba(255, 232, 210, 0.12);
  /* heavier frost reserved for overlays (bottom sheet, nav) — 2026 consensus is
     "restrained glass": static content cards stay lighter/flatter */
  --glass-bg-overlay: rgba(30, 22, 17, 0.72);
}

* { box-sizing: border-box; }

/* Several components set their own `display` (flex/grid) on elements that JS
   also toggles via the native `hidden` attribute/property (autocomplete
   results, the new-coffee fieldset, photo previews) — author styles beat the
   browser's built-in `[hidden] { display: none }` UA rule regardless of
   selector specificity, so without this override those elements stayed
   visible (empty flex/grid boxes) even while `hidden` was set. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% -10%, #3a2a1f, transparent 60%),
              linear-gradient(160deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  backdrop-filter: blur(20px);
  background: var(--glass-bg-overlay);
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--accent);
  text-decoration: none;
}

.nav-links a {
  color: var(--text-dim);
  text-decoration: none;
  margin-left: 1.25rem;
  transition: color 0.15s;
}
.nav-links a:hover { color: var(--accent); }
.nav-user { margin-left: 1.25rem; color: var(--text); font-weight: 500; }

.content {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.glass-panel {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 1.5rem;
  backdrop-filter: blur(9px);
  box-shadow: inset 0 1px 0 var(--glass-border-hi), 0 8px 32px rgba(0, 0, 0, 0.3);
}

.map-panel {
  padding: 0;
  overflow: hidden;
  position: relative;
  border-radius: 0;
  border-left: none;
  border-right: none;
  /* break out of .content's max-width to span the full viewport — there's a lot
     of dead space on wide screens otherwise, and the map is the app's centerpiece */
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
}
#map { height: clamp(480px, 80vh, 1200px); width: 100%; background: #171009; }

.region-tooltip {
  background: var(--glass-bg-overlay) !important;
  border: 1px solid var(--glass-border) !important;
  color: var(--text) !important;
  font-size: 0.72rem !important;
  padding: 0.15rem 0.5rem !important;
  border-radius: 6px !important;
  box-shadow: none !important;
}
.region-tooltip::before { display: none !important; }

.farm-popup .leaflet-popup-content-wrapper {
  background: var(--glass-bg-overlay) !important;
  color: var(--text) !important;
  border: 1px solid var(--glass-border) !important;
  border-radius: 10px !important;
  backdrop-filter: blur(16px);
}
.farm-popup .leaflet-popup-content { font-size: 0.82rem; line-height: 1.4; margin: 0.7rem 0.9rem; }
.farm-popup .leaflet-popup-tip { background: var(--glass-bg-overlay) !important; }
.farm-popup a.leaflet-popup-close-button { color: var(--text-dim) !important; }

.map-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  background: var(--glass-bg-overlay);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  font-size: 0.78rem;
  color: var(--text-dim);
}
.map-legend .swatch { width: 12px; height: 12px; border-radius: 3px; }

h1, h2, h3 { font-family: "Fraunces", Georgia, serif; margin-top: 0; color: var(--text); font-weight: 600; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.tastings-table { width: 100%; border-collapse: collapse; }
.tastings-table th, .tastings-table td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--glass-border);
  font-size: 0.92rem;
}
.tastings-table th { color: var(--text-dim); font-weight: 500; }

.empty { color: var(--text-dim); }

.form-panel { max-width: 480px; margin: 0 auto; }
form { display: flex; flex-direction: column; gap: 1rem; }
label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; color: var(--text-dim); }
input, select, textarea {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-strong); }
option {
  background: #2a1e17;
  color: var(--text);
}

fieldset { border: 1px solid var(--glass-border); border-radius: 10px; padding: 1rem; }
legend { color: var(--text-dim); padding: 0 0.4rem; }

.flavor-grid { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.flavor-chip {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.flavor-chip:has(input:checked) {
  border-color: var(--accent-strong);
  background: rgba(224, 138, 46, 0.18);
  color: var(--text);
}

button, .btn {
  background: var(--accent-strong);
  color: #251505;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button:active, .btn:active { transform: scale(0.98); }

.form-error { color: #e08a8a; }
.form-hint { color: var(--text-dim); font-size: 0.9rem; }
.form-hint a { color: var(--accent); }

.photo-field { display: flex; flex-direction: column; gap: 0.5rem; }
.photo-field label { color: var(--text-dim); font-size: 0.9rem; }
.photo-field input[type="file"] { color: var(--text-dim); font-size: 0.85rem; }
.photo-preview {
  max-width: 220px;
  max-height: 220px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  object-fit: cover;
}
.current-photo { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.4rem; }
.current-photo img { width: 90px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--glass-border); }

.delete-form { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--glass-border); }
.btn-danger {
  background: transparent;
  border: 1px solid rgba(224, 138, 138, 0.4);
  color: #e08a8a;
}
.btn-danger:hover { background: rgba(224, 138, 138, 0.12); filter: none; }

.row-actions { display: flex; gap: 0.6rem; align-items: center; }
.row-actions a, .row-actions button.link-btn {
  background: none; border: none; padding: 0; font: inherit; cursor: pointer;
  color: var(--text-dim); text-decoration: underline; font-size: 0.85rem;
}
.row-actions a:hover, .row-actions button.link-btn:hover { color: var(--accent-strong); }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; vertical-align: middle; }

.search-form { display: flex; align-items: center; gap: 0.6rem; }
.search-form input[type="search"] { width: 220px; padding: 0.4rem 0.7rem; font-size: 0.88rem; }

.coffee-meta { color: var(--text-dim); }
.tasting-entry { padding: 0.75rem 0; border-bottom: 1px solid var(--glass-border); }
.tasting-entry:last-child { border-bottom: none; }

/* --- bottom sheet: click a country on the map, detail slides up over it
   instead of a small Leaflet popup or a centered modal --- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 6, 3, 0.35);
  z-index: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.sheet-overlay.open { opacity: 1; pointer-events: auto; }

.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 901;
  max-width: 640px;
  margin: 0 auto;
  max-height: 72vh;
  overflow-y: auto;
  background: var(--glass-bg-overlay);
  backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  padding: 1.25rem 1.5rem 1.75rem;
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.bottom-sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--glass-border);
  margin: 0 auto 1rem;
}
.sheet-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
}
.sheet-close:hover { color: var(--text); }

.sheet-title { font-size: 1.3rem; margin-bottom: 0.25rem; }
.sheet-subtitle { color: var(--text-dim); font-size: 0.88rem; margin-bottom: 1rem; }
.sheet-coffee {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--glass-border);
  gap: 1rem;
}
.sheet-coffee:last-child { border-bottom: none; }
.sheet-coffee a { color: var(--text); text-decoration: none; font-weight: 500; }
.sheet-coffee a:hover { color: var(--accent-strong); }
.sheet-coffee .rating { color: var(--accent); font-size: 0.85rem; white-space: nowrap; }
.sheet-empty { color: var(--text-dim); font-size: 0.9rem; }

.sheet-section { margin-bottom: 1.25rem; }
.sheet-section:last-child { margin-bottom: 0; }
.sheet-section-title {
  font-family: -apple-system, sans-serif;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 600;
  margin: 0 0 0.6rem;
}
.sheet-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.sheet-tag {
  background: rgba(201, 162, 122, 0.14);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.82rem;
  color: var(--accent);
}
.sheet-farm { padding: 0.55rem 0; border-bottom: 1px solid var(--glass-border); font-size: 0.9rem; }
.sheet-farm:last-child { border-bottom: none; }
.sheet-farm-region { color: var(--text-dim); font-size: 0.82rem; font-weight: normal; }
.sheet-farm-notes { margin: 0.2rem 0 0; color: var(--text-dim); font-size: 0.82rem; line-height: 1.4; }

/* --- nav active state --- */
.nav-links a.active { color: var(--accent-strong); font-weight: 600; }

/* --- map loading spinner --- */
.map-loading {
  position: absolute;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  color: var(--text-dim);
  font-size: 0.9rem;
  background: #171009;
  border-radius: 16px;
}
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--glass-border);
  border-top-color: var(--accent-strong);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- interactive star rating picker (radio trick, reverse DOM order) --- */
.star-picker { display: flex; flex-direction: column; gap: 0.35rem; }
.star-picker-label { font-size: 0.9rem; color: var(--text-dim); }
.star-picker-stars {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 0.15rem;
  font-size: 1.9rem;
}
.star-picker-stars input { position: absolute; opacity: 0; width: 0; height: 0; }
.star-picker-stars label {
  cursor: pointer;
  color: rgba(255, 255, 255, 0.15);
  transition: color 0.12s;
  line-height: 1;
}
.star-picker-stars label:hover,
.star-picker-stars label:hover ~ label,
.star-picker-stars input:checked ~ label {
  color: var(--accent-strong);
}

.star-picker-sm .star-picker-stars { font-size: 1.15rem; }
.star-picker-sm .star-picker-label { font-size: 0.8rem; }

.field-row { display: flex; gap: 1rem; }
/* min-width:0 overrides the flex-item default of min-width:auto — without it,
   an <input> won't shrink below its content-based intrinsic width and
   overflows the row (visible as the input's border poking past the panel's
   edge) once the two fields don't both fit at full size. */
.field-row label { flex: 1; min-width: 0; }

.sub-ratings {
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 0.2rem 1rem;
}
.sub-ratings summary {
  cursor: pointer;
  padding: 0.75rem 0;
  color: var(--text-dim);
  font-size: 0.9rem;
  user-select: none;
}
.sub-ratings[open] summary { color: var(--text); margin-bottom: 0.25rem; }
.sub-ratings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding-bottom: 1rem;
}
@media (max-width: 480px) {
  .field-row { flex-direction: column; gap: 1rem; }
  .sub-ratings-grid { grid-template-columns: 1fr; }
}

.sub-rating-bars { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin-top: 0.4rem; }
.sub-rating-bar { font-size: 0.78rem; color: var(--accent); }
.sub-rating-label { color: var(--text-dim); margin-right: 0.3rem; }

/* --- stats page --- */
.stat-tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; }
.stat-tile { text-align: center; padding: 0.5rem 0; }
.stat-tile-value { font-family: "Fraunces", Georgia, serif; font-size: 2rem; font-weight: 600; color: var(--accent-strong); }
.stat-tile-label { color: var(--text-dim); font-size: 0.82rem; margin-top: 0.2rem; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

.bar-list { display: flex; flex-direction: column; gap: 0.6rem; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 28px; align-items: center; gap: 0.7rem; }
.bar-row-label { font-size: 0.85rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.bar-fill { display: block; height: 100%; min-width: 4px; border-radius: 4px; background: var(--accent-strong); }
.bar-row-count { font-size: 0.8rem; color: var(--text-dim); text-align: right; }

@media (max-width: 640px) {
  .stat-tiles { grid-template-columns: repeat(2, 1fr); gap: 1.25rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 85px 1fr 24px; gap: 0.5rem; }
}

/* --- activity heatmap (GitHub-contributions style) --- */
.heatmap-total { color: var(--text-dim); font-size: 0.85rem; }
.heatmap-scroll { overflow-x: auto; padding-bottom: 0.25rem; }
.heatmap { display: flex; gap: 3px; width: max-content; }
.heatmap-col { display: flex; flex-direction: column; gap: 3px; }
.heatmap-cell {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.06);
}
.heatmap-cell.future { background: transparent; }
.heatmap-cell.level-1 { background: rgba(224, 138, 46, 0.28); }
.heatmap-cell.level-2 { background: rgba(224, 138, 46, 0.5); }
.heatmap-cell.level-3 { background: rgba(224, 138, 46, 0.75); }
.heatmap-cell.level-4 { background: #e08a2e; }
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.6rem;
  color: var(--text-dim);
  font-size: 0.78rem;
}
.heatmap-legend .heatmap-cell { width: 10px; height: 10px; }

/* --- coffee search autocomplete --- */
.autocomplete { position: relative; display: flex; flex-direction: column; gap: 0.35rem; }
.autocomplete label { color: var(--text-dim); font-size: 0.9rem; }
.autocomplete-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  margin-top: 0.25rem;
  max-height: 280px;
  overflow-y: auto;
  background: var(--glass-bg-overlay);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.autocomplete-item { padding: 0.55rem 0.75rem; cursor: pointer; font-size: 0.9rem; color: var(--text); }
.autocomplete-item .ac-meta { color: var(--text-dim); font-size: 0.8rem; }
.autocomplete-item:hover, .autocomplete-item.active { background: rgba(224, 138, 46, 0.16); }
.autocomplete-item mark { background: rgba(224, 138, 46, 0.35); color: inherit; border-radius: 3px; padding: 0 1px; }
/* reference-only hit (country/region/farm/roastery with no coffee yet) —
   dashed top border visually separates it from real "pick this coffee"
   results above it, .ac-plus signals "this starts a new entry" */
.autocomplete-item--new { color: var(--text-dim); border-top: 1px dashed var(--glass-border); }
.autocomplete-item--new:first-child { border-top: none; }
.autocomplete-item--new strong { color: var(--text); }
.autocomplete-item--new .ac-plus { color: var(--accent-strong, #e08a2e); font-weight: 700; }
.autocomplete-selected {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(224, 138, 46, 0.12);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.92rem;
  color: var(--accent);
}
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  align-self: flex-start;
}
.btn-link:hover { color: var(--accent-strong); }

/* --- responsive tables --- */
.table-scroll { overflow-x: auto; }

/* --- motion: stat tiles stagger in, bars grow from zero on page load,
   dropdown/selection feedback reads as tactile rather than instant-snap.
   Everything here is gated by prefers-reduced-motion at the bottom. --- */
.stat-tile {
  animation: tile-in 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.stat-tile:nth-child(1) { animation-delay: 0s; }
.stat-tile:nth-child(2) { animation-delay: 0.06s; }
.stat-tile:nth-child(3) { animation-delay: 0.12s; }
.stat-tile:nth-child(4) { animation-delay: 0.18s; }
.stat-tile:nth-child(5) { animation-delay: 0.24s; }
@keyframes tile-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* .bar-row sets --i (its index) via inline style in stats.html; --pct (its
   target width) lives on .bar-fill itself. Custom properties inherit, so the
   fill picks up its row's stagger index without needing its own attribute. */
.bar-fill {
  width: var(--pct, 0%);
  animation: bar-grow 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: calc(var(--i, 0) * 0.05s);
}
@keyframes bar-grow {
  from { width: 0%; }
  to { width: var(--pct, 0%); }
}

.autocomplete-results {
  animation: dropdown-in 0.15s ease both;
}
@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.flavor-chip {
  transition: border-color 0.15s, background 0.15s;
}
.flavor-chip:has(input:checked) {
  animation: chip-pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes chip-pop {
  40% { transform: scale(1.06); }
}

.star-picker-stars label { transition: color 0.12s, transform 0.15s; }
.star-picker-stars label:hover,
.star-picker-stars label:hover ~ label {
  transform: scale(1.15);
}

/* Leaflet redraws vector layer styles (hover, region highlight) via inline
   SVG attributes on setStyle() calls in map.js — without this, country/region
   hover was an instant snap instead of a soft transition. */
.leaflet-interactive {
  transition: fill-opacity 0.2s ease, stroke-width 0.2s ease, fill 0.2s ease;
}

/* "Szczegółowa ocena" <details> — height/max-height can't be transitioned
   cleanly on native details/summary (content unhides in a single frame with
   no established "from" value), but a keyframe *animation* reliably replays
   every time an element goes from display:none to visible, so this needs no
   JS: fades + settles in on open, and (accepted simplification) closes
   instantly like plain <details> always did. */
.sub-ratings[open] .sub-ratings-grid {
  animation: reveal-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes reveal-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .stat-tile, .bar-fill, .autocomplete-results,
  .flavor-chip:has(input:checked), .sub-ratings[open] .sub-ratings-grid {
    animation: none;
  }
  .bar-fill { width: var(--pct, 0%); }
  .leaflet-interactive, .star-picker-stars label {
    transition: none;
  }
}

/* --- mobile --- */
@media (max-width: 640px) {
  .topbar { padding: 0.8rem 1rem; flex-wrap: wrap; gap: 0.5rem; }
  .brand { font-size: 1.1rem; }
  .nav-links { display: flex; flex-wrap: wrap; gap: 0.4rem; }
  .nav-links a, .nav-links .nav-user { margin-left: 0; font-size: 0.85rem; }
  .content { margin: 1rem auto; padding: 0 0.85rem; gap: 1rem; }
  .glass-panel { padding: 1rem; border-radius: 12px; }
  #map, .map-loading { height: 360px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .bottom-sheet { padding: 1rem 1.1rem 1.4rem; max-height: 80vh; }
  .star-picker-stars { font-size: 1.6rem; }
}
