:root {
  color-scheme: dark;
  --ink: #0d120f;
  --ink-raised: #141a16;
  --surface: #1a211c;
  --surface-light: #e4dfd2;
  --paper: #ece6d9;
  --paper-strong: #f8f3e8;
  --muted: #9ca298;
  --line: #353d36;
  --line-light: #b9b5aa;
  --amber: #d6954c;
  --amber-bright: #efb86f;
  --copper: #a75831;
  --moss: #405748;
  --burgundy: #6f302a;
  --blue: #49606a;
  --serif: Georgia, "Times New Roman", serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: var(--ink); }
body { margin: 0; overflow-x: hidden; background: var(--ink); color: var(--paper); font-family: var(--sans); text-rendering: optimizeLegibility; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
::selection { background: var(--amber); color: var(--ink); }

.skip-link { position: fixed; left: 1rem; top: -4rem; z-index: 50; padding: .8rem 1rem; background: var(--paper); color: var(--ink); }
.skip-link:focus { top: 1rem; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 4.5rem;
  padding: .9rem clamp(1rem, 4vw, 4rem);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 2rem;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 18, 15, .9);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  color: var(--paper);
  font: 750 .72rem/1 var(--mono);
  letter-spacing: .08em;
  text-decoration: none;
}

.brand span { color: var(--amber-bright); }
.brand i { width: 1px; height: 1rem; background: var(--line); }

nav { display: flex; gap: 1.5rem; align-items: center; }
nav a, .nav-pour { color: var(--muted); font: 650 .72rem/1 var(--mono); letter-spacing: .04em; text-decoration: none; }
nav a:hover, nav a:focus-visible { color: var(--paper); }
.nav-pour { padding: .7rem .9rem; border: 1px solid var(--amber); background: transparent; color: var(--amber-bright); cursor: pointer; }
.nav-pour:hover, .nav-pour:focus-visible { background: var(--amber); color: var(--ink); }

.snapshot { justify-self: end; margin: 0; color: var(--muted); font: .68rem/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; }

