/* ---------- Whisky bar theme ---------- */
:root {
  --wood-900: #1a1109;
  --wood-800: #24170c;
  --wood-700: #33210f;
  --wood-600: #4a3218;
  --leather: #3b2416;
  --cream: #f1e3c8;
  --cream-dim: #c9b795;
  --amber: #d99a2b;
  --amber-bright: #f2b63d;
  --brass: #b08d57;
  --ember: #b3442c;
  --gold-pale: #e6cf8a;
  --moss: #6f8f5a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  --radius: 10px;
  --serif: 'Playfair Display', 'Georgia', 'Times New Roman', serif;
  --body: 'Lora', 'Georgia', serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--body);
  color: var(--cream);
  background:
    radial-gradient(ellipse at top, rgba(217, 154, 43, 0.10), transparent 55%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.015) 0 2px, transparent 2px 7px),
    linear-gradient(180deg, var(--wood-800), var(--wood-900) 60%, #120b05);
  background-attachment: fixed;
  line-height: 1.45;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 500; margin: 0; letter-spacing: 0.01em; }
a { color: var(--amber-bright); }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: 0.9rem 1.5rem;
  background: linear-gradient(180deg, var(--wood-700), var(--wood-800));
  border-bottom: 2px solid var(--brass);
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-mark { color: var(--amber); font-size: 1.6rem; }
.brand h1 { font-size: 1.5rem; color: var(--gold-pale); }
.topbar nav { display: flex; gap: 0.25rem; }
.nav-link {
  color: var(--cream-dim); text-decoration: none; padding: 0.45rem 0.9rem;
  border-radius: 999px; font-family: var(--serif); font-size: 1.05rem;
}
.nav-link:hover { color: var(--cream); background: rgba(255, 255, 255, 0.05); }
.nav-link.active { color: var(--wood-900); background: var(--amber); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; color: var(--cream-dim); font-size: 0.9rem; }

.page { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1.1rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--brass); color: var(--cream);
  background: linear-gradient(180deg, var(--wood-600), var(--wood-700));
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn-primary { background: linear-gradient(180deg, var(--amber-bright), var(--amber)); color: var(--wood-900); border-color: var(--amber-bright); font-weight: 600; }
.btn-danger { border-color: var(--ember); color: #ffd9cf; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--cream-dim); }
.btn-ghost:hover { color: var(--cream); background: rgba(255, 255, 255, 0.06); }
.btn-lg { font-size: 1.15rem; padding: 0.8rem 1.6rem; font-family: var(--serif); }

/* ---------- Panels & tags ---------- */
.panel {
  background: linear-gradient(180deg, rgba(74, 50, 24, 0.55), rgba(36, 23, 12, 0.7));
  border: 1px solid rgba(176, 141, 87, 0.45); border-radius: var(--radius);
  padding: 1.1rem 1.3rem; box-shadow: var(--shadow);
}
.statbar { display: flex; flex-wrap: wrap; gap: 0.9rem; align-items: center; margin-bottom: 1.2rem; }
.stat {
  display: flex; flex-direction: column; align-items: center; min-width: 6.5rem;
  padding: 0.5rem 0.9rem; border-radius: 6px 6px 14px 14px;
  background: var(--leather); border: 1px solid var(--brass); position: relative;
}
.stat::before { content: ''; position: absolute; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--brass); }
.stat .n { font-family: var(--serif); font-size: 1.7rem; color: var(--gold-pale); line-height: 1; }
.stat .l { font-size: 0.75rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--cream-dim); }
.statbar .grow { flex: 1; }
.subtle { color: var(--cream-dim); font-size: 0.9rem; }

