:root {
  --sky: #74acdf;
  --sky-strong: #4a98d2;
  --sun: #f6b40e;
  --malbec: #4c1635;
  --plum: #6f1d46;
  --plum-soft: #f5e7ef;
  --ink: #17131a;
  --muted: #6f6670;
  --line: #e7dce4;
  --paper: #fffafc;
  --white: #ffffff;
  --shadow: 0 18px 50px rgba(42, 18, 33, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(116, 172, 223, 0.18), rgba(255, 255, 255, 0) 280px),
    radial-gradient(circle at 100% 0%, rgba(246, 180, 14, 0.16), transparent 260px),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(116, 172, 223, 0.55);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.flag {
  width: 78px;
  height: 52px;
  flex: 0 0 auto;
  border: 1px solid rgba(23, 19, 26, 0.12);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(23, 19, 26, 0.12);
}

.brand-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--plum);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--malbec);
  font-size: clamp(1.45rem, 4.8vw, 2.35rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand-copy h2,
.brand-copy h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand-copy h2 {
  color: var(--plum);
  font-size: clamp(1.05rem, 3.2vw, 1.52rem);
  line-height: 1.02;
  font-weight: 850;
}

.brand-copy h3 {
  margin-top: 3px;
  color: var(--muted);
  font-size: clamp(0.85rem, 2.3vw, 1rem);
  line-height: 1.12;
  font-weight: 780;
}

.top-actions,
.share-actions {
  display: flex;
  gap: 8px;
}

.top-actions {
  align-items: center;
}

.malbec-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 8px;
  box-shadow: 0 9px 22px rgba(76, 22, 53, 0.14);
}

.icon-button,
.view-button,
.share-actions button,
.export-actions button,
.danger-button,
.add-note-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  color: var(--white);
  background: var(--malbec);
  font-weight: 800;
  box-shadow: 0 9px 22px rgba(76, 22, 53, 0.16);
}

.icon-button {
  width: 48px;
  padding: 0;
}

.view-button.is-active {
  color: var(--malbec);
  background: var(--sun);
}

.main-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  grid-template-areas:
    "event event"
    "share share"
    "rail workspace";
  gap: 16px;
}

.event-strip,
.share-panel,
.workspace,
.wine-rail {
  border: 1px solid rgba(76, 22, 53, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.event-strip {
  grid-area: event;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 0.8fr) auto minmax(210px, 0.75fr);
  gap: 14px;
  align-items: end;
  padding: 14px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span,
.stepper span,
.scale-label,
.note-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

input,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--white);
}

input {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 132px;
  resize: vertical;
  padding: 12px;
}

.stepper {
  display: grid;
  grid-template-columns: 42px 92px 42px;
  gap: 6px;
  align-items: end;
}

.stepper label {
  display: grid;
  gap: 6px;
}

.stepper input {
  text-align: center;
  font-weight: 900;
}

.stepper button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: var(--white);
  background: var(--plum);
  font-size: 1.35rem;
  font-weight: 900;
}

.progress-block {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--malbec);
  font-size: 0.9rem;
  font-weight: 900;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 6px;
  background: #ede3e9;
}

.progress-track div {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--sky), var(--sun), var(--plum));
  transition: width 180ms ease;
}

.share-panel {
  grid-area: share;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  padding: 14px;
}

.share-panel[hidden] {
  display: none;
}

.qr-wrap {
  display: grid;
  place-items: center;
  width: 206px;
  height: 206px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(116, 172, 223, 0.18), rgba(255, 255, 255, 0.76)),
    var(--white);
  border: 1px solid var(--line);
}

#qrCanvas {
  width: 180px;
  height: 180px;
  image-rendering: pixelated;
}

.share-fields {
  display: grid;
  gap: 10px;
}

.share-actions button:nth-child(2) {
  color: var(--malbec);
  background: var(--sun);
}

