:root {
  --welcome-max: 620px;
  --welcome-wide: 720px;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: var(--lr-font-ui), system-ui, sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: var(--lr-grain);
  opacity: var(--lr-grain-alpha);
}

/* Hide the start card from JS-enabled new visitors until the tour switches to it. */
html.js[data-visit="new"] .card[data-step="start"]:not(.active) {
  display: none !important;
}

.welcome {
  position: relative;
  z-index: 1;
  width: 100%;
  /* Locked to the phone viewport (#174): the page itself never scrolls; the stage flexes and the card scrolls
     internally if a step is ever taller than the space left under the dots and footer. */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--lr-space-4) var(--lr-space-4) calc(var(--lr-space-4) + env(safe-area-inset-bottom));
  overflow: hidden;
}

.wash {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(50rem 34rem at 12% -10%, rgba(194, 58, 23, 0.14), transparent 65%),
    radial-gradient(44rem 30rem at 105% 110%, rgba(212, 160, 90, 0.16), transparent 65%);
}

.watermark {
  position: fixed;
  right: -8rem;
  bottom: -10rem;
  width: 34rem;
  height: 34rem;
  z-index: 0;
  pointer-events: none;
  opacity: 0.06;
  transform: rotate(-12deg);
}

.stage {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--welcome-max);
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--lr-space-6) 0;
}

/* The card stack: two peeking cards behind the active one. */
.stage::before,
.stage::after {
  content: '';
  position: absolute;
  inset: var(--lr-space-6) 0 auto 0;
  height: calc(100% - var(--lr-space-6) * 2);
  max-height: calc(100dvh - var(--lr-space-6) * 2);
  background: var(--lr-card);
  border: 1px solid var(--lr-rule);
  border-radius: var(--lr-radius-card);
  box-shadow: var(--lr-shadow-card);
  z-index: -1;
  pointer-events: none;
}

.stage::before {
  transform: rotate(-1.6deg) translateY(6px);
}

.stage::after {
  transform: rotate(1.1deg) translateY(10px);
}

.card {
  position: relative;
  width: 100%;
  /* Fill the stage but never push the dots or footer off screen (#174); overflow stays inside the card. */
  min-height: 0;
  overflow-y: auto;
  background: var(--lr-card);
  border: 1px solid var(--lr-rule);
  border-radius: var(--lr-radius-card);
  box-shadow: var(--lr-shadow-card);
  padding: var(--lr-space-6) var(--lr-space-5) var(--lr-space-5);
  display: flex;
  flex-direction: column;
  gap: var(--lr-space-4);
}

.card[hidden] {
  display: none !important;
}

/* The heading is only a focus target for screen readers, not a control. */
.card :is(h1, h2)[tabindex="-1"]:focus {
  outline: none;
}

.card-tab {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--lr-red);
}

.eyebrow {
  font-size: var(--lr-text-caption);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--lr-ink-2);
  margin: 0;
}

.welcome-brand {
  display: flex;
  align-items: center;
  gap: var(--lr-space-3);
}

#welcome-logo-canvas {
  display: block;
  width: 48px;
  height: 48px;
}

.welcome-wordmark {
  font-family: var(--lr-font-display);
  font-weight: 800;
  font-size: var(--lr-text-state);
  letter-spacing: -0.03em;
  color: var(--lr-ink);
}

h1, h2 {
  font-family: var(--lr-font-display);
  font-weight: 800;
  line-height: 0.98;
  letter-spacing: -0.03em;
  color: var(--lr-ink);
  margin: 0;
}

h1 {
  font-size: var(--lr-text-hero-m);
  text-wrap: balance;
}

h2 {
  font-size: var(--lr-text-station-m);
}

.lede {
  font-size: var(--lr-text-body);
  line-height: 1.5;
  color: var(--lr-ink-2);
  margin: 0;
  max-width: 52ch;
}

.features {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--lr-space-4);
}

.features li {
  display: flex;
  gap: var(--lr-space-3);
  align-items: flex-start;
}

.feature-icon {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--lr-radius-card-m);
  background: rgba(194, 58, 23, 0.10);
  color: var(--lr-red);
}

.feature-icon svg {
  width: 22px;
  height: 22px;
}

.features h3 {
  font-size: var(--lr-text-ui);
  font-weight: 700;
  margin: 0 0 2px;
  color: var(--lr-ink);
}

