:root {
  color-scheme: light;
  font: 100%/1.35 system-ui, sans-serif;
  --paper: #fffaf7;
  --ink: #391e29;
  --muted: #6f4554;
  --wine: #62273d;
  --wine-dark: #4d2130;
  --rose: #f4d2d8;
  --line: #dfc2c9;
  --tint: #efdee1;
  --radius: 14px;
  --serif: Georgia, "Times New Roman", serif;
  --gutter: max(1.35rem, env(safe-area-inset-left), env(safe-area-inset-right));
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--tint);
  color: var(--ink);
  display: grid;
  place-items: center;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  transition: background-color 400ms ease;
  -webkit-tap-highlight-color: transparent;
}

body[data-light="amber"] { --tint: #f6e2c9; }
body[data-light="pink"] { --tint: #f6d3de; }
body[data-light="lilac"] { --tint: #e3dbf4; }
body[data-light="off"] { --tint: #d9cfd3; }

.app {
  width: min(100%, 29rem);
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--paper);
  view-transition-name: app;
}

/* Header: back, progress, step count on one row */
.bar {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 4.5rem;
  align-items: center;
  gap: 0.75rem;
  padding: max(0.5rem, env(safe-area-inset-top)) var(--gutter) 0.25rem calc(var(--gutter) - 0.6rem);
  view-transition-name: bar;
}

.bar[hidden] { display: none; }

.back {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--wine);
  font: 400 2.1rem/1 var(--serif);
  cursor: pointer;
  touch-action: manipulation;
}

.back span { margin-top: -0.2rem; }
.back:active { background: var(--rose); }

.progress {
  height: 6px;
  border-radius: 3px;
  background: #f1dfe3;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: var(--wine);
  transform-origin: left;
  transform: scaleX(var(--done, 0));
  transition: transform 300ms ease;
}

.count {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#view {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  outline: none;
}

#view > section {
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  overscroll-behavior: contain;
}

#view > section::-webkit-scrollbar { display: none; }
#view > section:only-child { grid-row: 1 / -1; }

h1 { outline: none; }

/* Welcome */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: max(2rem, env(safe-area-inset-top)) var(--gutter) max(2rem, env(safe-area-inset-bottom));
  color: #fff2ec;
  background: var(--wine-dark);
  text-align: center;
}

.welcome h1 {
  margin: 0.5rem 0 0;
  font: 400 clamp(3rem, 15vw, 4.4rem)/1 var(--serif);
  letter-spacing: -0.07em;
  white-space: nowrap;
}

