:root {
  --bg: #fafaf7;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #ea580c;
  --accent-ink: #ffffff;
  --good: #16a34a;
  --bad: #dc2626;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.04), 0 4px 16px rgb(15 23 42 / 0.06);
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Inter Tight", "Inter", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --ink: #f8fafc;
    --muted: #94a3b8;
    --line: #1e293b;
    --card: #111827;
    --accent: #fb923c;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 20px max(24px, env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Landscape on small phones can swallow the submit button under the keyboard.
   Tighten vertical rhythm so the Join button stays in view (Mark finding). */
@media (max-height: 480px) {
  #app {
    gap: 12px;
    padding-top: 12px;
  }
  h1 {
    font-size: 22px;
  }
  .field input,
  .field textarea {
    padding: 10px 12px;
  }
  .btn {
    padding: 12px 14px;
  }
}

.eyebrow {
  font-family: var(--font-sans);
  font-variant: small-caps;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 12px;
  color: var(--muted);
}

h1,
h2 {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.15;
}

h2 {
  font-size: 22px;
  line-height: 1.2;
}

p {
  margin: 0;
  line-height: 1.5;
  color: var(--ink);
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

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

.header .room {
  font-family: var(--font-sans);
  font-size: 14px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.header .you {
  font-size: 14px;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 8px;
}

.field input,
.field textarea {
  font: inherit;
  font-size: 16px; /* iOS Safari auto-zooms on focus when input < 16px (Mark Fix 8) */
  width: 100%;
  padding: 14px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  transition: border-color 120ms ease;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.field textarea {
  resize: vertical;
  min-height: 120px;
}

.btn {
  font: inherit;
  font-weight: 600;
  padding: 16px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  width: 100%;
  text-align: center;
  transition: transform 80ms ease, background 120ms ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible,
.btn-ghost:focus-visible {
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
}

.btn:disabled {
  background: color-mix(in srgb, var(--accent) 30%, var(--card));
  color: color-mix(in srgb, var(--accent-ink) 60%, var(--card));
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--line);
}

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option {
  font: inherit;
  text-align: left;
  padding: 18px 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-weight: 500;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 80ms ease;
  display: flex;
  gap: 12px;
  align-items: center;
}

.option .marker {
  flex: 0 0 auto;
  font-family: var(--font-sans);
  font-size: 12px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.option:hover {
  border-color: var(--accent);
}

.option:active {
  transform: scale(0.99);
}

.option.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--card));
}

.option.selected .marker {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

/* Focus-visible uses a dashed outline outside the border — visually distinct from selected fill */
.option:focus-visible {
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
}

.confirm {
  text-align: center;
  padding: 40px 20px;
}

.confirm .check {
  font-size: 56px;
  line-height: 1;
  color: var(--good);
  margin-bottom: 12px;
}

.previous-response {
  /* Equalize the divider-to-answer gap with the card's bottom padding (40px)
   * so the echo block reads as designed rather than tacked on (Dorry P1). */
  margin-top: 24px;
  padding-top: 24px;
  /* Token is `--line`, NOT `--border` — the latter does not exist in :root,
   * and the previous hardcoded `#e2e8f0` fallback failed to flip in dark mode,
   * leaving a bright divider against a dark card (Dorry P0). */
  border-top: 1px solid var(--line);
}

.previous-response .small {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
  /* Reinforce label/answer hierarchy — label should be quiet, answer loud. */
  color: var(--muted);
}

.previous-response .your-answer {
  font-size: 18px;
  font-weight: 500;
  word-break: break-word;
  margin: 0;
  /* Preserve newlines emitted by formatPreviousResponse for ranking and
   * many-option multi-select renders (Dorry P1, P2). */
  white-space: pre-line;
  /* Cap long short-text answers so the card doesn't stretch off-screen
   * on mobile (Dorry P2). */
  max-height: 12em;
  overflow-y: auto;
}

.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.error-banner {
  background: color-mix(in srgb, var(--bad) 10%, var(--card));
  border: 1px solid var(--bad);
  color: var(--bad);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
}

.spacer {
  flex: 1;
}

.byline {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

@media (max-width: 420px) {
  h1 {
    font-size: 26px;
  }
}

.context strong {
  color: var(--ink);
  font-weight: 600;
}

.fw-reconnect-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 28px;
  z-index: 100;
  pointer-events: none; /* underneath state stays interactive once overlay clears */
}

.fw-reconnect-pill {
  pointer-events: auto;
  background: var(--card);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.fw-reconnect-pill::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bad);
  animation: fw-pulse 1.2s ease-in-out infinite;
}

@keyframes fw-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

option:disabled,
.option:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* --- "Not [name]?" identity reset link on waiting screen --- */
.fw-not-you {
  font-size: 13px;
  padding: 8px 14px;
  align-self: flex-start;
  width: auto;
}

/* --- Short-text submit positioning ---
 * Previously `position: sticky` to "keep the button above the iOS keyboard"
 * — but sticky keys off the layout viewport, not the visual viewport. When
 * iOS Safari's soft keyboard opens, it shrinks the visual viewport and the
 * sticky button slides UNDER the keyboard, unreachable without scrolling
 * (Mark P0 second-pass finding). Plain block flow with breathing room works
 * better: iOS auto-scrolls the focused textarea into view, and the submit
 * button sits right below it. */
.fw-short-text-submit {
  margin-top: 12px;
  padding-bottom: env(safe-area-inset-bottom, 12px);
}

/* --- Short-text character counter (Chuck P1) --- */
/* Anchored top-right of the field so it sits against the textarea edge —
 * keeps the visual association tight without taking a whole line. */
.fw-short-text-counter {
  font-size: 13px;
  color: var(--muted, #888);
  text-align: right;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  transition: color 120ms ease;
}
.fw-short-text-counter.is-at-max {
  color: var(--danger, #c0392b);
  font-weight: 600;
}

/* --- Paste-truncation notice (Chuck P2 #12) --- */
/* Inline beneath the counter; warm color so it reads as informational, not
 * a hard error. Auto-clears after 6s via JS — no manual dismiss needed. */
.fw-short-text-trim-notice {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(240, 168, 48, 0.15);
  color: var(--danger, #c0392b);
  border-left: 3px solid var(--danger, #c0392b);
  font-size: 13px;
  line-height: 1.35;
}

/* --- Short-text character counter (Chuck P1) --- */
/* Anchored top-right of the field so it sits against the textarea edge —
 * keeps the visual association tight without taking a whole line. */
.fw-short-text-counter {
  font-size: 13px;
  color: var(--muted, #888);
  text-align: right;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  transition: color 120ms ease;
}
.fw-short-text-counter.is-at-max {
  color: var(--danger, #c0392b);
  font-weight: 600;
}

/* --- Numeric input --- */
.fw-numeric-readout {
  text-align: center;
  font-size: 3rem;
  font-weight: 600;
  margin: 1rem 0 0.5rem;
  color: var(--ink);
}
.fw-slider {
  width: 100%;
  height: 44px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}
.fw-slider:focus { outline: none; }
.fw-slider::-webkit-slider-runnable-track {
  height: 8px;
  background: rgba(0, 0, 0, 0.12);
  border-radius: 4px;
}
.fw-slider::-moz-range-track {
  height: 8px;
  background: rgba(0, 0, 0, 0.12);
  border-radius: 4px;
}
.fw-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  margin-top: -10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}
.fw-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}
.fw-numeric-input {
  font-size: 1.2rem;
  text-align: center;
}
.fw-numeric-field {
  margin-top: 1rem;
}

/* --- Ranking --- */
.fw-ranking {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.fw-rank-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  border-radius: 0.5rem;
}
.fw-rank-label {
  flex: 1;
  font-size: 1rem;
}
.fw-rank-select {
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0.4rem 0.6rem;
  min-width: 4.5rem;
  border-radius: 0.4rem;
  border: 1px solid var(--line);
  background: var(--card);
}

/* ---------- slides screen (Unit 6/7) ---------- */
/* The slides screen overrides the default #app max-width — we want the iframe
   to fill the viewport on mobile, and the bottom bar is fixed-position so it
   doesn't need #app's flex column. */
#app.screen-slides {
  max-width: 100%;
  padding: 0;
  /* Bottom bar is 64px (locked from Dieter, plan-review). Pad so the iframe
     and any submission form stay above it including the iOS home-indicator. */
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  gap: 0;
  /* When showing the slides screen, hide #app's normal column-content surface
     — the iframe host below renders the actual slide view. The fallback
     screen still lives in #app (rendered when state.iframeFailed is true). */
  min-height: 0;
}

/* Iframe host lives as a sibling to #app so it survives render()'s
   innerHTML clears. Visibility is class-driven on #app. */
#fw-iframe-host {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(64px + env(safe-area-inset-bottom));
  z-index: 5;
  background: var(--bg);
}
#app.screen-slides ~ #fw-iframe-host {
  display: block;
}
/* When the iframe has failed, hide the host so the in-#app fallback shows. */
#fw-iframe-host[data-failed="true"] {
  display: none !important;
}

.fw-slide-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}

