:root {
  --brand: #6c1afb;
  --brand-soft: #ebe4ff;
  --surface: #f4f0ff;
  --surface-elevated: #ffffff;
  --border: #d8cff5;
  --radius: 12px;
  --text-on-brand: #fff;
  --shadow: 0 8px 28px rgba(60, 20, 120, 0.14);
  --highlight-ring: 0 0 0 3px color-mix(in oklch, var(--brand) 35%, transparent);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 0.45s;
}

@supports (color: contrast-color(var(--brand))) {
  :root {
    --text-on-brand: color-mix(
      in oklch,
      var(--brand) 25%,
      contrast-color(var(--brand))
    );
  }
}

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

body {
  font-family:
    system-ui,
    -apple-system,
    'Segoe UI',
    sans-serif;
  line-height: 1.5;
  color: #1a1228;
  background: linear-gradient(165deg, var(--surface) 0%, var(--brand-soft) 55%);
  margin: 0;
  min-height: 100vh;
  padding: 1.5rem 1rem 2.5rem;
}

a {
  color: var(--brand);
}

code {
  font-size: 0.88em;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  background: color-mix(in oklch, var(--brand) 8%, white);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

/* --- Tutorial shell --- */

.tutorial {
  max-width: 40rem;
  margin: 0 auto;
}

.tutorial-hero {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.tutorial-hero-logo {
  display: block;
  width: min(12rem, 72vw);
  height: auto;
  margin: 0 auto 0.75rem;
}

.tutorial-eyebrow {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b5c88;
}

.tutorial-hero h1 {
  margin: 0.2rem 0 0.5rem;
  font-size: clamp(1.5rem, 4vw, 1.85rem);
  font-weight: 700;
  line-height: 1.2;
}

.tutorial-lead {
  margin: 0;
  font-size: 0.95rem;
  color: #4a3d66;
  max-width: 38em;
}

.tutorial-lead a {
  font-weight: 600;
}

/* Progress stepper */

.tutorial-progress {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.tutorial-progress li {
  flex: 1 1 5.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #6b5c88;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition:
    background-color var(--dur) var(--ease-out),
    color var(--dur) var(--ease-out),
    border-color var(--dur) var(--ease-out),
    transform var(--dur) var(--ease-out);
}

.tutorial-progress li.done {
  color: #2d6a4f;
  border-color: #95d5b2;
  background: #f1faf4;
}

.tutorial-progress li.current {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--surface-elevated);
  box-shadow: var(--highlight-ring);
  transform: scale(1.02);
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  font-size: 0.68rem;
  background: color-mix(in oklch, var(--brand) 12%, white);
}

.tutorial-progress li.done .step-num {
  background: #95d5b2;
  color: #1b4332;
}

.tutorial-progress li.current .step-num {
  background: var(--brand);
  color: var(--text-on-brand);
}

/* Interactive flow diagram (Una-style explorable block) */

.flow-diagram {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-elevated);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.flow-diagram summary {
  cursor: pointer;
  padding: 0.75rem 1rem;
  font-weight: 650;
  font-size: 0.9rem;
  color: var(--brand);
  list-style: none;
}

.flow-diagram summary::-webkit-details-marker {
  display: none;
}

.flow-diagram summary::after {
  content: ' ▾';
  opacity: 0.6;
}

.flow-diagram[open] summary::after {
  content: ' ▴';
}

.flow-diagram-body {
  padding: 0 1rem 1rem;
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  text-align: center;
}

.flow-node {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 2px solid var(--border);
  background: #faf8ff;
  min-width: 8rem;
}

.flow-stream {
  border-color: var(--brand);
  background: color-mix(in oklch, var(--brand) 12%, white);
  color: var(--brand);
}

.flow-arrow {
  font-size: 0.72rem;
  color: #6b5c88;
  font-weight: 600;
}

.flow-patches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
}

.flow-patch {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: #2a2040;
  color: #f4f0ff;
  font-family: ui-monospace, monospace;
}

.flow-note {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: #6b5c88;
  max-width: 28em;
}

/* Card + live status */

.card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: clip;
}

