/* Tokyo Night (dark) and Tokyo Night Day (light), matched by the editor's
   themes of the same name. Strudel's editor sets unprefixed variables such as
   --background on :root, so the page's own variables use the --sw- prefix. */
:root {
  --sw-bg: #e1e2e7;
  --sw-raised: #d0d5e3;
  --sw-text: #343b58;
  --sw-muted: #4c5579;
  --sw-border: #6c7399;
  --sw-accent: #2959aa;
  --sw-on-accent: #ffffff;
  --sw-error: #a8274a;
  --sw-ok: #3d5a1e;
  --sw-font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --sw-bg: #1a1b26;
  --sw-raised: #24283b;
  --sw-text: #c0caf5;
  --sw-muted: #a9b1d6;
  --sw-border: #737aa2;
  --sw-accent: #7aa2f7;
  --sw-on-accent: #1a1b26;
  --sw-error: #f7768e;
  --sw-ok: #9ece6a;
  color-scheme: dark;
}

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

html {
  font-size: 100%;
}

body {
  margin: 0;
  background: var(--sw-bg);
  color: var(--sw-text);
  font-family: var(--sw-font);
  font-size: 1.0625rem;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.top,
main,
footer {
  width: min(100% - 2rem, 64rem);
  margin-inline: auto;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  padding: 0.5rem 0.75rem;
  background: var(--sw-accent);
  color: var(--sw-on-accent);
  border-radius: 4px;
}
.skip:focus {
  top: 1rem;
}

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

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  min-height: 2.75rem;
  border-radius: 6px;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* ---------------------------------------------------------------- header */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1.25rem 0.5rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.75rem, 1.2rem + 2.4vw, 2.5rem);
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.controls {
  display: flex;
  gap: 0.75rem;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--sw-border);
  border-radius: 8px;
  overflow: hidden;
}
.segmented button {
  min-width: 2.75rem;
  padding: 0 0.6rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
}
.segmented button + button {
  border-left: 1px solid var(--sw-border);
}
.segmented button[aria-pressed='true'] {
  background: var(--sw-accent);
  color: var(--sw-on-accent);
}
.segmented svg {
  width: 1.25rem;
  height: 1.25rem;
  vertical-align: middle;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------- request */

.intro {
  max-width: 62ch;
  margin: 0.5rem 0 1.5rem;
  color: var(--sw-muted);
}

.ask-label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 1.25rem;
  font-weight: 650;
}

/* The prompt is the one bold element: big type, with a bar on the left that
   runs like a playhead while the model writes. */
.prompt {
  position: relative;
  border: 2px solid var(--sw-border);
  border-radius: 8px;
  background: var(--sw-raised);
  overflow: hidden;
}
.prompt::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: var(--sw-accent);
}
.prompt:focus-within {
  border-color: var(--sw-accent);
}
.prompt textarea {
  display: block;
  width: 100%;
  min-height: 5.5rem;
  padding: 0.85rem 1rem 0.85rem 1.4rem;
  border: 0;
  background: transparent;
  font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem);
  line-height: 1.35;
  resize: vertical;
}
.prompt textarea:focus-visible {
  outline: none;
}
.prompt textarea::placeholder {
  color: var(--sw-muted);
  opacity: 1;
}
.busy .prompt::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  width: 30%;
  background: var(--sw-accent);
  animation: playhead 1.4s linear infinite;
}
@keyframes playhead {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(340%);
  }
}

.hint {
  margin: 0.5rem 0 0;
  color: var(--sw-muted);
  font-size: 1rem;
}

.ask-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  margin-top: 1rem;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  cursor: pointer;
}
.check input {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--sw-accent);
}

.primary {
  margin-left: auto;
  padding: 0 1.4rem;
  border: 0;
  background: var(--sw-accent);
  color: var(--sw-on-accent);
  font-weight: 700;
}

.secondary {
  padding: 0 1.1rem;
  border: 1px solid var(--sw-border);
  background: transparent;
  font-weight: 600;
}

.status {
  min-height: 1.5rem;
  margin: 1rem 0 0;
}
.status[data-kind='error'] {
  color: var(--sw-error);
}
.status[data-kind='ok'] {
  color: var(--sw-ok);
}
.status code {
  font-size: 0.95em;
}

/* ---------------------------------------------------------------- examples */

.examples {
  margin-top: 1.5rem;
}
h2 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 650;
}
.examples ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
}
.example {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--sw-border);
  background: transparent;
  text-align: left;
  font-size: 1rem;
}
.example:hover {
  border-color: var(--sw-accent);
}

/* ---------------------------------------------------------------- editor */

.editor {
  margin-top: 2rem;
}
.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.editor-slot {
  min-height: 18rem;
  border: 1px solid var(--sw-border);
  border-radius: 8px;
  overflow: hidden;
}
.editor-slot strudel-editor {
  display: none;
}
.editor-slot .cm-editor {
  min-height: 18rem;
}
.editor-loading {
  margin: 0;
  padding: 1rem;
  color: var(--sw-muted);
}

footer {
  padding-block: 2rem;
  color: var(--sw-muted);
  font-size: 1rem;
}
footer p {
  max-width: 62ch;
  margin: 0;
}

@media (max-width: 40rem) {
  .primary {
    width: 100%;
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .busy .prompt::after {
    animation: none;
    width: 100%;
    opacity: 0.6;
  }
}
