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

/* Evening desk: warm-violet neutrals, coral accent for focus and links only */
:root {
  color-scheme: dark;
  --bg: oklch(0.19 0.024 292);
  --surface: oklch(0.235 0.022 292);
  --surface-hover: oklch(0.28 0.02 292);
  --border: oklch(0.36 0.028 292);
  --border-strong: oklch(0.42 0.03 292);
  --text: oklch(0.945 0.012 292);
  --muted: oklch(0.62 0.032 292);
  --accent: oklch(0.74 0.13 28);
  --accent-dim: oklch(0.55 0.1 28);
  --accent-soft: oklch(0.74 0.13 28 / 0.14);
  --preview-bg: oklch(0.205 0.018 285);
  --preview-well: oklch(0.17 0.02 288);
  --quote-bg: oklch(0.26 0.035 292 / 0.45);
  --selection: oklch(0.74 0.13 28 / 0.28);
  --focus-ring: oklch(0.74 0.13 28 / 0.55);
  --shadow-toolbar: oklch(0.08 0.02 292 / 0.45);
  --font-ui: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  --font-prose: "Source Serif 4", "Georgia", "Times New Roman", serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.625rem;
  /* Reading preview: defaults (evening); overridden in JS on .pane__inner--preview */
  --cr-prose-text: oklch(0.945 0.012 292);
  --cr-prose-bg: oklch(0.205 0.018 285);
  --cr-prose-link: oklch(0.74 0.13 28);
  --cr-prose-link-hover: oklch(0.82 0.11 28);
  --cr-prose-muted: oklch(0.62 0.032 292);
  --cr-prose-border: oklch(0.36 0.028 292);
  --cr-prose-code-bg: oklch(0.17 0.02 288);
  --cr-prose-quote-bg: oklch(0.26 0.035 292 / 0.45);
  --cr-prose-table-header-bg: oklch(0.17 0.02 288);
  --cr-prose-th-text: oklch(0.62 0.032 292);
  --cr-prose-pre-inset: oklch(0.4 0.02 292 / 0.25);
  --cr-font-prose: "Source Serif 4", "Georgia", "Times New Roman", serif;
  --cr-font-code: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  --cr-prose-size: 1.0625rem;
  --cr-prose-line-height: 1.7;
  --cr-prose-max: 68ch;
  --cr-h1: 2rem;
  --cr-h2: 1.45rem;
  --cr-h3: 1.2rem;
  --cr-h4: 1.05rem;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: var(--font-ui);
  font-optical-sizing: auto;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--selection);
}

.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;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.app-alert {
  flex-shrink: 0;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border-strong);
  background: oklch(0.32 0.08 28 / 0.35);
  color: var(--text);
  font-size: 0.8125rem;
  line-height: 1.45;
}

.app-alert[hidden] {
  display: none !important;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
  padding: 0.65rem 1rem 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 1px 0 oklch(0.5 0.04 292 / 0.06), 0 8px 24px var(--shadow-toolbar);
}

.toolbar__start {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.toolbar__identity {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  min-width: 0;
  max-width: min(42rem, 100%);
}

.toolbar__brand {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
}

.toolbar__tagline {
  margin: 0;
  max-width: 70ch;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.35;
  letter-spacing: 0.01em;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.toolbar__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.toolbar__theme {
  position: relative;
}

.theme-details {
  list-style: none;
}

.theme-details[open] {
  z-index: 5;
}

.theme-details > summary {
  list-style: none;
}

.theme-details > summary::-webkit-details-marker {
  display: none;
}

.theme-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 10;
  width: min(20rem, calc(100vw - 2.5rem));
  padding: 0.75rem 0.85rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 32px var(--shadow-toolbar);
}

.theme-panel__row {
  margin: 0 0 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.theme-panel__row--btns {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
}

.theme-panel__label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.theme-panel__select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--bg);
}

.theme-panel__range {
  width: 100%;
  min-height: 1.25rem;
  margin: 0.1rem 0 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.theme-panel__reset {
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--text);
  background: var(--bg);
  cursor: pointer;
  transition: color 0.18s var(--ease-out), background-color 0.18s var(--ease-out),
    border-color 0.18s var(--ease-out);
}