.dashboard {
  min-height: calc(100svh - 4.5rem);
  padding: clamp(2.5rem, 6vw, 6rem) clamp(1rem, 5vw, 5rem) 0;
  display: grid;
  grid-template-columns: minmax(20rem, .88fr) minmax(24rem, 1.12fr);
  grid-template-rows: 1fr auto;
  gap: clamp(2rem, 5vw, 6rem);
  background:
    radial-gradient(circle at 18% 30%, rgba(214,149,76,.08), transparent 28rem),
    linear-gradient(rgba(236,230,217,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(236,230,217,.025) 1px, transparent 1px);
  background-size: auto, 5rem 5rem, 5rem 5rem;
}

.dashboard-copy { align-self: center; padding-bottom: 2rem; }
.kicker, .section-number { margin: 0; color: var(--amber-bright); font: 700 .74rem/1.45 var(--mono); letter-spacing: .09em; text-transform: uppercase; }

h1 { margin: 1rem 0 1.5rem; max-width: 10ch; color: var(--paper-strong); font-size: clamp(4rem, 8vw, 8.6rem); font-weight: 640; line-height: .86; letter-spacing: -.07em; }
h1 em { color: var(--amber); font-family: var(--serif); font-weight: 400; }
.intro { max-width: 36rem; margin: 0; color: #c2c6bd; font-size: clamp(1.05rem, 1.7vw, 1.3rem); line-height: 1.55; }

.hero-actions { margin-top: 2rem; display: flex; align-items: center; gap: 1.5rem; }
.primary-button { min-height: 3.25rem; padding: 0 1.15rem; display: inline-flex; align-items: center; justify-content: space-between; gap: 2.5rem; border: 1px solid var(--amber); background: var(--amber); color: var(--ink); font: 750 .78rem/1 var(--mono); letter-spacing: .04em; cursor: pointer; }
.primary-button:hover, .primary-button:focus-visible { background: var(--amber-bright); border-color: var(--amber-bright); }
.text-link { color: var(--muted); font: 650 .75rem/1 var(--mono); text-decoration: none; }
.text-link:hover, .text-link:focus-visible { color: var(--paper); }

.cabinet-image { position: relative; min-height: 31rem; margin: 0; align-self: stretch; overflow: hidden; border: 1px solid #41392e; background: var(--ink-raised); }
.cabinet-image::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 7rem rgba(0,0,0,.48); pointer-events: none; }
.cabinet-image img { width: 100%; height: 100%; display: block; object-fit: cover; object-position: 52% center; filter: saturate(.88) contrast(1.04); }
.cabinet-image figcaption { position: absolute; z-index: 2; right: 1rem; bottom: 1rem; left: 1rem; padding: .75rem; display: flex; justify-content: space-between; gap: 1rem; background: rgba(13,18,15,.78); backdrop-filter: blur(8px); color: #c4c7bd; font: .65rem/1.3 var(--mono); letter-spacing: .05em; text-transform: uppercase; }

.stat-strip { grid-column: 1 / -1; margin: 0; display: grid; grid-template-columns: repeat(6, 1fr); border-top: 1px solid var(--line); }
.stat-strip div { min-width: 0; padding: 1.25rem 1rem 1.5rem 0; }
.stat-strip div + div { padding-left: 1rem; border-left: 1px solid var(--line); }
.stat-strip dt { margin-bottom: .75rem; color: var(--muted); font: .68rem/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.stat-strip dd { margin: 0; color: var(--paper-strong); font: 720 clamp(1.6rem, 3vw, 2.7rem)/1 var(--mono); letter-spacing: -.05em; }

.shape, .collection { padding: clamp(4rem, 8vw, 8rem) clamp(1rem, 5vw, 5rem); }
.shape { background: var(--surface-light); color: var(--ink); }
.collection { background: var(--ink-raised); border-top: 1px solid var(--line); }

.section-heading { margin-bottom: clamp(3rem, 6vw, 6rem); display: grid; grid-template-columns: minmax(8rem, .35fr) minmax(0, 1fr); gap: 2rem; align-items: start; }
.shape .section-number { color: #85551f; }
.section-heading h2 { max-width: 13ch; margin: 0 0 1rem; color: inherit; font-size: clamp(2.9rem, 6vw, 6.5rem); font-weight: 620; line-height: .92; letter-spacing: -.065em; }
.section-heading > div > p { max-width: 42rem; margin: 0; color: #686c65; font-size: 1.05rem; line-height: 1.55; }
.collection .section-heading > div > p { color: var(--muted); }

.shape-grid { display: grid; grid-template-columns: 1.25fr 1fr .85fr; gap: 1px; background: var(--line-light); border: 1px solid var(--line-light); }
.analysis-card { min-width: 0; padding: clamp(1.25rem, 2.5vw, 2.25rem); background: #f1ece1; }
.card-heading { margin-bottom: 2.5rem; display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
.card-heading p { margin: 0; font-weight: 700; }
.card-heading span { color: #74766f; font: .68rem/1 var(--mono); text-transform: uppercase; letter-spacing: .05em; }

.region-bar { min-height: 4rem; display: flex; overflow: hidden; background: #d1ccc0; }
.region-segment { position: relative; flex: var(--count) 1 0; min-width: 2px; background: var(--segment-colour); }
.region-segment:hover::after { content: attr(aria-label); position: absolute; left: 50%; bottom: calc(100% + .5rem); z-index: 4; width: max-content; max-width: 14rem; padding: .45rem .55rem; transform: translateX(-50%); background: var(--ink); color: var(--paper); font: .68rem/1.3 var(--mono); }
.region-legend { margin-top: 1.5rem; display: grid; grid-template-columns: repeat(2, 1fr); gap: .8rem 1.2rem; }
.legend-item { display: grid; grid-template-columns: .6rem 1fr auto; gap: .55rem; align-items: center; color: #62665f; font-size: .82rem; }
.legend-swatch { width: .55rem; height: .55rem; background: var(--segment-colour); }
.legend-item strong { color: var(--ink); font: 700 .78rem/1 var(--mono); }

.ranking { margin: 0; padding: 0; list-style: none; }
.ranking li { display: grid; grid-template-columns: 1fr auto; gap: 1rem; padding: .75rem 0; border-top: 1px solid #cbc7bc; }
.ranking li:last-child { border-bottom: 1px solid #cbc7bc; }
.rank-name { min-width: 0; }
.rank-name p { margin: 0 0 .5rem; font-size: .9rem; }
.rank-track { height: 3px; background: #d5d0c4; }
.rank-fill { width: var(--width); height: 100%; background: var(--copper); }
.ranking strong { font: 720 .9rem/1 var(--mono); }

.extreme { padding: 1.5rem 0; border-top: 1px solid #cbc7bc; }
.extreme:last-child { border-bottom: 1px solid #cbc7bc; }
.extreme span { color: #777970; font: .68rem/1 var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.extreme strong { display: block; margin: .7rem 0 .45rem; font-family: var(--serif); font-size: clamp(1.45rem, 2.4vw, 2.4rem); font-weight: 400; line-height: 1.08; }
.extreme p { margin: 0; color: #646861; font-size: .85rem; line-height: 1.4; }

.control-panel { padding: 1rem; display: grid; grid-template-columns: minmax(15rem, 1.7fr) repeat(4, minmax(9rem, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.control-panel label { min-width: 0; padding: .75rem .85rem; display: flex; flex-direction: column; gap: .5rem; background: var(--ink); }
.control-panel label > span { color: var(--muted); font: .65rem/1 var(--mono); text-transform: uppercase; letter-spacing: .06em; }
.control-panel input, .control-panel select { width: 100%; min-width: 0; padding: .15rem 1.5rem .15rem 0; border: 0; outline: 0; background: transparent; color: var(--paper); font-size: .9rem; }
.control-panel select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--amber) 50%), linear-gradient(135deg, var(--amber) 50%, transparent 50%); background-position: calc(100% - 8px) 55%, calc(100% - 3px) 55%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.control-panel option { background: var(--ink); }
.control-panel label:focus-within { outline: 1px solid var(--amber); outline-offset: -1px; }
.control-panel input::placeholder { color: #646b64; }

.results-toolbar { min-height: 4.5rem; display: flex; justify-content: space-between; gap: 2rem; align-items: center; border-bottom: 1px solid var(--line); }
.results-toolbar p { margin: 0; color: var(--muted); font: .72rem/1 var(--mono); letter-spacing: .03em; }
.results-toolbar > div { display: flex; gap: 1rem; }
.quiet-button, .reset-button, .empty-state button, .text-button { padding: .45rem 0; border: 0; border-bottom: 1px solid transparent; background: transparent; color: var(--muted); font: 650 .72rem/1 var(--mono); cursor: pointer; }
.quiet-button { color: var(--amber-bright); }
.quiet-button:hover, .quiet-button:focus-visible { border-color: var(--amber); }
.reset-button:hover, .reset-button:focus-visible, .empty-state button:hover, .text-button:hover { color: var(--paper); border-color: var(--paper); }

.bottle-list { border-bottom: 1px solid var(--line); }
.list-header, .bottle-row { display: grid; grid-template-columns: 4rem minmax(15rem, 2fr) minmax(7rem, .7fr) 5rem 5rem 3.5rem 1.5rem; gap: 1rem; align-items: center; }
.list-header { min-height: 2.75rem; padding: 0 .75rem; color: #777f77; font: .65rem/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.bottle-row { width: 100%; min-height: 5rem; padding: .85rem .75rem; border: 0; border-top: 1px solid var(--line); background: transparent; color: inherit; text-align: left; cursor: pointer; transition: background .15s ease, padding .15s ease; }
.bottle-row:hover, .bottle-row:focus-visible { background: #1d261f; outline: 0; }
.bottle-row:focus-visible { box-shadow: inset 3px 0 var(--amber); }
.bottle-ref { color: #747d75; font: .68rem/1 var(--mono); }
.bottle-name { min-width: 0; }
.bottle-name strong { display: block; overflow: hidden; color: var(--paper-strong); font-size: .95rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.bottle-name small { display: block; margin-top: .25rem; color: var(--muted); font-size: .76rem; }
.bottle-region, .bottle-age, .bottle-abv, .bottle-qty { color: #bcc1b8; font: .76rem/1.3 var(--mono); }
.bottle-arrow { color: var(--amber); transform: translateX(-.2rem); transition: transform .15s ease; }
.bottle-row:hover .bottle-arrow { transform: translateX(.15rem); }
.review-dot { display: inline-block; width: .4rem; height: .4rem; margin-left: .5rem; border-radius: 50%; background: var(--amber); vertical-align: middle; }

.empty-state { padding: 5rem 1rem; text-align: center; border-top: 1px solid var(--line); }
.empty-state p { margin: 0 0 1rem; color: var(--muted); }
.empty-state button { color: var(--amber-bright); }

footer { min-height: 9rem; padding: 2rem clamp(1rem, 4vw, 4rem); display: grid; grid-template-columns: 1fr auto 1fr; gap: 2rem; align-items: center; border-top: 1px solid var(--line); background: var(--ink); color: var(--muted); }
footer p { margin: 0; font-size: .75rem; }
footer p:first-child { color: var(--paper); font: 700 .7rem/1 var(--mono); letter-spacing: .06em; }
footer p:first-child span { color: var(--amber); }
footer p:nth-child(2) { text-align: center; }
footer a { justify-self: end; color: var(--muted); font: .7rem/1 var(--mono); text-decoration: none; }
footer a:hover { color: var(--paper); }

dialog { margin: 0; color: var(--paper); }
dialog::backdrop { background: rgba(3,6,4,.72); backdrop-filter: blur(4px); }
.detail-dialog { width: min(38rem, 100%); max-width: none; height: 100%; max-height: none; inset: 0 0 0 auto; padding: clamp(1.5rem, 4vw, 3.5rem); border: 0; border-left: 1px solid var(--line); background: var(--ink-raised); overflow-y: auto; }
.pour-dialog { width: min(42rem, calc(100% - 2rem)); max-width: none; inset: 50% auto auto 50%; padding: clamp(1.5rem, 4vw, 3.5rem); transform: translate(-50%,-50%); border: 1px solid #72512f; background: #171c18; }
.dialog-close { position: absolute; top: 1.1rem; right: 1.2rem; width: 2.5rem; height: 2.5rem; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer; }
.dialog-close:hover, .dialog-close:focus-visible { color: var(--paper); border-color: var(--paper); }
.detail-ref { margin: 0 0 2.5rem; color: var(--amber-bright); font: .72rem/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.detail-dialog h2, .pour-dialog h2 { max-width: 12ch; margin: 0 0 1rem; color: var(--paper-strong); font-family: var(--serif); font-size: clamp(2.6rem, 6vw, 5rem); font-weight: 400; line-height: .92; letter-spacing: -.045em; }
.detail-byline { margin: 0 0 2.5rem; color: var(--muted); font-size: 1rem; }
.detail-facts { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-facts div { padding: 1.15rem 0; }
.detail-facts div + div { padding-left: 1rem; border-left: 1px solid var(--line); }
.detail-facts span, .detail-block span { display: block; margin-bottom: .55rem; color: #777f77; font: .65rem/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.detail-facts strong { color: var(--paper); font: 700 1rem/1 var(--mono); }
.detail-block { padding: 1.5rem 0; border-bottom: 1px solid var(--line); }
.detail-block p { margin: 0; color: #c0c5bc; line-height: 1.55; }
.detail-source { display: inline-block; margin-top: 1.5rem; color: var(--amber-bright); font: 700 .72rem/1 var(--mono); text-decoration: none; border-bottom: 1px solid var(--amber); }
.detail-warning { margin-top: 1.5rem; padding: 1rem; border: 1px solid #785430; background: rgba(214,149,76,.06); color: #d7c3a7; font-size: .8rem; line-height: 1.5; }

.pour-dialog > .kicker { margin-bottom: 1rem; }
.pour-result { margin: 2.5rem 0; padding: 1.5rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.pour-result .pour-name { margin: 0 0 .65rem; color: var(--paper-strong); font-family: var(--serif); font-size: clamp(2rem, 5vw, 3.8rem); line-height: 1; }
.pour-result .pour-meta { margin: 0; color: var(--muted); line-height: 1.5; }
.pour-result .pour-cask { margin: 1.3rem 0 0; color: #c3c7be; font-size: .88rem; line-height: 1.5; }
.pour-actions { display: flex; align-items: center; gap: 1.5rem; }

@media (max-width: 1100px) {
  .dashboard { grid-template-columns: 1fr 1fr; }
  .stat-strip { grid-template-columns: repeat(3, 1fr); }
  .stat-strip div:nth-child(4) { border-left: 0; }
  .stat-strip div:nth-child(n+4) { border-top: 1px solid var(--line); }
  .shape-grid { grid-template-columns: 1fr 1fr; }
  .extremes-card { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
  .extremes-card .card-heading { grid-column: 1 / -1; margin-bottom: 0; }
  .control-panel { grid-template-columns: 1.5fr 1fr 1fr; }
  .control-panel label:nth-child(n+4) { border-top: 1px solid var(--line); }
}

@media (max-width: 780px) {
  .topbar { grid-template-columns: 1fr auto; }
  .topbar nav a, .snapshot { display: none; }
  .dashboard { min-height: auto; grid-template-columns: 1fr; padding-top: 4rem; }
  .dashboard-copy { padding-bottom: 0; }
  .cabinet-image { min-height: 22rem; }
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .stat-strip div:nth-child(odd) { padding-left: 0; border-left: 0; }
  .stat-strip div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .section-heading { grid-template-columns: 1fr; gap: 1rem; }
  .shape-grid { grid-template-columns: 1fr; }
  .extremes-card { grid-column: auto; grid-template-columns: 1fr; gap: 0; }
  .extremes-card .card-heading { grid-column: auto; margin-bottom: 2.5rem; }
  .control-panel { grid-template-columns: 1fr 1fr; }
  .search-control { grid-column: 1 / -1; }
  .list-header { display: none; }
  .bottle-row { grid-template-columns: 3.5rem minmax(0, 1fr) 3.5rem 2.2rem 1.25rem; gap: .7rem; }
  .bottle-region, .bottle-age { display: none; }
  .bottle-abv { text-align: right; }
  footer { grid-template-columns: 1fr auto; }
  footer p:nth-child(2) { grid-column: 1 / -1; grid-row: 2; text-align: left; }
  .detail-dialog { width: 100%; }
}

@media (max-width: 480px) {
  h1 { font-size: clamp(3.7rem, 19vw, 5.5rem); }
  .hero-actions { align-items: flex-start; flex-direction: column; }
  .cabinet-image { min-height: 18rem; }
  .cabinet-image figcaption span:last-child { display: none; }
  .stat-strip dd { font-size: 1.65rem; }
  .control-panel { grid-template-columns: 1fr; }
  .search-control { grid-column: auto; }
  .results-toolbar { padding: 1rem 0; align-items: flex-start; flex-direction: column; gap: 1rem; }
  .bottle-row { grid-template-columns: 2.8rem minmax(0, 1fr) 3.2rem 1rem; padding-right: .2rem; padding-left: .2rem; }
  .bottle-qty { display: none; }
  .detail-facts { grid-template-columns: 1fr; }
  .detail-facts div + div { padding-left: 0; border-top: 1px solid var(--line); border-left: 0; }
  .pour-actions { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; }
}