.welcome em { color: #f6b8c8; font-weight: 400; }
.welcome p { margin: 0 0 1.5rem; color: #f7d6d9; font-size: 1rem; }
.welcome .primary { width: min(100%, 20rem); background: #f6b8c8; color: var(--wine-dark); }
.welcome .primary span { color: var(--wine); }
.welcome .primary:active { background: #eea3b7; }

.seal {
  position: relative;
  display: grid;
  place-items: center;
  width: 6.2rem;
  aspect-ratio: 1;
  border: 1px solid #b77488;
  border-radius: 50%;
  color: #f3b6c5;
  transform: rotate(-12deg);
}

.seal::before {
  content: "";
  position: absolute;
  inset: 0.3rem;
  border: 1px solid #b77488;
  border-radius: inherit;
}

.seal span {
  position: relative;
  width: 1.7rem;
  height: 1.7rem;
  margin-top: 0.3rem;
  border-radius: 0.12rem;
  background: currentColor;
  transform: rotate(-45deg);
}

.seal span::before, .seal span::after {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  border-radius: 50%;
}

.seal span::before { transform: translateY(-48%); }
.seal span::after { transform: translateX(48%); }

/* Steps */
.step, .review, .booked {
  padding: 1.25rem var(--gutter) max(1.5rem, env(safe-area-inset-bottom));
}

.step h1, .review h1, .booked h1 {
  margin: 0 0 1.25rem;
  font: 400 clamp(2.1rem, 9vw, 2.6rem)/1.05 var(--serif);
  letter-spacing: -0.04em;
}

.choices { display: grid; gap: 0.65rem; }

.choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  min-height: 64px;
  padding: 0 3.2rem 0 1.15rem;
  border: 1px solid #c79aa7;
  border-radius: var(--radius);
  background: #fffdfb;
  color: var(--ink);
  font: 600 1.08rem/1.2 system-ui, sans-serif;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 140ms ease, border-color 140ms ease, transform 120ms ease;
}

.count-5 .choice { min-height: 56px; }
.choice-label { white-space: nowrap; }

.choice::after {
  content: "";
  position: absolute;
  right: 1.1rem;
  top: 50%;
  width: 1.4rem;
  height: 1.4rem;
  margin-top: -0.7rem;
  border: 1.5px solid #c79aa7;
  border-radius: 50%;
}

.choice[aria-pressed="true"] {
  border-color: var(--wine);
  background: var(--rose);
  color: #48172c;
  box-shadow: inset 0 0 0 1px var(--wine);
}

.choice[aria-pressed="true"]::after {
  border-color: var(--wine);
  background: var(--wine);
  box-shadow: inset 0 0 0 4px var(--rose);
}

.choice:active { transform: scale(0.985); background: #f7dfe4; }

.swatch::before {
  content: "";
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--swatch);
  border: 1px solid var(--swatch-edge);
}

.amber { --swatch: #f8c075; --swatch-edge: #8f532d; }
.pink { --swatch: #ed9db6; --swatch-edge: #994362; }
.lilac { --swatch: #c7b3ef; --swatch-edge: #735893; }
.off { --swatch: #4b3f45; --swatch-edge: #211820; }

/* Review */
.rows {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdfb;
  overflow: hidden;
}

.row {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  min-height: 56px;
  padding: 0 1rem;
  color: var(--ink);
  text-decoration: none;
  touch-action: manipulation;
}

.row + .row { border-top: 1px solid var(--line); }
.row:active { background: #fbeef0; }
.row-label { color: var(--muted); font-size: 0.86rem; white-space: nowrap; }
.row-value { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-edit { color: var(--wine); font: 400 1.6rem/1 var(--serif); }

/* Footer actions */
.actions {
  display: grid;
  gap: 0.6rem;
  padding: 0.8rem var(--gutter) max(0.9rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #f9eaeb;
}

.primary, .secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  min-height: 52px;
  padding: 0 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: 650 1rem/1.2 system-ui, sans-serif;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}

.primary { background: var(--wine); color: #fff9f6; }
.primary span { color: #f6b8c8; }
.primary:active { background: #431b2c; }
.primary:disabled { opacity: 0.8; cursor: default; }

.secondary-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.secondary { min-height: 48px; background: #fffdfb; border-color: #c79aa7; color: var(--wine); }
.secondary:active { background: var(--rose); }

.status { margin: 0; min-height: 1.2rem; color: var(--muted); font-size: 0.8rem; text-align: center; }

/* Booked */
.booked { display: flex; flex-direction: column; justify-content: center; }
.booked h1 { text-align: center; }

.ticket {
  position: relative;
  padding: 1.5rem 1.25rem 1.25rem;
  border-radius: var(--radius);
  background: var(--wine-dark);
  color: #fff2ec;
  text-align: center;
}

.ticket p { margin: 0; }
.ticket-time { font: 400 clamp(2.8rem, 14vw, 3.6rem)/1 var(--serif); letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.ticket-main { margin-top: 0.5rem !important; color: #f6b8c8; font-weight: 650; }

.ticket dl {
  display: grid;
  gap: 0.5rem;
  margin: 1.25rem 0 0;
  padding-top: 1.1rem;
  border-top: 1px dashed #9a5a70;
}

.ticket dl div { display: flex; justify-content: space-between; gap: 1rem; }
.ticket dt { color: #e6bcc6; }
.ticket dd { margin: 0; font-weight: 650; white-space: nowrap; }

.noscript { padding: 2rem; text-align: center; }

/* Fallback copy dialog */
.receipt {
  width: min(25rem, calc(100% - 2.5rem));
  padding: 1rem 1.2rem 1.2rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.receipt::backdrop { background: rgb(57 30 41 / 64%); }
.receipt h2 { margin: 0.2rem 3rem 0.8rem 0; font: 500 1.8rem/1.08 var(--serif); }
.receipt label { display: block; margin-block-end: 0.4rem; }
.receipt textarea { width: 100%; min-height: 9rem; padding: 0.7rem; resize: vertical; border: 1px solid var(--line); border-radius: var(--radius); font: inherit; }
.close { position: absolute; inset: 0.55rem 0.55rem auto auto; width: 44px; height: 44px; border: 0; border-radius: var(--radius); background: #f9eaeb; color: var(--wine); font: 1.7rem/1 system-ui; cursor: pointer; }

:focus-visible { outline: 2px solid #7b3151; outline-offset: 2px; }
.welcome :focus-visible { outline-color: #f6b8c8; }

@media (hover: hover) {
  .choice:hover:not([aria-pressed="true"]) { border-color: #a86a80; background: #fbeef0; }
  .row:hover { background: #fbeef0; }
  .primary:hover:not(:disabled) { background: #512136; }
  .welcome .primary:hover { background: #f2aabd; }
  .secondary:hover { background: #fbeef0; }
  .back:hover { background: #fbeef0; }
}

@media (min-width: 34rem) and (min-height: 44rem) {
  .app { height: min(calc(100% - 3rem), 52rem); border: 1px solid #d2a5b1; border-radius: 1.25rem; overflow: hidden; }
}

@media (max-height: 40rem) {
  .step, .review, .booked { padding-top: 0.6rem; }
  .step h1, .review h1, .booked h1 { margin-bottom: 0.75rem; font-size: 1.9rem; }
  .choice { min-height: 50px; }
  .count-5 .choice { min-height: 46px; }
  .choices { gap: 0.45rem; }
  .row { min-height: 46px; }
  .welcome .seal { width: 4.4rem; }
  .welcome p { margin-bottom: 0.75rem; }
  .ticket { padding-block: 1rem; }
}

/* Page transitions */
::view-transition-old(app), ::view-transition-new(app) { animation-duration: 240ms; animation-timing-function: cubic-bezier(0.2, 0.7, 0.2, 1); }
::view-transition-old(app) { animation-name: slide-out; }
::view-transition-new(app) { animation-name: slide-in; }
html[data-direction="back"]::view-transition-old(app) { animation-name: slide-out-back; }
html[data-direction="back"]::view-transition-new(app) { animation-name: slide-in-back; }
::view-transition-group(bar) { animation-duration: 240ms; }

@keyframes slide-out { to { opacity: 0; transform: translateX(-24px); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes slide-out-back { to { opacity: 0; transform: translateX(24px); } }
@keyframes slide-in-back { from { opacity: 0; transform: translateX(-24px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

@media (forced-colors: active) {
  .choice[aria-pressed="true"] { border: 3px solid Highlight; }
}