.badge {
  display: inline-block; padding: 0.15rem 0.6rem; border-radius: 4px 4px 10px 10px;
  font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; border: 1px solid;
}
.badge-alive { color: var(--amber-bright); border-color: var(--amber); background: rgba(217, 154, 43, 0.15); }
.badge-unopened { color: var(--gold-pale); border-color: var(--brass); background: rgba(176, 141, 87, 0.15); }
.badge-dead { color: #f0a08a; border-color: var(--ember); background: rgba(179, 68, 44, 0.18); }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center; margin-bottom: 1rem; }
.filters .group { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.filters label { font-size: 0.8rem; color: var(--cream-dim); text-transform: uppercase; letter-spacing: 0.08em; margin-right: 0.2rem; }
.chip {
  padding: 0.3rem 0.75rem; border-radius: 999px; cursor: pointer; font-size: 0.9rem;
  border: 1px solid rgba(176, 141, 87, 0.6); background: transparent; color: var(--cream-dim);
}
.chip:hover { color: var(--cream); border-color: var(--brass); }
.chip.on { background: var(--amber); color: var(--wood-900); border-color: var(--amber); }
.chip .x { margin-left: 0.35rem; opacity: 0.7; }
input[type="text"], input[type="url"], input[type="number"], input[type="search"], select {
  background: rgba(0, 0, 0, 0.35); color: var(--cream); border: 1px solid rgba(176, 141, 87, 0.6);
  border-radius: 6px; padding: 0.45rem 0.7rem; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--amber); outline-offset: 1px; }
input[type="number"] { width: 5rem; }
.range { display: flex; align-items: center; gap: 0.3rem; }
.results-head { display: flex; align-items: center; gap: 1rem; margin: 0.5rem 0; color: var(--cream-dim); }
.results-head .spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--brass); border-radius: 999px; overflow: hidden; }
.seg button { background: transparent; color: var(--cream-dim); border: 0; padding: 0.3rem 0.8rem; cursor: pointer; }
.seg button.on { background: var(--brass); color: var(--wood-900); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid rgba(176, 141, 87, 0.45); }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
thead th {
  text-align: left; padding: 0.7rem 0.8rem; font-family: var(--serif); font-weight: 500;
  color: var(--gold-pale); background: var(--wood-700); border-bottom: 2px solid var(--brass);
  cursor: pointer; user-select: none; white-space: nowrap; position: sticky; top: 0;
}
thead th.sorted { color: var(--amber-bright); }
tbody td { padding: 0.55rem 0.8rem; border-bottom: 1px solid rgba(176, 141, 87, 0.18); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:nth-child(odd) { background: rgba(255, 255, 255, 0.025); }
tbody tr:hover { background: rgba(217, 154, 43, 0.12); }
tbody tr.dead { color: var(--cream-dim); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 2rem; text-align: center; color: var(--cream-dim); font-style: italic; }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.card { cursor: pointer; display: flex; flex-direction: column; gap: 0.4rem; transition: transform 0.12s ease; }
.card:hover { transform: translateY(-3px); }
.card .thumb {
  height: 160px; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.35); border-radius: 6px; overflow: hidden; font-size: 3rem; color: var(--brass);
}
.card .thumb img { height: 100%; width: 100%; object-fit: contain; }
.card h3 { font-size: 1.05rem; color: var(--gold-pale); }
.card .meta { font-size: 0.85rem; color: var(--cream-dim); display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- Modal / drawer ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(8, 4, 1, 0.7); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem;
}
.modal {
  width: min(680px, 100%); max-height: 92vh; overflow: auto;
  background: linear-gradient(180deg, var(--wood-700), var(--wood-800));
  border: 1px solid var(--brass); border-radius: 14px; box-shadow: var(--shadow); padding: 1.5rem 1.7rem;
}
.modal-head { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.modal-head h2 { font-size: 1.6rem; color: var(--gold-pale); }
.modal-head .close { margin-left: auto; }
.access-backdrop { z-index: 70; }
.access-modal { max-width: 34rem; }
.access-error { color: #ffd2cb; background: rgba(132, 42, 31, .35); border: 1px solid rgba(255, 151, 136, .35); padding: .75rem; border-radius: .45rem; }
.mode-divider { display: flex; align-items: center; gap: .75rem; color: var(--cream-dim); margin: 1rem 0; }
.mode-divider::before, .mode-divider::after { content: ''; height: 1px; background: rgba(176, 141, 87, 0.45); flex: 1; }
.edit-cue { margin-top: .5rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1.2rem; margin: 1rem 0; }
.kv dt { color: var(--cream-dim); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; align-self: center; }
.kv dd { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; }
.bottle-img { max-height: 260px; display: block; margin: 0 auto 1rem; border-radius: 6px; }
.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.inline-form input { flex: 1; min-width: 12rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.8rem 1rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label { font-size: 0.8rem; color: var(--cream-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.field.wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 0.5rem; }

/* ---------- Pour ---------- */
.pour { text-align: center; padding: 1rem 0; }
.pour .glass { font-size: 4.5rem; line-height: 1; filter: drop-shadow(0 6px 16px rgba(217, 154, 43, 0.45)); }
.pour h2 { font-size: 2rem; margin: 0.6rem 0 0.2rem; color: var(--gold-pale); }
.pour .distillery { font-size: 1.2rem; color: var(--amber-bright); letter-spacing: 0.15em; text-transform: uppercase; }
.pour .rolling h2 { animation: flicker 0.25s infinite alternate; }
@keyframes flicker { from { opacity: 0.5; } to { opacity: 1; } }
.pour .meta { margin: 0.8rem 0; color: var(--cream-dim); }

/* ---------- Map ---------- */
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 1.5rem; align-items: start; }
.map-panel { position: relative; }
.map-svg { width: 100%; height: auto; display: block; max-height: 82vh; }
.land { fill: #3a2a17; stroke: var(--brass); stroke-width: 0.6; stroke-linejoin: round; }
.dot { stroke: var(--wood-900); stroke-width: 0.5; cursor: pointer; transition: r 0.1s ease; }
.dot:hover, .dot:focus { stroke: var(--cream); stroke-width: 1.2; outline: none; }
.dot-none { fill: #aeb8b8; opacity: 1; }
.dot-alive { fill: var(--amber-bright); }
.dot-unopened { fill: var(--gold-pale); }
.dot-dead { fill: var(--ember); }
.region-label { fill: rgba(241, 227, 200, 0.45); font-family: var(--serif); font-size: 6px; letter-spacing: 0.15em; text-transform: uppercase; pointer-events: none; }
.legend { display: flex; flex-direction: column; gap: 0.5rem; }
.legend .row { display: flex; align-items: center; gap: 0.6rem; }
.swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--wood-900); }
.map-tip {
  position: fixed; z-index: 60; pointer-events: none; max-width: 300px;
  background: var(--wood-800); border: 1px solid var(--brass); border-radius: 8px;
  padding: 0.6rem 0.8rem; font-size: 0.85rem; box-shadow: var(--shadow);
}
.map-tip h4 { margin: 0 0 0.3rem; font-family: var(--serif); color: var(--gold-pale); font-size: 1rem; }
.map-tip ul { margin: 0; padding-left: 1rem; }
.map-tip .none { color: var(--cream-dim); font-style: italic; }
@media (max-width: 900px) { .map-layout { grid-template-columns: 1fr; } }

/* ---------- Landing & settings ---------- */
.landing { max-width: 620px; margin: 4rem auto; text-align: center; }
.landing h1 { font-size: 2.6rem; color: var(--gold-pale); margin-bottom: 0.4rem; }
.landing form { display: flex; flex-direction: column; gap: 0.7rem; margin: 1.5rem 0; text-align: left; }
.recent { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.recent li { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.6rem; border-radius: 6px; background: rgba(0, 0, 0, 0.25); }
.recent li .url { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem; color: var(--cream-dim); }
.settings { max-width: 760px; display: flex; flex-direction: column; gap: 1.2rem; }
.settings h2 { font-size: 1.3rem; color: var(--gold-pale); margin-bottom: 0.6rem; }
.banner { padding: 0.6rem 1rem; border-radius: 8px; background: rgba(179, 68, 44, 0.25); border: 1px solid var(--ember); margin-bottom: 1rem; }
.banner.info { background: rgba(176, 141, 87, 0.2); border-color: var(--brass); }

/* ---------- Toasts & spinner ---------- */
#toasts { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 0.5rem; z-index: 100; }
.toast {
  padding: 0.7rem 1.2rem; border-radius: 999px; border: 1px solid var(--brass);
  background: var(--wood-700); color: var(--cream); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px); transition: opacity 0.3s, transform 0.3s;
}
.toast.show { opacity: 1; transform: none; }
.toast-success { border-color: var(--moss); }
.toast-error { border-color: var(--ember); background: #3a1a12; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; display: inline-block;
  border: 2px solid rgba(241, 227, 200, 0.3); border-top-color: var(--amber); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

/* ---------- Add form ---------- */
.field input[type="number"], .field input[type="text"], .field input[type="url"] { width: 100%; }
.req { color: var(--amber-bright); }

/* ---------- Map legend swatches ---------- */
.swatch.dot-none { background: #aeb8b8; }
.swatch.dot-alive { background: var(--amber-bright); }
.swatch.dot-unopened { background: var(--gold-pale); }
.swatch.dot-dead { background: var(--ember); }

/* ---------- Interactive distillery explorer ---------- */
.explorer-heading, .selection-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.explorer-heading { margin-bottom: 1rem; }
.explorer-heading h2 { font-size: 1.8rem; color: var(--gold-pale); }
.eyebrow { margin: 0 0 0.3rem; text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.75rem; color: var(--cream-dim); }
.map-explorer .map-layout { grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; }
.map-column { min-width: 0; display: grid; gap: 1rem; }
.map-explorer .map-panel { padding: 0.8rem; overflow: hidden; }
.map-controls { display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
.map-controls .btn { min-height: 44px; }
.map-controls output { min-width: 3.5rem; text-align: center; color: var(--gold-pale); font-variant-numeric: tabular-nums; }
.map-controls .btn:disabled { cursor: default; }
.map-explorer .map-svg { height: clamp(330px, 56vh, 640px); width: 100%; max-height: none; touch-action: none; cursor: grab; user-select: none; }
.map-svg.is-dragging, .map-svg.is-dragging .dot { cursor: grabbing; }
.map-svg:focus-visible { outline: 2px solid var(--amber); outline-offset: -2px; border-radius: 6px; }
.map-ring { fill: none; stroke: var(--amber-bright); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.map-explorer .land { vector-effect: non-scaling-stroke; stroke-width: 1.2; }
.map-ring[hidden] { display: none; }
.dot { vector-effect: non-scaling-stroke; stroke-width: 1px; }
.dot.map-muted { opacity: 0.16; }
.dot[hidden] { display: none; }
.dot[aria-pressed="true"] { stroke: var(--cream); stroke-width: 2px; }
.map-help { text-align: center; margin: 0.4rem 0; font-size: 0.75rem; }
.map-legend { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; justify-content: center; font-size: 0.8rem; color: var(--cream-dim); }
.map-legend > span { display: inline-flex; align-items: center; gap: 0.35rem; }
.map-legend .swatch { width: 10px; height: 10px; }
.distillery-browser { padding: 1rem; min-width: 0; }
.distillery-browser h2 { font-size: 1.25rem; margin-bottom: 1rem; color: var(--gold-pale); }
.distillery-browser label { display: block; font-size: 0.75rem; color: var(--cream-dim); margin: 0.5rem 0 0.3rem; }
.distillery-browser input, .distillery-browser select { width: 100%; min-height: 44px; font-size: 0.85rem; }
.explorer-filter-row { display: grid; grid-template-columns: 1fr 1.2fr; gap: 0.5rem; }
.explorer-filter-row > div { min-width: 0; }
.distillery-browser .closed-toggle { min-height: 44px; display: flex; align-items: center; gap: 0.55rem; margin: 0.45rem 0 0; cursor: pointer; }
.closed-toggle input { width: 1.1rem; min-height: 1.1rem; accent-color: var(--amber); }
.explorer-clear { margin-top: 0.4rem; font-size: 0.8rem; }
.explorer-count { font-size: 0.8rem; margin: 0.4rem 0; }
.distillery-list { max-height: 56vh; overflow-y: auto; overscroll-behavior: contain; scrollbar-color: var(--brass) var(--wood-800); padding: 3px; }
.distillery-entry { display: block; width: 100%; text-align: left; color: var(--cream); background: transparent; border: 1px solid transparent; border-bottom-color: rgba(176,141,87,0.22); border-radius: 6px; padding: 0.65rem 0.55rem; cursor: pointer; }
.distillery-entry:hover { background: rgba(217,154,43,0.08); }
.distillery-entry.selected { background: rgba(217,154,43,0.16); border-color: var(--amber); }
.distillery-entry-name { display: flex; align-items: center; gap: 0.5rem; }
.distillery-entry-name strong { font-weight: 600; font-size: 0.9rem; }
.distillery-entry-name .swatch { flex: 0 0 10px; width: 10px; height: 10px; }
.distillery-entry > .subtle { display: block; font-size: 0.72rem; margin: 0.2rem 0 0 1.15rem; }
.bottle-count { margin-left: auto; color: var(--gold-pale); font-size: 0.8rem; }
.map-explorer button:focus-visible { outline: 2px solid var(--amber-bright); outline-offset: 2px; }
.map-selection { scroll-margin-top: 100px; }
.map-browse-back { display: none; }
.map-selection h2 { color: var(--gold-pale); }
.map-selection p { margin: 0.5rem 0; }
.distillery-status-closed { color: #e1a48e; }
.distillery-locality { margin-top: 0.25rem; }
.distillery-blurb { max-width: 65ch; color: var(--cream); line-height: 1.55; }
.selection-placeholder { padding: 0.5rem 0; }
.map-bottles { display: grid; gap: 0.4rem; max-height: 200px; overflow: auto; margin: 0.8rem 0; padding: 3px; }
.map-bottle { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; text-align: left; border: 1px solid rgba(176,141,87,0.3); border-radius: 6px; background: rgba(0,0,0,0.15); color: var(--cream); padding: 0.6rem; cursor: pointer; }
.map-bottle:hover { border-color: var(--amber); }
.map-bottle .badge { flex-shrink: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 900px) {
  .map-explorer .map-layout { grid-template-columns: 1fr; }
  .map-browse-back { display: inline-flex; }
  .map-selection, .distillery-browser { scroll-margin-top: 200px; }
  .explorer-heading { align-items: flex-start; flex-direction: column; gap: 0.3rem; }
  .explorer-heading p { margin: 0; }
  .map-explorer .map-svg { height: 48vh; min-height: 300px; }
  .distillery-list { max-height: 50vh; }
}
@media (max-width: 480px) {
  .page { padding: 0.8rem; }
  .selection-heading { flex-wrap: wrap; }
  .map-controls { gap: 0.25rem; }
  .map-controls .btn { padding: 0.5rem 0.7rem; }
  .map-bottle { flex-wrap: wrap; }
}