.theme-panel__reset:hover {
  background: var(--surface-hover);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.theme-panel__reset:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.theme-panel__hint {
  margin: 0.3rem 0 0;
  font-size: 0.7rem;
  line-height: 1.3;
  color: var(--muted);
}

.theme-details__summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.375rem;
  height: 2.375rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: color 0.18s var(--ease-out), background-color 0.18s var(--ease-out), border-color 0.18s var(--ease-out);
}

.theme-details__summary:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--accent);
}

.theme-details__summary:focus {
  outline: none;
}

.theme-details__summary:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.toolbar__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.375rem;
  height: 2.375rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: color 0.18s var(--ease-out), background-color 0.18s var(--ease-out), border-color 0.18s var(--ease-out);
}

.toolbar__toggle:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--accent);
}

.toolbar__toggle:active {
  transform: scale(0.97);
}

.toolbar__toggle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.toolbar__toggle-icon {
  font-size: 1.125rem;
  line-height: 1;
}

.toolbar__file {
  position: relative;
  display: inline-flex;
  cursor: pointer;
}

.toolbar__file input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.toolbar__file-label {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  background: var(--bg);
  transition: color 0.18s var(--ease-out), background-color 0.18s var(--ease-out), border-color 0.18s var(--ease-out);
}

.toolbar__file:hover .toolbar__file-label {
  background: var(--surface-hover);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.toolbar__file:focus-within .toolbar__file-label {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.toolbar__download {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: 0.01em;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: color 0.18s var(--ease-out), background-color 0.18s var(--ease-out), border-color 0.18s var(--ease-out);
}

.toolbar__download:hover {
  background: var(--surface-hover);
  border-color: var(--accent-dim);
  color: var(--accent);
}

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

.toolbar__download:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.toolbar__sync-scroll {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: 0.01em;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.18s var(--ease-out), background-color 0.18s var(--ease-out), border-color 0.18s var(--ease-out);
}

.toolbar__sync-scroll:hover {
  background: var(--surface-hover);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.toolbar__sync-scroll:active {
  transform: scale(0.98);
}

.toolbar__sync-scroll:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.toolbar__sync-scroll[aria-pressed="true"] {
  border-color: var(--accent-dim);
  background: var(--accent-soft);
  color: var(--accent);
}

.main {
  display: flex;
  flex: 1;
  min-height: 0;
}

.app-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  padding: 0.5rem 1rem 0.55rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--muted);
}

.app-footer__link {
  color: inherit;
  text-decoration: none;
  text-underline-offset: 0.15em;
  transition: color 0.18s var(--ease-out);
}

.app-footer__link:hover {
  color: var(--accent);
}

.app-footer__link:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.app-footer__credit {
  margin: 0;
  font-size: 0.6875rem;
  line-height: 1.35;
  color: var(--muted);
  opacity: 0.9;
}

.pane {
  flex: 1 1 50%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pane--editor {
  border-right: 1px solid var(--border);
}

.pane__inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pane__inner--editor {
  position: relative;
}

.pane__inner--editor.drop-active {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
  background: var(--accent-soft);
}

.editor {
  flex: 1;
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 1.15rem 1.25rem;
  border: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.65;
  tab-size: 2;
  color: var(--text);
  background: var(--bg);
  caret-color: var(--accent);
}

.editor::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

.editor:focus {
  outline: none;
}

.editor:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
  box-shadow: inset 0 0 0 1px oklch(0.74 0.13 28 / 0.35);
}

.pane__inner--preview {
  overflow: auto;
  padding: 1.5rem 1.5rem 2.5rem;
  background: var(--cr-prose-bg);
  scrollbar-color: var(--cr-prose-border) var(--cr-prose-bg);
  /* One centered column (margin:auto on many siblings is unreliable across browsers) */
  display: grid;
  justify-content: center;
  align-content: start;
  grid-template-columns: min(100%, var(--cr-prose-max));
  font-family: var(--cr-font-prose);
  font-size: var(--cr-prose-size);
  line-height: var(--cr-prose-line-height);
  color: var(--cr-prose-text);
}

.pane__inner--preview > * {
  min-width: 0;
}

.pane__inner--preview h1,
.pane__inner--preview h2,
.pane__inner--preview h3,
.pane__inner--preview h4 {
  font-family: var(--cr-font-prose);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.28;
  color: var(--cr-prose-text);
}

.pane__inner--preview h1 {
  margin: 0 0 0.65em;
  font-size: var(--cr-h1);
  font-weight: 700;
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--cr-prose-border);
}

