/* The visual system stays intentionally quiet: system fonts, neutral surfaces and clean spacing. */
:root {
  --bg: #0a0d10;
  --bg-subtle: #101419;
  --surface: #151a20;
  --surface-muted: #10151a;
  --surface-soft: #1b222a;
  --ink: #f4f7fb;
  --muted: #98a3b2;
  --muted-strong: #c4ccd6;
  --line: #242c35;
  --line-strong: #333d49;
  --accent: #f4f7fb;
  --accent-contrast: #0a0d10;
  --danger: #ff8d82;
  --danger-bg: #301619;
  --success: #7ae0c7;
  --success-bg: #102721;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.32), 0 18px 48px rgba(0, 0, 0, 0.24);
  --radius: 14px;
  --radius-sm: 10px;
  --max-width: 1040px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

html[data-theme="light"] {
  --bg: #f5f7fa;
  --bg-subtle: #eef2f6;
  --surface: #ffffff;
  --surface-muted: #f7f8fa;
  --surface-soft: #eef2f6;
  --ink: #111827;
  --muted: #667085;
  --muted-strong: #344054;
  --line: #d9e0e8;
  --line-strong: #c4ced8;
  --accent: #111827;
  --accent-contrast: #ffffff;
  --danger: #c2413a;
  --danger-bg: #fff1f0;
  --success: #0f766e;
  --success-bg: #eafaf7;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 18px 40px rgba(16, 24, 40, 0.08);
}

/* Global defaults keep box sizing and fonts consistent across SSR pages. */
* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg-subtle);
  color: var(--ink);
  font-family: var(--font-ui);
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top center, rgba(255, 255, 255, 0.035), transparent 34%),
    linear-gradient(180deg, #090b0e 0%, var(--bg-subtle) 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

/* The shell width and spacing mirror a document-style reading layout. */
.page-shell {
  width: min(calc(100% - 2rem), var(--max-width));
  margin: 0 auto;
  padding: 1.125rem 0 3rem;
}

.page-content {
  display: grid;
  gap: 1.75rem;
}

.page-content > * {
  min-width: 0;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  padding: 0.125rem 0 0.5rem;
}

.site-header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.brand {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.site-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem;
}

.nav-link,
.primary-button,
.secondary-button,
.danger-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.2;
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease, color 140ms ease;
}

.nav-link,
.secondary-button,
.ghost-button {
  background: var(--surface);
  border-color: var(--line);
}

.nav-link {
  color: var(--muted);
  background: transparent;
  border-color: transparent;
}

.nav-link.is-current {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
}

.primary-button {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
}

.danger-button {
  background: var(--danger-bg);
  border-color: #56242a;
  color: var(--danger);
}

.ghost-button {
  color: var(--muted);
  background: transparent;
  border-color: transparent;
}

.theme-toggle {
  min-width: 5.5rem;
}

.nav-link:hover,
.primary-button:hover,
.secondary-button:hover,
.danger-button:hover,
.ghost-button:hover {
  border-color: var(--line-strong);
}

.primary-button:hover {
  background: #ffffff;
}

.ghost-button:hover {
  background: var(--surface-soft);
}

.nav-link:hover {
  color: var(--ink);
  background: var(--surface-soft);
}

.nav-link:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.danger-button:focus-visible,
.ghost-button:focus-visible,
.field input:focus-visible,
.field textarea:focus-visible,
.copy-row input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(244, 247, 251, 0.12);
  border-color: var(--muted-strong);
}

.section-heading,
.preview-header,
.note-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.section-heading {
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 0.25rem;
}

.section-heading > div,
.note-card-header > div,
.preview-header {
  min-width: 0;
}

.section-heading > div {
  display: grid;
  gap: 0.375rem;
}

.hero-card,
.panel,
.note-card,
.empty-state,
.auth-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-card,
.auth-card,
.empty-state {
  padding: 1.5rem;
}

.panel,
.note-card {
  padding: 1.25rem;
}

.panel:not(.markdown-body) {
  display: grid;
  gap: 0.875rem;
  align-content: start;
}

.accent-panel {
  background: #11161c;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.35;
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(2rem, 5vw, 2.625rem);
  font-weight: 700;
}

h2 {
  font-size: 1.2rem;
  font-weight: 650;
}

.lead,
.meta-line,
.muted {
  color: var(--muted);
}

.lead {
  margin: 0;
  line-height: 1.6;
}

.meta-line,
.muted {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.55;
}

.flash {
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  font-size: 0.9375rem;
}

.flash-success {
  background: var(--success-bg);
  color: var(--success);
}

.flash-error {
  background: var(--danger-bg);
  color: var(--danger);
}

.flash-info {
  background: var(--surface-soft);
}

.stack-form,
.notes-grid,
.viewer-stack {
  display: grid;
  gap: 1.25rem;
}

.field {
  display: grid;
  gap: 0.5rem;
}

.field span {
  display: block;
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.4;
}

.field input,
.field textarea,
.copy-row input {
  margin: 0;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.875rem;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.5;
  transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.field textarea {
  min-height: 21rem;
  resize: vertical;
}

.stack-form > .field + .field {
  margin-top: -0.125rem;
}

.field input::placeholder,
.field textarea::placeholder,
.copy-row input::placeholder {
  color: #66717f;
}

.actions,
.copy-row,
.toolbar-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.625rem;
}

.actions > * {
  flex-shrink: 0;
}

.copy-row {
  align-items: stretch;
}

.toolbar-row {
  align-items: center;
}

.copy-row input {
  flex: 1 1 16rem;
  min-width: 0;
}

.inline-form {
  display: inline-flex;
  margin: 0;
}

