:root {
  --bg: #141820;
  --panel: #1c232e;
  --panel-2: #151b24;
  --ink: #f4f1ea;
  --muted: #9aa3b2;
  --line: rgba(255,255,255,.08);
  --yellow: #f2cd37;
  --red: #c91a09;
  --blue: #0055bf;
  --ocean-deep: #082848;
  --shadow: 0 12px 40px rgba(0,0,0,.35);
  --sans: "Nunito", "Segoe UI", sans-serif;
  --display: "Rubik", "Nunito", sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --app-h: 100dvh;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  height: var(--app-h, 100dvh);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  color-scheme: dark;
}

button, a, input, label {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(242, 205, 55, .28);
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: calc(.7rem + var(--sat)) calc(1rem + var(--sar)) .7rem calc(1rem + var(--sal));
  background: var(--yellow);
  color: #1a1408;
  z-index: 5;
  border-bottom: 6px solid #c91a09;
}

.logo {
  display: flex;
  align-items: center;
  gap: .7rem;
  flex-shrink: 0;
}

.brick-mark {
  width: 42px;
  height: 34px;
  background: var(--red);
  border-radius: 6px;
  position: relative;
  box-shadow: 0 3px 0 #7a0e06;
}
.brick-mark::before,
.brick-mark::after {
  content: "";
  position: absolute;
  top: -5px;
  width: 12px;
  height: 10px;
  background: var(--red);
  border-radius: 50%;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
}
.brick-mark::before { left: 6px; }
.brick-mark::after { right: 6px; }