.status-live {
  display: block;
  padding: 0.65rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: #2a2040;
  background: color-mix(in oklch, var(--brand) 6%, white);
  border-bottom: 1px solid var(--border);
  min-height: 2.75rem;
  transition:
    background-color var(--dur) var(--ease-out),
    color var(--dur) var(--ease-out);
}

.card-body {
  padding: 1.15rem 1.25rem 1.35rem;
}

/* Entry / exit panels — Chrome entry-exit-animations pattern */

.tutorial-callout,
.tutorial-panel,
#demo-live,
.tutorial-stage,
.room-item,
.msg,
.error-banner {
  transition:
    opacity var(--dur) var(--ease-out),
    transform var(--dur) var(--ease-out),
    display var(--dur) allow-discrete,
    overlay var(--dur) allow-discrete;
}

@starting-style {
  .tutorial-callout,
  .tutorial-panel,
  #demo-live {
    opacity: 0;
    transform: translateY(14px);
  }

  .room-item,
  .msg {
    opacity: 0;
    transform: translateX(-10px);
  }

  .error-banner {
    opacity: 0;
    transform: scale(0.98);
  }
}

.tutorial-callout {
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid color-mix(in oklch, var(--brand) 25%, var(--border));
  background: linear-gradient(
    135deg,
    color-mix(in oklch, var(--brand) 8%, white) 0%,
    var(--surface-elevated) 100%
  );
}

.tutorial-callout h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  color: var(--brand);
}

.tutorial-callout p {
  margin: 0;
  font-size: 0.88rem;
  color: #4a3d66;
}

.tutorial-callout--finish {
  border-color: #95d5b2;
  background: linear-gradient(135deg, #f1faf4 0%, var(--surface-elevated) 100%);
}

.tutorial-callout--finish h2 {
  color: #2d6a4f;
}

.tutorial-panel {
  margin-bottom: 1rem;
}

.tutorial-panel.highlight {
  border-radius: var(--radius);
  box-shadow: var(--highlight-ring);
}

.tutorial-panel--auth.highlight fieldset {
  border-color: var(--brand);
}

.tutorial-panel h2,
.tutorial-stage h2 {
  margin: 0 0 0.65rem;
  font-size: 1.05rem;
  font-weight: 650;
}

.session-badge {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 1rem;
  font-size: 0.82rem;
  color: #5c4d7a;
}

.stream-pill {
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #2d6a4f;
  color: #fff;
  animation: pulse-live 2s ease-in-out infinite;
}

@keyframes pulse-live {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.75;
  }
}

.room-actions {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

@media (min-width: 520px) {
  .room-actions {
    grid-template-columns: 1fr 1fr;
  }
}

/* Forms */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0;
  padding: 0.65rem 0.85rem 0.85rem;
  transition: border-color var(--dur) var(--ease-out);
}

legend {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0 0.25rem;
  color: #5c4d7a;
}

label {
  display: block;
  margin-top: 0.55rem;
  font-size: 0.82rem;
  font-weight: 500;
}