.features p {
  font-size: var(--lr-text-meta);
  line-height: 1.5;
  color: var(--lr-ink-2);
  margin: 0;
}

.actions {
  display: flex;
  align-items: center;
  gap: var(--lr-space-3);
  flex-wrap: wrap;
  margin-top: auto;
}

.primary,
.button-secondary,
.signin-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--lr-btn-m);
  padding: 0 22px;
  border-radius: var(--lr-radius-pill);
  font: 600 var(--lr-text-ui) var(--lr-font-ui);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-touch-callout: none;
}

.primary,
.signin-button.primary {
  border: 0;
  background: var(--lr-red);
  color: var(--lr-on-red);
  box-shadow: var(--lr-shadow-press);
  transition: transform var(--lr-dur-press), box-shadow var(--lr-dur-press);
}

.primary:active,
.signin-button.primary:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--lr-red-deep);
}

.button-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--lr-rule-2);
}

.signin-form {
  display: flex;
  flex-direction: column;
  gap: var(--lr-space-3);
}

.signin-label {
  font-size: var(--lr-text-ui);
  font-weight: 500;
}

.signin-input {
  font-size: 16px;
  padding: var(--lr-space-3);
  border: 1px solid var(--lr-field-border);
  border-radius: var(--lr-radius-card-m);
  background: var(--lr-field);
  color: var(--text);
}

.signin-input::placeholder {
  color: var(--text-faint);
}

.signin-input:focus-visible {
  outline: 2px solid var(--lr-red);
  outline-offset: 2px;
}

.signin-error {
  font-size: var(--lr-text-ui);
  color: var(--lr-red);
  margin: 0;
}

.signin-hint {
  font-size: var(--lr-text-meta);
  color: var(--lr-ink-2);
  margin: 0;
}

/* The front page's stations (Post Radio #148): one link card per station, whole card tappable. */
.front-stations {
  display: flex;
  flex-direction: column;
  gap: var(--lr-space-3);
}

.front-stations[hidden] {
  display: none;
}

.front-stations h2 {
  font-size: var(--lr-text-ui);
  margin: 0;
}

.station-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: var(--lr-tap);
  justify-content: center;
  padding: var(--lr-space-2) var(--lr-space-3);
  background: var(--lr-field);
  border: 1px solid var(--lr-rule);
  border-radius: var(--lr-radius-media);
  text-decoration: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.station-card:hover {
  border-color: var(--lr-rule-3);
}

.station-name {
  font-size: var(--lr-text-ui);
  font-weight: 700;
  color: var(--lr-ink);
}

.station-now {
  font-size: var(--lr-text-caption);
  color: var(--lr-ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.station-listeners {
  font-size: var(--lr-text-caption);
  color: var(--lr-red);
}

.signed-in-panel {
  display: flex;
  flex-direction: column;
  gap: var(--lr-space-3);
}

.signed-in-panel .signed-in-handle {
  font-size: var(--lr-text-body);
  margin: 0;
  word-break: break-word;
}

.rejoin-last-room {
  max-width: 100%;
  gap: var(--lr-space-3);
}

.rejoin-show {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phaseline-wrap {
  width: 100%;
  height: 80px;
}

#welcome-phaseline {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.room-grid {
  display: flex;
  flex-direction: column;
  gap: var(--lr-space-4);
}

#welcome-demo {
  display: block;
}

.dots {
  position: relative;
  z-index: 1;
  flex: none;
  display: flex;
  justify-content: center;
  gap: calc(var(--lr-tap) - 8px);
  margin-top: var(--lr-space-4);
}

.dot {
  position: relative;
  width: 8px;
  height: 8px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--lr-rule-2);
  cursor: pointer;
  user-select: none;
  -webkit-touch-callout: none;
  transition: background var(--lr-dur-press), transform var(--lr-dur-press);
}

/* The visible dot stays 8px; the tap target is the full 44px hit size around it (#178). */
.dot::after {
  content: "";
  position: absolute;
  inset: calc((var(--lr-tap) - 8px) / -2);
}

.dot.active {
  background: var(--lr-red);
  transform: scale(1.35);
}

.welcome-footer {
  position: relative;
  z-index: 1;
  flex: none;
  margin-top: var(--lr-space-6);
  display: flex;
  gap: var(--lr-space-4);
  align-items: center;
  font-size: var(--lr-text-ui);
}

