:root {
  color-scheme: light;
  --bg: #f7f3ed;
  --surface: #fffdfa;
  --surface-strong: #ffffff;
  --ink: #241c19;
  --muted: #7b6f68;
  --line: #e4d9cd;
  --burgundy: #5e1224;
  --burgundy-2: #7c1d34;
  --gold: #b18a45;
  --green: #2f7558;
  --shadow: 0 18px 50px rgba(64, 35, 21, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(94, 18, 36, 0.08), transparent 260px),
    var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  position: relative;
  width: min(100%, 430px);
  min-height: 100svh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(84px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0 12px;
  background: linear-gradient(180deg, var(--bg) 78%, rgba(247, 243, 237, 0));
}

.session-label,
.section-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar h1,
.section-heading h2,
.cellar-panel h2 {
  margin: 2px 0 0;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.08;
  letter-spacing: 0;
}

.invite-button,
.icon-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--burgundy);
  box-shadow: 0 8px 22px rgba(94, 18, 36, 0.08);
}

.invite-button {
  flex: 0 0 auto;
  max-width: 178px;
  padding: 10px 11px;
  font-size: 12px;
  font-weight: 800;
}

.invite-button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main {
  display: grid;
  gap: 14px;
}

.scan-panel,
.synthesis-panel,
.notes-section,
.cellar-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.9);
  box-shadow: var(--shadow);
}

.scan-panel {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 14px;
  padding: 12px;
}

.scan-image-wrap {
  position: relative;
  min-height: 214px;
  overflow: hidden;
  border-radius: 8px;
  background: #221713;
}

.scan-image-wrap img {
  width: 100%;
  height: 100%;
  min-height: 214px;
  object-fit: cover;
}

.scan-status {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(47, 117, 88, 0.16);
}

.wine-summary {
  min-width: 0;
}

.summary-topline,
.ai-note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.confidence,
.vintage,
.ai-note-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
}

.confidence {
  background: rgba(47, 117, 88, 0.12);
  color: var(--green);
}

.vintage,
.ai-note-meta span:last-child {
  background: rgba(177, 138, 69, 0.14);
  color: #765922;
}

.wine-summary h2 {
  margin: 12px 0 6px;
  font-size: 22px;
  line-height: 1.04;
  letter-spacing: 0;
}

.wine-summary p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.metadata-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 14px;
}

.metadata-grid div {
  border-left: 3px solid rgba(94, 18, 36, 0.18);
  padding-left: 8px;
}

.metadata-grid span,
label,
legend {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metadata-grid strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
}

.camera-button {
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  border-radius: 8px;
  background: var(--burgundy);
  color: #fffaf3;
  font-size: 14px;
  font-weight: 850;
  box-shadow: 0 14px 30px rgba(94, 18, 36, 0.22);
}

#photoInput {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.synthesis-panel,
.notes-section,
.cellar-panel {
  padding: 14px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
}

.ai-note {
  border-radius: 8px;
  padding: 13px;
  background:
    linear-gradient(145deg, rgba(94, 18, 36, 0.08), rgba(177, 138, 69, 0.08)),
    #fff8f1;
}

.ai-note-meta {
  margin-bottom: 10px;
}

.ai-note-meta span:first-child {
  background: rgba(94, 18, 36, 0.1);
  color: var(--burgundy);
}

.ai-note p {
  margin: 0;
  color: #33241d;
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.note-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 124px;
  gap: 10px;
}

input,
textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  outline: none;
}

input:focus,
textarea:focus,
button:focus-visible,
.camera-button:focus-visible {
  outline: 3px solid rgba(177, 138, 69, 0.35);
  outline-offset: 2px;
}

input {
  min-height: 42px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 10px 11px;
  line-height: 1.45;
}

input[type="range"] {
  height: 28px;
  padding: 0;
  accent-color: var(--burgundy);
}

output {
  float: right;
  color: var(--burgundy);
  font-size: 12px;
  font-weight: 900;
}

fieldset {
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chip.selected {
  border-color: rgba(94, 18, 36, 0.32);
  background: rgba(94, 18, 36, 0.1);
  color: var(--burgundy);
}

.primary-button,
.secondary-button {
  min-height: 46px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 900;
}

.primary-button {
  width: 100%;
  background: var(--burgundy);
  color: #fffaf3;
  box-shadow: 0 14px 30px rgba(94, 18, 36, 0.18);
}

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

.note-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: var(--surface-strong);
}

.avatar,
.avatar-stack span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--burgundy);
  color: #fffaf3;
  font-weight: 900;
}

.avatar {
  width: 40px;
  height: 40px;
  font-size: 14px;
}

.note-body {
  min-width: 0;
}

.note-topline {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.note-topline h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.note-topline span {
  color: var(--burgundy);
  font-size: 12px;
  font-weight: 900;
}

.aroma-line,
.note-copy {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.note-copy {
  color: #43342e;
}

.avatar-stack {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  min-width: 98px;
}

.avatar-stack span {
  width: 30px;
  height: 30px;
  margin-left: -8px;
  border: 2px solid var(--surface);
  font-size: 11px;
}

.cellar-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.secondary-button {
  flex: 0 0 auto;
  padding: 0 12px;
}

.bottom-nav {
  position: fixed;
  right: max(16px, calc((100vw - 430px) / 2 + 16px));
  bottom: env(safe-area-inset-bottom);
  left: max(16px, calc((100vw - 430px) / 2 + 16px));
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  border: 1px solid rgba(228, 217, 205, 0.88);
  border-radius: 8px 8px 0 0;
  padding: 7px 6px 8px;
  background: rgba(255, 253, 250, 0.96);
  box-shadow: 0 -18px 42px rgba(64, 35, 21, 0.16);
  backdrop-filter: blur(16px);
}

.nav-item {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-width: 0;
  min-height: 54px;
  border-radius: 8px;
  padding: 6px 4px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.nav-item svg {
  width: 21px;
  height: 21px;
}

.nav-item.active {
  background: rgba(94, 18, 36, 0.1);
  color: var(--burgundy);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(82px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 40;
  max-width: 398px;
  margin: 0 auto;
  border-radius: 8px;
  padding: 12px 14px;
  background: #241c19;
  color: #fffaf3;
  font-size: 13px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 760px) {
  .app-shell {
    width: min(100%, 920px);
  }

  main {
    grid-template-columns: 1.1fr 0.9fr;
    align-items: start;
  }

  .scan-panel {
    grid-template-columns: 176px minmax(0, 1fr);
  }

  .synthesis-panel,
  .notes-section {
    grid-column: auto;
  }

  .cellar-panel {
    grid-column: 1 / -1;
  }
}

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

  .scan-panel {
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 10px;
  }

  .wine-summary h2 {
    font-size: 19px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .topbar h1 {
    font-size: 21px;
  }

  .invite-button {
    max-width: 138px;
    padding-inline: 9px;
    font-size: 11px;
  }

  .scan-panel {
    grid-template-columns: 124px minmax(0, 1fr);
  }

  .scan-image-wrap,
  .scan-image-wrap img {
    min-height: 202px;
  }

  .wine-summary h2 {
    font-size: 20px;
  }

  .metadata-grid {
    gap: 6px;
  }

  .synthesis-panel,
  .notes-section,
  .cellar-panel {
    overflow: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