.pane__inner--preview h2 {
  margin: 1.35em 0 0.45em;
  font-size: var(--cr-h2);
  font-weight: 600;
}

.pane__inner--preview h3 {
  margin: 1.25em 0 0.4em;
  font-size: var(--cr-h3);
  font-weight: 600;
}

.pane__inner--preview h4 {
  margin: 1.1em 0 0.35em;
  font-size: var(--cr-h4);
  font-weight: 600;
}

.pane__inner--preview p {
  margin: 0.7em 0;
}

.pane__inner--preview a {
  color: var(--cr-prose-link);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color 0.15s var(--ease-out);
}

.pane__inner--preview a:hover {
  color: var(--cr-prose-link-hover);
}

.pane__inner--preview strong {
  font-weight: 700;
}

.pane__inner--preview hr {
  margin: 2em 0;
  border: none;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--cr-prose-border) 12%,
    var(--cr-prose-border) 88%,
    transparent
  );
}

.pane__inner--preview code {
  font-family: var(--cr-font-code);
  font-size: 0.88em;
  font-weight: 400;
  padding: 0.12em 0.38em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--cr-prose-border);
  background: var(--cr-prose-code-bg);
}

.pane__inner--preview pre {
  margin: 1.1em 0;
  padding: 1rem 1.1rem;
  overflow: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--cr-prose-border);
  background: var(--cr-prose-code-bg);
  box-shadow: inset 0 1px 0 var(--cr-prose-pre-inset);
}

.pane__inner--preview pre code {
  padding: 0;
  border: none;
  background: transparent;
  font-size: 0.84em;
  line-height: 1.6;
}

.pane__inner--preview ul,
.pane__inner--preview ol {
  margin: 0.65em 0;
  padding-left: 1.35em;
}

.pane__inner--preview li {
  margin: 0.35em 0;
  padding-left: 0.25em;
}

.pane__inner--preview li::marker {
  color: var(--cr-prose-muted);
}

.pane__inner--preview blockquote {
  margin: 1.1em 0;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--cr-prose-border);
  background: var(--cr-prose-quote-bg);
  color: var(--cr-prose-muted);
  font-style: italic;
}

.pane__inner--preview table {
  width: 100%;
  margin: 1.1em 0;
  border-collapse: collapse;
  font-size: 0.95em;
  font-variant-numeric: tabular-nums;
}

.pane__inner--preview th,
.pane__inner--preview td {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--cr-prose-border);
  text-align: left;
}

.pane__inner--preview th {
  font-family: var(--font-ui);
  font-size: 0.78em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cr-prose-th-text);
  background: var(--cr-prose-table-header-bg);
}

.pane__inner--preview img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: 0.75em 0;
}

.pane__inner--preview img[src=""] {
  display: none;
}

/* Collapsed editor: full-width reading (display:none avoids flex min-content bugs from textarea) */
.app.app--editor-collapsed .pane--editor {
  display: none;
}

.app.app--editor-collapsed .pane--preview {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  border: none;
}

.app.app--editor-collapsed .pane__inner--preview {
  padding: 2rem clamp(1rem, 4vw, 3rem) 3rem;
}

@media (max-width: 720px) {
  .toolbar {
    flex-wrap: wrap;
    row-gap: 0.5rem;
    padding: 0.55rem 0.75rem;
  }

  .toolbar__brand {
    display: none;
  }

  .toolbar__tagline {
    font-size: 0.6875rem;
  }

  .toolbar__actions {
    width: 100%;
    justify-content: flex-end;
  }

  .main {
    flex-direction: column;
  }

  .pane--editor {
    flex: 1 1 42vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .pane--preview {
    flex: 1 1 58vh;
  }

  .app.app--editor-collapsed .pane--editor {
    display: none;
  }

  .app.app--editor-collapsed .pane--preview {
    flex: 1 1 auto;
    min-height: 0;
  }
}

/* Service-doc and help pages (e.g. docs/api.html) */
.doc-surface {
  min-height: 100vh;
  padding: 1.5rem;
  max-width: 42rem;
  margin: 0 auto;
}