header h1 {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  line-height: 1.1;
  white-space: nowrap;
}
header h1 span {
  display: block;
  font-family: var(--sans);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .16em;
  opacity: .7;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: .45rem;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.search {
  position: relative;
}
.search input {
  width: min(240px, 36vw);
  padding: .45rem .7rem .45rem 2rem;
  border: 2px solid rgba(0,0,0,.12);
  border-radius: 999px;
  background: #fff8d6;
  font: 700 .9rem var(--sans);
  color: #1a1408;
  outline: none;
}
.search input:focus { border-color: var(--blue); }
.search::before {
  content: "";
  position: absolute;
  left: .7rem;
  top: 50%;
  width: 8px;
  height: 8px;
  border: 2px solid #1a1408;
  border-radius: 50%;
  transform: translateY(-60%);
  opacity: .55;
  pointer-events: none;
}

.seg {
  display: flex;
  flex-wrap: wrap;
  background: rgba(0,0,0,.12);
  border-radius: 999px;
  padding: 3px;
}
.seg button,
.icon-btn {
  font: 800 .72rem/1 var(--sans);
  letter-spacing: .04em;
  text-transform: uppercase;
  border: 0;
  background: transparent;
  color: #1a1408;
  padding: .42rem .58rem;
  border-radius: 999px;
  cursor: pointer;
}
.seg button.active {
  background: #1a1408;
  color: var(--yellow);
}
.icon-btn {
  min-width: 2.1rem;
  min-height: 2.1rem;
  background: rgba(0,0,0,.12);
}
.icon-btn[hidden] { display: none; }
.seg button[hidden] { display: none; }
.sheet-btn { display: none; }

.stage {
  display: grid;
  grid-template-columns: 1fr minmax(280px, 340px);
  min-height: 0;
}

.map-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.viewport {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 280px;
  background:
    radial-gradient(1200px 600px at 50% 40%, #16345c 0%, var(--ocean-deep) 70%);
  cursor: grab;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}
.viewport.dragging { cursor: grabbing; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.map-zoom {
  display: none;
  position: absolute;
  z-index: 5;
  top: max(.75rem, var(--sat));
  right: max(.75rem, var(--sar));
  flex-direction: column;
  gap: .35rem;
}
.map-zoom .icon-btn {
  width: 2.75rem;
  height: 2.75rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  font-size: 1.15rem;
  background: rgba(8, 16, 28, .78);
  color: var(--ink);
  border: 1px solid var(--line);
}
.map-marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 3;
}
.map-marks span {
  position: absolute;
  transform: translate(-50%, -52%);
  font-size: clamp(1.2rem, 2.5vw, 1.75rem);
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(8, 16, 28, .7));
  user-select: none;
}

.hint {
  position: absolute;
  z-index: 4;
  left: max(1rem, var(--sal));
  bottom: max(1rem, var(--sab));
  padding: .45rem .7rem;
  background: rgba(8, 16, 28, .72);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: .78rem;
  font-weight: 700;
  color: var(--muted);
  pointer-events: none;
}
.hint[hidden] { display: none; }

.tooltip {
  position: absolute;
  z-index: 4;
  padding: .4rem .65rem;
  background: #11161e;
  border: 2px solid var(--yellow);
  border-radius: 8px;
  font-weight: 800;
  font-size: .85rem;
  pointer-events: none;
  transform: translate(12px, 12px);
  box-shadow: var(--shadow);
  display: none;
}
.tooltip small {
  display: block;
  font-size: .7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.tooltip small.grapes {
  text-transform: none;
  letter-spacing: .02em;
}
.tooltip .tips-icons {
  display: inline;
  margin-left: .4rem;
  font-size: 1.05rem;
  letter-spacing: .12em;
  line-height: 1;
  text-transform: none;
  vertical-align: -0.05em;
}

aside {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.card {
  padding: 1rem 1.1rem 1.05rem;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}
.card .kicker {
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--yellow);
  margin-bottom: .25rem;
}
.card h2 {
  font-family: var(--display);
  font-size: 1.45rem;
  line-height: 1.15;
  margin-bottom: .55rem;
}
.card h2 .title-sep {
  font-weight: 500;
  opacity: .4;
}
.card h2 .title-region {
  font-weight: 700;
}
.card h2 button.title-region {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  letter-spacing: inherit;
  text-transform: inherit;
}
.card h2 .title-region.is-zoom {
  cursor: zoom-in;
  text-decoration: underline;
  text-decoration-color: rgba(242, 205, 55, .55);
  text-underline-offset: .12em;
}
.card h2 .title-icons {
  font-family: inherit;
  font-size: 1.05rem;
  letter-spacing: .12em;
  line-height: 1;
  font-weight: 400;
  margin-left: .4rem;
  white-space: nowrap;
}
.pills { display: flex; flex-wrap: wrap; gap: .35rem; }
.sub-pills { margin-top: .4rem; }
.terroir { margin-top: .55rem; }
.pill.sub {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  text-transform: none;
  letter-spacing: .02em;
}
.pill.soil,
.pill.climate {
  text-transform: none;
  letter-spacing: .02em;
  font-weight: 700;
}
.legend.grapes {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  align-items: center;
}
.legend.grapes button {
  text-transform: none;
  letter-spacing: .02em;
  font-weight: 700;
}
.pill.region {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  text-transform: none;
  letter-spacing: .02em;
}
.pill {
  font: 800 .72rem var(--sans);
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: .28rem .55rem;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  color: inherit;
  border: 1px solid transparent;
  cursor: pointer;
}
button.pill:hover,
.pill.active {
  background: rgba(255,255,255,.16);
  border-color: rgba(242, 205, 55, .45);
}
.pill.grape {
  text-transform: none;
  letter-spacing: .02em;
  font-weight: 700;
}
.pill.grape.red {
  color: #e23b2c;
  background: rgba(255,255,255,.08);
}
.pill.grape.gris {
  color: #e56aa8;
  background: rgba(255,255,255,.08);
}
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  margin-top: .8rem;
}
.stats[hidden] { display: none; }
.highlight {
  margin-top: .7rem;
  padding: .65rem .75rem .7rem;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.highlight .snap {
  display: block;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--yellow);
  margin-bottom: .35rem;
}
.highlight p {
  font-size: .86rem;
  line-height: 1.45;
  font-weight: 600;
  max-height: 18rem;
  overflow-y: auto;
}
.stat {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .55rem .7rem;
}
.stat b {
  display: block;
  font-size: 1.15rem;
  font-family: var(--display);
}
.stat span {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.legend {
  padding: .75rem 1.1rem;
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  border-bottom: 1px solid var(--line);
}
.legend[hidden] { display: none; }
.legend button {
  display: flex;
  align-items: center;
  gap: .4rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: 800 .72rem var(--sans);
  padding: .28rem .5rem;
  border-radius: 999px;
  cursor: pointer;
}
.legend button.active {
  border-color: var(--yellow);
  background: rgba(242, 205, 55, .12);
}
.legend .note {
  display: flex;
  align-items: center;
  gap: .4rem;
  border: 1px dashed var(--line);
  color: var(--muted);
  font: 800 .72rem var(--sans);
  padding: .28rem .5rem;
  border-radius: 999px;
  cursor: default;
}
.style-legend {
  flex-shrink: 0;
  padding: .45rem .75rem .5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .35rem;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.style-legend[hidden] { display: none; }
.style-legend .key {
  display: flex;
  align-items: center;
  gap: .35rem;
  border: 1px solid var(--line);
  background: transparent;
  font: 800 .72rem var(--sans);
  padding: .26rem .48rem;
  border-radius: 999px;
  color: var(--ink);
  cursor: pointer;
}
.style-legend .key.active {
  border-color: var(--yellow);
  background: rgba(242, 205, 55, .12);
}
.style-legend .key i {
  font-style: normal;
  font-size: .95rem;
  line-height: 1;
}
.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  box-shadow: 0 1px 0 rgba(0,0,0,.4);
}

.list {
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  padding: .4rem .55rem calc(1rem + var(--sab));
}
.list button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 700 .92rem var(--sans);
  padding: .45rem .55rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: .5rem;
}
.list button:hover,
.list button.sel {
  background: rgba(255,255,255,.06);
}
.list button.sel { outline: 1px solid var(--yellow); }
.list button em {
  font-style: normal;
  color: var(--muted);
  font-size: .75rem;
}
.list .winery {
  width: 100%;
  text-align: left;
  color: var(--ink);
  font: 700 .92rem var(--sans);
  padding: .45rem .55rem;
  border-radius: 8px;
  cursor: default;
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  box-sizing: border-box;
}
.list .winery em {
  font-style: normal;
  color: var(--muted);
  font-size: .75rem;
}
.group {
  margin: .55rem .55rem .2rem;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
@media (max-width: 860px) {
  .sheet-btn { display: inline-flex; align-items: center; justify-content: center; }
  .map-zoom { display: flex; }
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(12rem, 1fr) minmax(11rem, 34dvh);
  }
  .app.sheet-list .stage {
    grid-template-rows: minmax(7rem, 28vh) minmax(0, 1fr);
  }
  aside {
    border-left: 0;
    border-top: 1px solid var(--line);
    min-height: 0;
  }
  header {
    flex-wrap: wrap;
    gap: .5rem;
    padding: calc(.5rem + var(--sat)) calc(.75rem + var(--sar)) .5rem calc(.75rem + var(--sal));
  }
  header h1 { font-size: 1rem; }
  header h1 span { display: none; }
  .brick-mark { width: 34px; height: 28px; }
  .toolbar { margin-left: 0; width: 100%; justify-content: flex-start; }
  .search { flex: 1 1 12rem; }
  .search input {
    width: 100%;
    font-size: 16px;
    min-height: 44px;
  }
  .seg button,
  .icon-btn {
    min-height: 44px;
    min-width: 44px;
    padding: .55rem .7rem;
  }
  .list button {
    min-height: 44px;
    padding: .7rem .65rem;
  }
  .pill,
  .legend button,
  .style-legend .key {
    padding: .42rem .65rem;
    min-height: 36px;
  }
  .style-legend {
    padding-bottom: calc(.5rem + var(--sab));
  }
  .app.sheet-list .style-legend { display: none; }
  .hint { display: none; }
}

@media (max-width: 860px) and (max-height: 500px) {
  .stage { grid-template-rows: minmax(0, 1fr) minmax(8rem, 38dvh); }
  .app.sheet-list .stage { grid-template-rows: minmax(5rem, 22vh) minmax(0, 1fr); }
  .viewport { min-height: 8rem; }
}

@media (pointer: coarse) {
  .search input { font-size: 16px; }
  .list button { min-height: 44px; }
  .map-zoom { display: flex; }
  .hint { display: none; }
}