.fw-slide-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(64px + env(safe-area-inset-bottom));
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgb(15 23 42 / 0.06);
  z-index: 20;
}

.fw-slide-bar .btn,
.fw-slide-bar .btn-ghost {
  width: auto;
  flex: 1 1 0;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 15px;
  border-radius: 10px;
}

.fw-slide-bar .fw-gate-label {
  flex: 1 1 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.2;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  cursor: default;
}

/* Loading indicator inside the iframe host while Slidev is bootstrapping. */
#fw-iframe-host[data-loading="true"]::before {
  content: "Loading slides…";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 14px;
  color: var(--muted);
}

/* Slide counter — small, unobtrusive, top-right of iframe host. */
.fw-slide-counter {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: 12px;
  z-index: 6;
  font-size: 12px;
  font-feature-settings: "tnum";
  color: var(--muted);
  background: color-mix(in srgb, var(--card) 90%, transparent);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  pointer-events: none;
}

/* Always-visible slide title strip (Mark P2 #14). Stretches across the top
 * just below the safe-area, sits above the iframe via z-index, and tells the
 * participant which slide is currently on the projector regardless of how
 * the embedded deck scales. Truncates with ellipsis for long titles. */
.fw-slide-title-strip {
  position: fixed;
  top: env(safe-area-inset-top, 0);
  left: 0;
  right: 0;
  z-index: 6;
  padding: 8px 92px 8px 12px; /* right padding clears the slide-counter pill */
  background: color-mix(in srgb, var(--card) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
  pointer-events: none;
}
.fw-slide-title-text {
  display: block;
  font-family: var(--font-display, inherit);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Push the iframe down so the title strip doesn't overlap slide content. */
#app.screen-slides ~ #fw-iframe-host {
  top: calc(env(safe-area-inset-top, 0) + 36px);
}

/* Narrow-screen hardening for the slide bar. The gate-label can be up to
 * 40 characters ("The class is here — moving on shortly.") — at phone width
 * with 3 flex children it'll squish or overlap. Reduce font and let it wrap
 * to two lines so it stays legible. */
@media (max-width: 480px) {
  .fw-slide-bar {
    gap: 6px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .fw-slide-bar .btn,
  .fw-slide-bar .btn-ghost {
    font-size: 14px;
    padding: 8px 8px;
  }
  .fw-slide-bar .fw-gate-label {
    font-size: 12px;
    line-height: 1.15;
    padding: 0 4px;
    white-space: normal;
  }
}

.fw-slide-fallback {
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fw-slide-fallback h2 {
  margin: 0;
  font-family: var(--font-display);
}

/* ============================================================
   Countdown + closed/reveal — spec §3.1, §3.4, §3.5 (class-2)
   ============================================================ */

.fw-countdown-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  font-family: var(--font-display);
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1;
  padding: 0.3rem 0.8rem;
  min-width: 2.5rem;
  margin: 0.25rem 0 0.5rem;
  color: var(--ink);
  background: transparent;
  border: 2px solid color-mix(in srgb, var(--ink) 25%, transparent);
  border-radius: 8px;
  letter-spacing: -0.02em;
}

.fw-countdown-badge.is-urgent {
  color: var(--accent);
  border-color: var(--accent);
}

.fw-closed-banner {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--ink);
  padding: 0.5rem 0 0.25rem;
}

.fw-closed-prompt {
  font-family: var(--font-display);
  font-size: 1.4rem;
  line-height: 1.2;
  margin: 0.25rem 0 1rem;
  color: var(--ink);
}

.fw-closed-aggregates {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
}

.fw-closed-text-item {
  padding: 0.5rem 0.75rem;
  background: var(--card);
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
  font-size: 0.95rem;
  line-height: 1.35;
  white-space: pre-wrap;
}

.fw-closed-vote-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--card);
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
