@font-face {
  font-family: "Newsreader";
  src: url("./fonts/newsreader-normal.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Newsreader";
  src: url("./fonts/newsreader-italic.woff2") format("woff2");
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("./fonts/source-sans-3.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f3efe6;
  --bg-2: #f6dcc8;
  --well: #f6f1e6;
  --surface: #fffdf8;
  --ink: #1f1a14;
  --muted: #5e564c;
  --line: #e0d5c6;
  --track: #efe8dc;
  --accent: #b8431f;
  --accent-hover: #9a3418;
  --accent-ink: #fffaf6;
  --ok: #1f6b45;
  --select: #f3c4b0;
  --logo: #1f1a14;
  --logo-ink: #f6f1e7;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
  --serif: "Newsreader", "Iowan Old Style", Palatino, Georgia, serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12110f;
    --bg-2: #2a1c16;
    --well: #171512;
    --surface: #1e1b17;
    --ink: #f4efe6;
    --muted: #c4b8a8;
    --line: #3a332c;
    --track: #2a261f;
    --accent: #e07a45;
    --accent-hover: #e89268;
    --accent-ink: #1a100c;
    --ok: #9dceb4;
    --select: #6b3a28;
    --logo: #f4efe6;
    --logo-ink: #1c1916;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12110f;
  --bg-2: #2a1c16;
  --well: #171512;
  --surface: #1e1b17;
  --ink: #f4efe6;
  --muted: #c4b8a8;
  --line: #3a332c;
  --track: #2a261f;
  --accent: #e07a45;
  --accent-hover: #e89268;
  --accent-ink: #1a100c;
  --ok: #9dceb4;
  --select: #6b3a28;
  --logo: #f4efe6;
  --logo-ink: #1c1916;
}

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

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  min-height: 100%;
  background:
    radial-gradient(880px 420px at 100% -12%, var(--bg-2), transparent 58%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  caret-color: var(--accent);
  text-rendering: optimizeLegibility;
}

::selection { background: var(--select); color: var(--ink); }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 5;
  text-decoration: none;
}

.skip:focus { top: 12px; }

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

.app {
  max-width: 1160px;
  min-height: 100%;
  margin: 0 auto;
  padding: 20px 28px 28px;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.spool { width: 36px; height: 36px; flex: 0 0 auto; color: var(--logo); }

.brand .mark {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.625rem;
  font-weight: 560;
  letter-spacing: -0.03em;
  line-height: 1;
}

.tag {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.3;
}

.theme { margin-left: auto; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.12fr);
  gap: 20px;
  align-items: stretch;
  grid-template-rows: 1fr;
}

.layout > * { min-width: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.composer {
  background: var(--well);
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 7.5rem);
}

.composer label {
  display: block;
  margin: 2px 4px 8px;
  font-size: 0.8125rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--muted);
}

textarea {
  width: 100%;
  flex: 1 1 auto;
  min-height: 22rem;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: var(--surface);
  color: var(--ink);
  font: 0.9375rem/1.6 var(--mono);
  caret-color: var(--accent);
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

textarea::placeholder { color: var(--muted); opacity: 1; }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.composer .row { margin-top: 10px; }

.stats {
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  margin-right: auto;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  min-height: 44px;
  padding: 0 14px;
  font: 600 0.9375rem/1 var(--sans);
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--accent); }

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.tools { margin: 0 0 8px; }

#copy-md { margin-left: auto; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--track);
  border: 1px solid var(--line);
}

.tabs button {
  border: 0;
  background: transparent;
  min-height: 44px;
  padding: 0 14px;
  font-weight: 550;
  color: var(--muted);
}

.tabs button:hover:not(:disabled):not([aria-selected="true"]) {
  border-color: transparent;
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.tabs button[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  box-shadow: 0 1px 2px rgba(60, 32, 12, 0.14);
}

.paper {
  display: flex;
  flex-direction: column;
  padding: 14px 22px 16px;
  background: var(--surface);
}

#read-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sheet, .empty, .md { min-height: 0; }

.sheet {
  position: relative;
  padding: 18px 6px 8px;
}

.post-title,
.empty h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 2.125rem;
  font-weight: 560;
  letter-spacing: -0.03em;
  line-height: 1.14;
  text-wrap: balance;
}

.meta {
  margin: 0.45rem 0 1.15rem;
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.sheet p,
.sheet li {
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.55;
  margin: 0 0 0.85rem;
}

.lede::first-letter {
  font-size: 3.2rem;
  font-weight: 560;
  float: left;
  line-height: 0.78;
  padding: 0.08em 0.08em 0 0;
  color: var(--accent);
}

.sheet h2 {
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--ink);
  margin: 1.45rem 0 0.35rem;
}

.sheet blockquote {
  margin: 1.05rem 0 1.15rem;
  padding: 0;
  border: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 480;
  font-size: 1.3125rem;
  line-height: 1.35;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.sheet blockquote::before {
  content: "\201C";
  float: left;
  margin: 0.12em 0.12em 0 0;
  font-style: normal;
  font-weight: 560;
  font-size: 1.85rem;
  line-height: 0.7;
  color: var(--accent);
}

.sheet a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  overflow-wrap: anywhere;
}

.empty {
  flex: 1;
  padding: 12px 6px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.empty h1::after {
  content: "";
  display: block;
  width: 2.25rem;
  height: 2px;
  margin-top: 0.85rem;
  background: var(--accent);
  border-radius: 1px;
}

.empty p {
  margin: 0.85rem 0 0;
  max-width: 36ch;
  color: var(--muted);
  font-size: 1.0625rem;
  line-height: 1.5;
}

.empty.is-error h1 { color: var(--accent); }

.md {
  flex: 1;
  margin: 0;
  padding: 18px 6px 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 0.875rem/1.6 var(--mono);
  color: var(--ink);
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.foot {
  margin: 14px 2px 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

.status {
  min-height: 1.25rem;
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.status:empty {
  min-height: 0;
  margin: 0;
}

.status[data-kind="ok"] { color: var(--ok); }
.status[data-kind="err"] { color: var(--accent); }

@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: settle 200ms var(--ease); }
  button:active:not(:disabled) { transform: translateY(1px); }
}

@keyframes settle {
  from { filter: blur(3px); transform: translateY(6px); }
}

@media (max-width: 1080px) {
  .app { padding: 16px 16px 24px; }
  .layout { grid-template-columns: 1fr; grid-template-rows: none; gap: 16px; }
  .composer {
    position: static;
    max-height: none;
  }
  textarea { min-height: 11.5rem; }
  .tag { font-size: 0.8125rem; }
  .paper { padding: 12px 14px 14px; }
  .sheet { padding: 16px 2px 4px; }
  .post-title, .empty h1 { font-size: 1.75rem; }
  .sheet blockquote { font-size: 1.2rem; }
  .tools {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-bottom: 4px;
  }
  .tools .tabs {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .tools .tabs button { width: 100%; }
  .tools button { width: 100%; }
  #copy-md { grid-column: 1 / -1; margin-left: 0; }
  .composer .row {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .stats { grid-column: 1 / -1; margin-right: 0; }
  .empty { justify-content: flex-start; padding-top: 18px; }
}

@media (max-width: 380px) {
  .brand .mark { font-size: 1.35rem; }
  .spool { width: 32px; height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  button:active { transform: none; }
}

@media (forced-colors: active) {
  .panel { border: 1px solid CanvasText; }
  button.primary { background: ButtonText; color: ButtonFace; }
  .tabs button[aria-selected="true"] { border: 1px solid Highlight; }
}
