:root {
  --bg: #f8f7f3;
  --surface: #ffffff;
  --ink: #1c1c1a;
  --ink-soft: #2d2d2a;
  --ink-muted: #807d75;
  --ink-faint: #b8b5ac;
  --hairline: #e5e2d9;
  --code-bg: #f0ede4;
  --error: #8b2c2c;

  --font-serif: 'Instrument Serif', 'Iowan Old Style', 'Palatino', serif;
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --pad-x: 36px;
  --pad-x-mobile: 20px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─────────────────────────────────  Header  ───────────────────────────────── */

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 22px var(--pad-x) 14px;
  border-bottom: 1px solid var(--hairline);
  animation: fadeUp 600ms cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.brand {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 30px;
  line-height: 1;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.brand em {
  font-style: italic;
}

.tagline {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 15px;
  line-height: 1.35;
  color: var(--ink-muted);
  letter-spacing: 0.005em;
}

.tagline em {
  color: var(--ink);
}

.brand-arrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.55em;
  font-style: normal;
  margin: 0 0.35em;
  color: var(--ink-faint);
  position: relative;
  top: -0.32em;
  font-weight: 400;
  letter-spacing: 0;
}

.repo-link {
  flex-shrink: 0;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
  transition: color 200ms ease, border-color 200ms ease;
}

.repo-link:hover {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

/* ─────────────────────────────────  Workspace  ───────────────────────────────── */

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  animation: fadeUp 700ms 100ms cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

.pane--input  { background: var(--bg); }
.pane--preview {
  background: var(--surface);
  border-left: 1px solid var(--hairline);
}

.pane-label {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 22px var(--pad-x) 10px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-muted);
  user-select: none;
}

.pane-num {
  font-variant-numeric: tabular-nums;
  color: var(--ink-faint);
}

/* ─────────────────────────────────  Input  ───────────────────────────────── */

#md-input {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.75;
  color: var(--ink);
  padding: 6px var(--pad-x) 28px;
  resize: none;
  tab-size: 2;
  -webkit-font-smoothing: antialiased;
}

#md-input::selection {
  background: var(--ink);
  color: var(--bg);
}

#md-input::placeholder {
  color: var(--ink-faint);
}

/* Scrollbars — desaturated, thin */
#md-input,
.preview {
  scrollbar-width: thin;
  scrollbar-color: var(--ink-faint) transparent;
}

#md-input::-webkit-scrollbar,
.preview::-webkit-scrollbar {
  width: 8px;
}

#md-input::-webkit-scrollbar-thumb,
.preview::-webkit-scrollbar-thumb {
  background: var(--ink-faint);
  border-radius: 4px;
  border: 2px solid var(--bg);
}

.pane--preview .preview::-webkit-scrollbar-thumb {
  border-color: var(--surface);
}

/* ─────────────────────────────────  Preview  ───────────────────────────────── */

.preview {
  flex: 1;
  overflow-y: auto;
  padding: 6px var(--pad-x) 28px;
  line-height: 1.65;
  color: var(--ink);
}

.preview > *:first-child { margin-top: 0; }
.preview > *:last-child { margin-bottom: 0; }

.preview h1, .preview h2, .preview h3,
.preview h4, .preview h5, .preview h6 {
  font-family: var(--font-serif);
  font-weight: 400;
  letter-spacing: -0.015em;
  margin: 1.4em 0 0.4em;
  line-height: 1.15;
  color: var(--ink);
}

.preview h1 { font-size: 36px; }
.preview h2 { font-size: 26px; }
.preview h3 { font-size: 20px; font-style: italic; }
.preview h4 { font-size: 17px; font-family: var(--font-sans); font-weight: 500; text-transform: uppercase; letter-spacing: 0.1em; }

.preview p { margin: 0.7em 0; }

.preview strong { font-weight: 500; }
.preview em { font-family: var(--font-serif); font-size: 1.05em; }

.preview a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--ink-faint);
  transition: text-decoration-color 200ms ease;
}
.preview a:hover { text-decoration-color: var(--ink); }

.preview ul, .preview ol {
  padding-left: 1.6em;
  margin: 0.7em 0;
}

.preview li { margin: 0.25em 0; }
.preview li::marker { color: var(--ink-faint); }

.preview code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--code-bg);
  padding: 0.12em 0.4em;
  border-radius: 2px;
}

.preview pre {
  background: var(--code-bg);
  padding: 16px 20px;
  overflow-x: auto;
  margin: 1em 0;
  border-radius: 3px;
  line-height: 1.55;
}
.preview pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}

.preview blockquote {
  border-left: 2px solid var(--ink-faint);
  margin: 1em 0;
  padding: 0.2em 0 0.2em 1.2em;
  color: var(--ink-soft);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 19px;
  line-height: 1.45;
}

.preview blockquote p { margin: 0.3em 0; }

.preview table {
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 14px;
  width: 100%;
}
.preview th, .preview td {
  border-bottom: 1px solid var(--hairline);
  padding: 9px 14px;
  text-align: left;
  vertical-align: top;
}
.preview th {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
}

.preview hr {
  border: none;
  border-top: 1px solid var(--hairline);
  margin: 2em 0;
}

.preview img { max-width: 100%; }

/* ─────────────────────────────────  Actions  ───────────────────────────────── */

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px var(--pad-x);
  border-top: 1px solid var(--hairline);
  background: var(--bg);
  gap: 24px;
  animation: fadeUp 800ms 200ms cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.hint {
  font-size: 13px;
  color: var(--ink-muted);
  font-family: var(--font-sans);
  letter-spacing: 0.01em;
}

.hint em {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 15px;
  color: var(--ink);
  margin-right: 2px;
}

.copy-btn {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  background: var(--ink);
  color: var(--bg);
  border: 1px solid var(--ink);
  padding: 13px 22px 13px 24px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 18px;
  transition: background 180ms ease, transform 100ms ease, letter-spacing 220ms ease;
}

.copy-btn:hover {
  background: var(--ink-soft);
  letter-spacing: 0.22em;
}

.copy-btn:active {
  transform: translateY(1px);
}

.copy-btn:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.copy-shortcut {
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  font-weight: 400;
  padding-left: 14px;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
}

/* ─────────────────────────────────  Toast  ───────────────────────────────── */

.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  padding: 11px 22px;
  opacity: 0;
  transform: translate(-50%, -16px);
  pointer-events: none;
  transition: opacity 250ms ease, transform 250ms ease;
  z-index: 100;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error { background: var(--error); }

/* ─────────────────────────────────  Motion  ───────────────────────────────── */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

/* ─────────────────────────────────  Responsive  ───────────────────────────────── */

@media (max-width: 760px) {
  :root { --pad-x: var(--pad-x-mobile); }

  html, body { overflow: auto; }
  body { height: auto; min-height: 100vh; }

  .header { padding: 16px var(--pad-x) 12px; gap: 16px; }
  .brand { font-size: 24px; }
  .tagline { font-size: 13px; line-height: 1.4; }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(50vh, auto) minmax(40vh, auto);
  }

  .pane--preview { border-left: none; border-top: 1px solid var(--hairline); }

  .pane-label { padding-top: 18px; padding-bottom: 8px; }

  .actions {
    flex-direction: column;
    align-items: stretch;
    padding: 14px var(--pad-x);
    gap: 12px;
  }

  .hint { text-align: center; }

  .copy-btn { width: 100%; justify-content: center; padding: 14px; }
  .copy-shortcut { display: none; }
}