input.field,
select.field {
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  color: var(--text, #2a2238);
  background-color: #faf8ff;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

select.field.room-picker {
  padding-right: 2.25rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235c4d7a' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 12px 8px;
}

select.field.room-picker option {
  background: #fff;
  color: #2a2238;
}

select.field.room-picker option.preconfigured-private,
select.field.room-picker option.room-option.preconfigured-private {
  color: #1b6b3a;
  font-weight: 600;
}

select.field.room-picker option.preconfigured-public,
select.field.room-picker option.room-option.preconfigured-public {
  color: #2c5282;
  font-weight: 600;
}

select.field.room-picker.room-picker--private-selected {
  border-color: #3d9a62;
  color: #1b6b3a;
  font-weight: 600;
  background-color: #f3fbf6;
}

select.field.room-picker.room-picker--public-selected {
  border-color: #6b8fc7;
  color: #2c5282;
  font-weight: 600;
  background-color: #f0f5ff;
}

select.field.room-picker.room-picker--other-selected {
  border-color: #8a7aa8;
  color: #2a2238;
  font-weight: 600;
}

.room-picker-legend {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  color: #6b5f80;
  line-height: 1.4;
}

.room-picker-legend-private {
  color: #1b6b3a;
  font-weight: 600;
}

.room-picker-legend-public {
  color: #2c5282;
  font-weight: 600;
}

.room-picker-legend-other {
  color: #2a2238;
  font-weight: 500;
}

.active-room-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.active-room-label-row .active-room-label {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 500;
}

#room-picker {
  margin-top: 0.2rem;
}

.room-by-name-trigger {
  flex: 0 0 auto;
  min-width: 1.75rem;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #faf8ff;
  color: #5c4d7a;
}

.room-by-name-trigger:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.room-by-name-trigger-icon {
  display: block;
}

.room-by-name-dialog {
  max-width: 22rem;
  width: calc(100% - 2rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.room-by-name-dialog::backdrop {
  background: rgba(26, 18, 40, 0.35);
}

.room-by-name-dialog-form {
  margin: 0;
  padding: 1rem 1.1rem 1.1rem;
}

.room-by-name-dialog-title {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 650;
}

.room-by-name-dialog--success .room-by-name-dialog-form {
  animation: room-by-name-success 0.6s var(--ease-out);
}

@keyframes room-by-name-success {
  0% {
    box-shadow: inset 0 0 0 0 transparent;
  }
  40% {
    box-shadow: inset 3px 0 0 0 #2d6a4f;
  }
  100% {
    box-shadow: inset 0 0 0 0 transparent;
  }
}

.room-by-name-remembered {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
  min-height: 0;
}

.room-by-name-chip {
  flex: 0 1 auto;
  min-width: 0;
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 999px;
  border: 1px solid #9ed4b0;
  background: #e8f7ed;
  color: #1b6b3a;
}

.room-by-name-dialog-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

.room-by-name-dialog-actions button {
  flex: 0 1 auto;
  min-width: 5rem;
}

input.field:focus-visible,
select.field:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--highlight-ring);
}

/* Legacy inputs without .field */
input:not(.field) {
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #faf8ff;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

button {
  flex: 1 1 auto;
  min-width: 6rem;
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition:
    transform 0.15s var(--ease-out),
    background-color 0.2s,
    border-color 0.2s;
}

button:active {
  transform: scale(0.98);
}

button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

button.primary {
  background: var(--brand);
  color: var(--text-on-brand);
  border-color: var(--brand);
}

button.secondary {
  background: transparent;
  color: var(--brand);
  border-color: var(--brand);
}

.hint {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: #6b5c88;
}

/* Room list */

.room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.room-list .empty {
  padding: 0.75rem;
  text-align: center;
  font-size: 0.85rem;
  color: #6b5c88;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.state-connecting {
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

.room-pick {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.85rem;
  background: #faf8ff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  font-weight: 500;
}

.room-item--preconfigured-private .room-pick {
  border-color: #9ed4b0;
  background: #f0faf3;
}

.room-item--preconfigured-private .room-pick strong {
  color: #1b6b3a;
}

.room-item--preconfigured-public .room-pick {
  border-color: #a8c4e8;
  background: #f0f5ff;
}

.room-item--preconfigured-public .room-pick strong {
  color: #2c5282;
}

.room-pick:hover {
  border-color: var(--brand);
  background: color-mix(in oklch, var(--brand) 6%, white);
}

.room-pick.active {
  border-color: var(--brand);
  background: color-mix(in oklch, var(--brand) 14%, white);
  box-shadow: var(--highlight-ring);
}

.room-id {
  font-size: 0.72rem;
  font-family: ui-monospace, monospace;
  color: #6b5c88;
  font-weight: 400;
  margin-top: 0.15rem;
}

/* Inbox */

.inbox {
  margin-top: 0.75rem;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #faf8ff;
  min-height: 5rem;
  max-height: 14rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.inbox .empty {
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  color: #6b5c88;
}

.msg {
  margin: 0;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  font-size: 0.88rem;
}

.msg .sender {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brand);
  font-family: ui-monospace, monospace;
}

.msg-body {
  display: block;
  margin-top: 0.15rem;
}

.error-banner {
  margin-top: 1rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  background: #fff0f0;
  border: 1px solid #f5c2c2;
  color: #9b2226;
  font-size: 0.88rem;
  font-weight: 500;
}

/* Reduced motion */

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

  .tutorial-progress li.current {
    transform: none;
  }
}