.welcome-footer a,
.welcome-footer .button-link {
  color: var(--text-muted);
  text-decoration: none;
  user-select: none;
  -webkit-touch-callout: none;
  background: none;
  border: none;
  /* 44px tap target (#178); the horizontal padding is given back as negative margin so spacing is unchanged. */
  display: inline-flex;
  align-items: center;
  min-height: var(--lr-tap);
  padding: 0 var(--lr-space-2);
  margin: 0 calc(-1 * var(--lr-space-2));
  font: inherit;
  cursor: pointer;
}

.welcome-footer a:hover,
.welcome-footer .button-link:hover {
  color: var(--text);
}

/* Entrance choreography */
.card.active {
  animation: card-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.reveal {
  opacity: 1;
}

.card.active .reveal {
  animation: rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(var(--i, 0) * 70ms + 80ms);
}

/* The initial card paints whole: heading, pitch and buttons all visible at first paint (#180). */
.card.no-enter,
.card.no-enter .reveal {
  animation: none !important;
}

.reveal[data-i="1"] { --i: 1; }
.reveal[data-i="2"] { --i: 2; }
.reveal[data-i="3"] { --i: 3; }
.reveal[data-i="4"] { --i: 4; }

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(10px) rotate(-0.5deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .card.active,
  .reveal,
  .card.active .reveal {
    animation: none !important;
  }
}

@media (min-width: 1024px) {
  .welcome {
    padding: var(--lr-space-8);
  }

  .stage {
    max-width: var(--welcome-wide);
    padding: var(--lr-space-8) 0;
  }

  .stage::before,
  .stage::after {
    inset: var(--lr-space-8) 0 auto 0;
    height: calc(100% - var(--lr-space-8) * 2);
  }

  .card {
    padding: var(--lr-space-8);
  }

  #welcome-logo-canvas {
    width: 64px;
    height: 64px;
  }

  h1 {
    font-size: var(--lr-text-hero);
  }

  h2 {
    font-size: var(--lr-text-station);
  }

  .room-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--lr-space-6);
    align-items: start;
  }
}

/* Example room card (rendered by app/views/welcome-demo.mjs) */
.demo-card {
  background: var(--lr-card);
  border: 1px solid var(--lr-rule);
  border-radius: var(--lr-radius-card);
  box-shadow: var(--lr-shadow-card);
  padding: var(--lr-space-4);
  display: flex;
  flex-direction: column;
  gap: var(--lr-space-3);
}

.demo-label {
  font-family: var(--lr-font-time);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--lr-ink-2);
}

.demo-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0E0D0C;
  border-radius: var(--lr-radius-media);
  display: flex;
  align-items: center;
  justify-content: center;
}

.demo-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lr-red);
  box-shadow: 0 0 0 2px rgba(194, 58, 23, 0.25);
  animation: demo-live-breath 1.4s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .demo-live-dot {
    animation: none;
  }
}

@keyframes demo-live-breath {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.85); opacity: 0.7; }
}

.demo-track {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.demo-title {
  font-family: var(--lr-font-display);
  font-weight: 800;
  font-size: var(--lr-text-state-m);
  letter-spacing: -0.02em;
  margin: 0;
}

.demo-artist {
  font-family: var(--lr-font-ui);
  font-size: var(--lr-text-meta);
  color: var(--lr-ink-2);
  margin: 0;
}

.demo-line-wrap {
  width: 100%;
  height: 44px;
}

#welcome-demo-phaseline {
  display: block;
  width: 100%;
  height: 100%;
}

.demo-reaction-area {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  min-height: 56px;
}

.demo-reaction-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

#welcome-demo .reaction-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.demo-heart-wrap {
  position: relative;
  z-index: 1;
  margin-left: auto;
}

@media (max-width: 374px) {
  .card {
    padding: var(--lr-space-5) var(--lr-space-4);
  }

  .watermark {
    width: 24rem;
    height: 24rem;
    right: -6rem;
    bottom: -7rem;
  }
}

/* Phones, portrait and landscape (#174): the example room card tells the same story as the features list, so it
   yields its space and the step fits one screen with the buttons and dots visible. */
@media (max-width: 767px), (max-height: 500px) {
  #welcome-demo {
    display: none;
  }
}

@media (max-width: 767px) {
  .phaseline-wrap {
    height: 56px;
  }
}