.status-line {
  min-height: 1.2em;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.wine-rail {
  grid-area: rail;
  align-self: start;
  display: grid;
  gap: 8px;
  padding: 12px;
}

.wine-tab {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  color: var(--ink);
  background: var(--white);
  text-align: left;
}

.wine-tab.is-active {
  border-color: var(--sky-strong);
  background: rgba(116, 172, 223, 0.16);
  box-shadow: inset 4px 0 0 var(--sky-strong);
}

.wine-tab.is-active .wine-number {
  background: var(--sky-strong);
}

.wine-number {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: var(--white);
  background: var(--malbec);
  font-weight: 950;
}

.wine-tab-text {
  min-width: 0;
}

.wine-title {
  display: block;
  color: var(--malbec);
  font-weight: 900;
}

.wine-meta {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wine-status {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  color: var(--malbec);
  background: rgba(246, 180, 14, 0.22);
  font-size: 0.78rem;
  font-weight: 950;
}

.workspace {
  grid-area: workspace;
  min-width: 0;
  overflow: hidden;
}

.tasting-view,
.summary-view {
  padding: 18px;
}

.wine-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.wine-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.wine-heading .wine-number {
  width: 52px;
  height: 52px;
  font-size: 1.2rem;
}

.wine-heading h2,
.summary-view h2 {
  margin: 0;
  color: var(--malbec);
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  letter-spacing: 0;
}

.wine-heading p {
  margin: 2px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.nav-arrows {
  display: flex;
  gap: 8px;
}

.nav-arrows button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: var(--white);
  background: var(--plum);
  font-size: 1.25rem;
  font-weight: 900;
}

.nav-arrows button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.rating-row {
  display: grid;
  gap: 8px;
  margin: 18px 0;
}

.stars {
  display: grid;
  grid-template-columns: repeat(6, minmax(42px, 1fr));
  gap: 8px;
}

.stars button {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--malbec);
  background: var(--white);
  font-size: 1.35rem;
  font-weight: 950;
}

.stars button.is-selected {
  border-color: var(--sun);
  background: #fff5d7;
  box-shadow: inset 0 -4px 0 var(--sun);
}

.stars button:first-child {
  font-size: 0.95rem;
}

.scale-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 18px;
}

.scale-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.78);
}

.scale-card input[type="range"] {
  height: auto;
  accent-color: var(--sky-strong);
  padding: 0;
}

.scale-value {
  color: var(--malbec);
  font-weight: 950;
}

.tag-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 18px;
}

.tag-bank button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  color: var(--ink);
  background: var(--white);
  font-weight: 800;
}

.tag-bank button.is-selected {
  border-color: var(--plum);
  color: var(--white);
  background: var(--plum);
}

.note-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(220px, 0.7fr);
  gap: 12px;
}

.note-panel {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.guess-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
}

.buy-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.buy-options button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--white);
  font-weight: 850;
}

.buy-options button.is-selected {
  border-color: var(--malbec);
  color: var(--white);
  background: var(--malbec);
}

.summary-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.summary-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.export-actions button:nth-child(2) {
  color: var(--malbec);
  background: var(--sun);
}

.danger-button {
  background: #8f1d2c;
}

.ranking-list {
  display: grid;
  gap: 10px;
}

.ranking-item {
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--white);
}

.rank-number {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: var(--white);
  background: var(--malbec);
  font-weight: 950;
}

.ranking-item h3 {
  margin: 0;
  color: var(--malbec);
  font-size: 1rem;
}

.ranking-item p {
  margin: 3px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rating-pill {
  min-width: 72px;
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--malbec);
  background: #fff5d7;
  font-weight: 950;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 10;
  max-width: min(92vw, 420px);
  transform: translate(-50%, 16px);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--white);
  background: var(--malbec);
  box-shadow: var(--shadow);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 860px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .flag {
    width: 64px;
    height: 43px;
  }

  .main-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "event"
      "share"
      "rail"
      "workspace";
  }

  .event-strip {
    grid-template-columns: 1fr 1fr;
  }

  .progress-block {
    grid-column: 1 / -1;
  }

  .wine-rail {
    display: flex;
    overflow-x: auto;
    padding: 10px;
    scroll-snap-type: x proximity;
  }

  .wine-tab {
    flex: 0 0 162px;
    scroll-snap-align: start;
  }

  .scale-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .note-grid,
  .share-panel {
    grid-template-columns: 1fr;
  }

  .qr-wrap {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: flex-start;
    gap: 10px;
  }

  .brand {
    gap: 9px;
  }

  .flag {
    width: 56px;
    height: 38px;
  }

  .malbec-mark {
    width: 42px;
    height: 42px;
  }

  .top-actions {
    flex-direction: column;
  }

  .event-strip {
    grid-template-columns: 1fr;
  }

  .stepper {
    grid-template-columns: 42px minmax(92px, 1fr) 42px;
  }

  .wine-header,
  .summary-head {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-arrows {
    justify-content: space-between;
  }

  .nav-arrows button {
    width: calc(50% - 4px);
  }

  .stars {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .scale-grid {
    grid-template-columns: 1fr;
  }

  .ranking-item {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .rating-pill {
    grid-column: 1 / -1;
    width: 100%;
  }
}
