:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --text: #17171c;
  --muted: #50505f;
  --border: #d3d3dc;
  --accent: #4338ca;
  --on-accent: #ffffff;
  --user: #4338ca;
  --on-user: #ffffff;
  --bot: #eceef6;
  --note: #f3efe4;
  --ok: #166534;
  --warn: #92400e;
  --error: #b91c1c;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1014;
    --surface: #17181e;
    --text: #ececf2;
    --muted: #a9a9b8;
    --border: #30313b;
    --accent: #a5b4fc;
    --on-accent: #0f1014;
    --user: #3730a3;
    --on-user: #ffffff;
    --bot: #22232c;
    --note: #2a261c;
    --ok: #86efac;
    --warn: #fcd34d;
    --error: #fca5a5;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
  color: var(--accent);
  text-underline-offset: 0.18em;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.wrap {
  max-width: 60rem;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--accent);
  color: var(--on-accent);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  z-index: 10;
}

.skip:focus {
  top: 1rem;
}

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}

.brand {
  margin: 0;
  font-weight: 700;
}

.brand a {
  color: var(--text);
  text-decoration: none;
}

nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.15;
  margin: 2.5rem 0 1rem;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.5rem;
  margin: 3rem 0 0.75rem;
}

h3 {
  font-size: 1.1rem;
  margin: 1.75rem 0 0.5rem;
}

.lead {
  font-size: 1.2rem;
  max-width: 44rem;
}

.meta,
.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.panel {
  margin-top: 1.5rem;
}

.settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.setting .hint {
  margin: 0.4rem 0 0;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

legend,
label[for='volume'] {
  font-weight: 600;
  padding: 0;
}

.family label {
  display: block;
  margin-top: 0.35rem;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}

input[type='radio'] {
  accent-color: var(--accent);
}

.note {
  border-left: 4px solid var(--warn);
  padding: 0.5rem 0.75rem;
  background: var(--surface);
}

/* Switch */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  background: none;
  border: 0;
  padding: 0.25rem 0;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.switch-track {
  width: 3rem;
  height: 1.75rem;
  border-radius: 999px;
  background: var(--muted);
  position: relative;
  transition: background 0.15s;
}

.switch-thumb {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: var(--surface);
  transition: transform 0.15s;
}

.switch[aria-checked='true'] .switch-track {
  background: var(--accent);
}

.switch[aria-checked='true'] .switch-thumb {
  transform: translateX(1.25rem);
}

.switch[aria-checked='true'] .switch-label::after {
  content: ' on';
}

.switch[aria-checked='false'] .switch-label::after {
  content: ' off';
}

/* Buttons */
button {
  font: inherit;
  cursor: pointer;
}

.primary,
.ghost,
.chip {
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
  min-height: 2.75rem;
  border: 1px solid var(--accent);
}

.primary {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.ghost,
.chip {
  background: transparent;
  color: var(--accent);
}

.chip[aria-pressed='true'],
.ghost[aria-pressed='true'] {
  background: var(--accent);
  color: var(--on-accent);
}

.small {
  min-height: 2.25rem;
  padding: 0.25rem 0.85rem;
  font-size: 0.9rem;
}

/* Chat */
.chat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 46rem;
  overflow: hidden;
}

.chat-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-weight: 600;
}

.dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--muted);
}

.status[data-kind='busy'] .dot {
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.status[data-kind='done'] .dot {
  background: var(--ok);
}

.status[data-kind='warn'] .dot {
  background: var(--warn);
}

.status[data-kind='error'] .dot {
  background: var(--error);
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

.log {
  list-style: none;
  margin: 0;
  padding: 1rem;
  height: 24rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.msg {
  max-width: 85%;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  background: var(--bot);
}

.msg .who {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0.85;
}

.msg .body {
  margin: 0.1rem 0 0;
}

.msg.user {
  align-self: flex-end;
  background: var(--user);
  color: var(--on-user);
}

.msg.note {
  align-self: center;
  background: var(--note);
  font-size: 0.92rem;
}

.msg.waiting {
  opacity: 0.75;
}

.msg button {
  margin-top: 0.5rem;
}

.msg .actions {
  display: flex;
  gap: 0.5rem;
}

.scenarios {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.scenarios .hint {
  margin: 0 0.25rem 0 0;
}

.composer {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
}

.composer label {
  font-weight: 600;
}

textarea {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--muted);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  resize: vertical;
}

.composer .hint {
  margin: 0.35rem 0 0.5rem;
}

.composer-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.attachment {
  display: inline-block;
  font-size: 0.85rem;
  border: 1px dashed var(--muted);
  border-radius: 8px;
  padding: 0.1rem 0.5rem;
  margin-top: 0.35rem;
}

/* Library */
.cues {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 0.75rem;
}

.cue {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
}

.cue p {
  margin: 0;
}

.cue-name code {
  font-weight: 700;
}

.cue-when {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0.25rem 0 0.75rem !important;
  flex: 1;
}

.cue-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
}

.download {
  font-size: 0.85rem;
}

.tag {
  font-size: 0.75rem;
  border: 1px solid var(--muted);
  border-radius: 999px;
  padding: 0 0.45rem;
  margin-left: 0.35rem;
  color: var(--muted);
}

/* Code and text */
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  overflow-x: auto;
}

.steps li {
  margin-bottom: 1rem;
}

.credit {
  background: var(--surface);
  border-left: 4px solid var(--accent);
  padding: 0.5rem 0.75rem;
}

.rules li {
  margin-bottom: 0.5rem;
}

.site-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 1.5rem 0 2rem;
}

.site-footer p {
  margin: 0.25rem 0;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {
  .switch-track,
  .switch-thumb,
  .dot {
    forced-color-adjust: none;
    border: 1px solid CanvasText;
  }
}