.hidden-form {
  display: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted-strong);
  font-size: 0.78rem;
  font-weight: 600;
}

.markdown-body {
  line-height: 1.7;
  color: var(--ink);
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin-top: 1.4em;
  margin-bottom: 0.45em;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre {
  margin: 0.8em 0;
}

.markdown-body code {
  padding: 0.12rem 0.32rem;
  border-radius: 6px;
  background: var(--surface-soft);
  font-size: 0.92em;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: break-spaces;
}

.markdown-body pre {
  overflow-x: auto;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
  color: var(--ink);
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
}

.markdown-body blockquote {
  margin-left: 0;
  padding-left: 0.875rem;
  border-left: 3px solid var(--line-strong);
  color: var(--muted);
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.4rem;
}

.content-narrow {
  width: 100%;
  max-width: 32rem;
  margin-inline: auto;
}

.content-wide {
  width: 100%;
}

.viewer-stack {
  width: 100%;
  max-width: 46rem;
}

.note-grid {
  display: grid;
  gap: 1rem;
  width: 100%;
  max-width: 72rem;
}

.note-grid > * {
  min-width: 0;
}

.note-editor-panel {
  align-content: start;
}

.note-preview-panel {
  align-content: start;
  min-height: 100%;
}

.note-share-stack {
  display: grid;
  gap: 0.875rem;
}

.empty-state {
  justify-items: start;
}

.empty-state .primary-button {
  width: fit-content;
}

.note-card,
.empty-state,
.auth-card,
.hero-card {
  display: grid;
  gap: 0.875rem;
}

.note-card {
  gap: 1rem;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.note-card:hover {
  border-color: var(--line-strong);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28), 0 20px 40px rgba(0, 0, 0, 0.22);
  transform: translateY(-1px);
}

.note-card-header > div {
  display: grid;
  gap: 0.25rem;
}

.preview-header {
  display: grid;
  gap: 0.5rem;
  align-content: start;
}

.preview-header-compact {
  gap: 0;
}

.preview-header p {
  margin: 0;
  color: var(--muted);
  max-width: 30ch;
}

.panel:not(.markdown-body) > p:not(.eyebrow),
.empty-state > p:not(.eyebrow),
.hero-card:not(.markdown-body) > p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.hero-card > :first-child,
.panel > :first-child,
.note-card > :first-child,
.empty-state > :first-child {
  margin-top: 0;
}

.hero-card > :last-child,
.panel > :last-child,
.note-card > :last-child,
.empty-state > :last-child {
  margin-bottom: 0;
}

.note-card h2 a:hover {
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.section-heading .actions {
  justify-content: flex-start;
}

.preview-panel .markdown-body {
  min-height: 9rem;
}

.preview-panel {
  background: linear-gradient(180deg, #171d24 0%, #13181e 100%);
}

html[data-theme="light"] .preview-panel {
  background: linear-gradient(180deg, #ffffff 0%, #f7f8fa 100%);
}

.preview-panel .markdown-body {
  display: grid;
  align-content: start;
  gap: 0.75rem;
}

.support-panel {
  padding: 1rem 1.125rem;
  gap: 0.75rem;
}

.panel > .actions,
.panel > .copy-row,
.panel > .toolbar-row {
  margin-top: 0.125rem;
}

.editor-layout > .panel:first-child {
  gap: 1.125rem;
}

.editor-layout .actions {
  padding-top: 0.125rem;
}

.empty-state h2,
.hero-card h1,
.section-heading h1 {
  max-width: 12ch;
}

.section-heading .primary-button,
.section-heading .secondary-button {
  margin-top: 0.125rem;
}

/* Wider screens can place the editor and note cards into multiple columns. */
@media (min-width: 860px) {
  .editor-layout {
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
    align-items: start;
  }

  .note-grid {
    grid-template-columns: minmax(0, 1.15fr) minmax(21rem, 0.85fr);
    align-items: start;
  }

  .note-editor-panel {
    grid-column: 1;
    grid-row: 1 / span 2;
  }

  .note-preview-panel {
    grid-column: 2;
    grid-row: 1;
  }

  .note-share-stack {
    grid-column: 2;
    grid-row: 2;
    align-content: start;
  }

  .notes-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
  }
}

/* Mobile keeps the layout stacked and buttons easy to tap without crowding. */
@media (max-width: 859px) {
  .site-header,
  .section-heading,
  .preview-header,
  .note-card-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .site-header {
    align-items: center;
  }

  .brand {
    text-align: center;
  }

  .site-header-controls {
    width: 100%;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
  }

  .site-nav {
    width: 100%;
    justify-content: center;
  }

  .site-nav .nav-link,
  .site-nav .ghost-button,
  .site-nav .inline-form,
  .site-nav .inline-form > button {
    min-height: 2.375rem;
    width: auto;
  }

  .page-shell {
    width: min(calc(100% - 1rem), var(--max-width));
  }

  .hero-card,
  .auth-card,
  .empty-state,
  .panel,
  .note-card {
    padding: 1rem;
  }

  .inline-form,
  .actions > * {
    width: 100%;
  }

  .inline-form > button,
  .inline-form > input,
  .actions > a,
  .actions > button {
    width: 100%;
  }

  .section-heading > a,
  .section-heading .actions,
  .section-heading .actions > *,
  .section-heading .inline-form,
  .section-heading .inline-form > button {
    width: auto;
  }

  .section-heading .actions {
    justify-content: flex-start;
  }

  .empty-state .primary-button {
    width: 100%;
  }

  .content-narrow,
  .viewer-stack {
    max-width: 100%;
  }
}
