/* =========================================================
   md.reader — tokens
   ========================================================= */
:root {
  --paper: #FAF8F2;
  --paper-dim: #F1EEE3;
  --ink: #1B1F23;
  --ink-soft: #3D4148;
  --slate: #6B7280;
  --line: #E2DFD2;
  --line-strong: #D2CDBC;
  --accent: #2A52E3;
  --accent-soft: #EAF0FF;
  --error: #B3401E;
  --error-soft: #FBEFEA;
  --card-bg: #FFFFFF;
  --code-bg: #1B1F23;
  --code-text: #F1EEE3;

  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;

  --radius: 4px;
  --max-width: 70%;
}

/* Dark mode — same identity, inverted: warm cream becomes a cool, near-black
   "ink well", and the off-white text keeps the same warm tint the light
   mode's background had. Accent blue is brightened to hold contrast. */
:root[data-theme="dark"] {
  --paper: #15171C;
  --paper-dim: #1C1F26;
  --ink: #ECEAE2;
  --ink-soft: #BFBCB1;
  --slate: #8B8A80;
  --line: #2A2D35;
  --line-strong: #3A3E48;
  --accent: #7C97FF;
  --accent-soft: #1E2540;
  --error: #FF8569;
  --error-soft: #2B1B17;
  --card-bg: #1B1E25;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  position: relative;
  transition: background-color 0.2s ease, color 0.2s ease;
}

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

.card, .dropzone, .link-input, .cta-btn, .ghost-btn, .back-btn,
.theme-toggle, .error-line, .md-content code, .render-bar, .topbar {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* the "compiling" sweep between source and rendered states */
.scan-line {
  position: fixed;
  left: 0;
  top: -4px;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  z-index: 50;
  pointer-events: none;
  opacity: 0;
}
.scan-line.run {
  animation: sweep 0.6s ease-in-out forwards;
}
@keyframes sweep {
  0%   { top: 0%;   opacity: 1; }
  90%  { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .scan-line.run { animation: none; }
}

/* =========================================================
   Top bar
   ========================================================= */
.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 90%;
  margin: 0 auto;
  padding: 28px 24px 0;
}
.logo {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  color: var(--ink);
}
.accent-dot { color: var(--accent); }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar-tag {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--slate);
  margin: 0;
}

/* theme toggle: a small circular switch in the topbar. Sun shows when dark
   mode is active (click to go light); moon shows in light mode (click to
   go dark) — the icon always signals what the click will do. */
.theme-toggle {
  position: relative;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper-dim);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.theme-toggle svg {
  position: absolute;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}
.theme-toggle .icon-sun circle { fill: currentColor; stroke: none; }
.theme-toggle .icon-moon { display: none; fill: currentColor; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* =========================================================
   Home view
   ========================================================= */
.home-view {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 64px 24px 48px;
}

.hero { margin-bottom: 48px; }
.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 14px;
}
.hero h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.1rem, 5vw, 3.1rem);
  line-height: 1.08;
  letter-spacing: -0.01em;
  margin: 0 0 16px;
  color: var(--ink);
}
.subhead {
  font-size: 1.05rem;
  color: var(--ink-soft);
  max-width: 46ch;
  margin: 0;
}

/* input row */
.input-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 22px;
  margin-bottom: 28px;
}
.card {
  border: 1px solid var(--line-strong);
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--slate);
  margin: 0;
}
.card-hint {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--slate);
  margin: 0;
  line-height: 1.5;
}

.divider {
  display: flex;
  align-items: center;
  justify-content: center;
}
.divider span {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--slate);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.dropzone {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-dim);
  padding: 26px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover,
.dropzone:focus-visible,
.dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dz-icon {
  font-size: 20px;
  color: var(--accent);
}
.dz-text {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--ink-soft);
}
.dz-text.has-file {
  color: var(--accent);
  font-weight: 500;
}

.clear-btn {
  align-self: flex-start;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--slate);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}
.clear-btn:hover { color: var(--error); }

.link-input {
  font-family: var(--mono);
  font-size: 13.5px;
  color: var(--ink);
  background: var(--paper-dim);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 12px;
  width: 100%;
}
.link-input:focus-visible {
  background: var(--card-bg);
}

/* CTA */
.cta-row {
  display: flex;
  margin-bottom: 18px;
}
.cta-btn {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14.5px;
  color: var(--paper);
  background: var(--ink);
  border: none;
  border-radius: var(--radius);
  padding: 13px 22px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin: auto;
}
.cta-btn:hover { background: var(--accent); }
.cta-btn:active { transform: translateY(1px); }
.cta-btn .arrow { transition: transform 0.15s; }
.cta-btn:hover .arrow { transform: translateX(2px); }
.cta-btn:disabled {
  background: var(--line-strong);
  color: var(--slate);
  cursor: progress;
}

.url-hint {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--slate);
  line-height: 1.6;
  margin: auto;
}
.url-hint code {
  background: var(--paper-dim);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11.5px;
  white-space: nowrap;
}

.error-line {
  margin-top: 16px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--error);
  border-left: 2px solid var(--error);
  padding: 8px 12px;
  background: var(--error-soft);
}

/* =========================================================
   Render view
   ========================================================= */
.render-view {
  position: relative;
  z-index: 1;
  min-height: 70vh;
}

.render-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 32px 24px 18px;
  border-bottom: 1px solid var(--line);
}
.back-btn {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-soft);
  background: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); }

.render-filename {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--slate);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.render-actions {
  display: flex;
  gap: 8px;
}
.ghost-btn {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--slate);
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }

/* =========================================================
   Rendered markdown typography (the "compiled" world)
   ========================================================= */
.md-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 40px 24px 100px;
  font-size: 1.05rem;
  color: var(--ink);
}
.md-content h1, .md-content h2, .md-content h3,
.md-content h4, .md-content h5, .md-content h6 {
  font-family: var(--serif);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.25;
  margin: 1.6em 0 0.6em;
}
.md-content h1 { font-size: 2.1rem; margin-top: 0; }
.md-content h2 { font-size: 1.55rem; border-top: 1px solid var(--line); padding-top: 0.9em; }
.md-content h3 { font-size: 1.25rem; }
.md-content h4 { font-size: 1.05rem; }

.md-content p { margin: 1em 0; }
.md-content a { color: var(--accent); text-decoration: underline; text-decoration-color: var(--line-strong); }
.md-content a:hover { text-decoration-color: var(--accent); }

.md-content strong { font-weight: 700; }
.md-content em { font-style: italic; }
.md-content del { color: var(--slate); }

.md-content code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--paper-dim);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.15em 0.4em;
}
.md-content pre {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--radius);
  padding: 16px 18px;
  overflow-x: auto;
  margin: 1.4em 0;
}
.md-content pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: 0.85em;
  line-height: 1.55;
}

.md-content blockquote {
  margin: 1.4em 0;
  padding: 2px 0 2px 18px;
  border-left: 3px solid var(--accent);
  color: var(--ink-soft);
  font-style: italic;
}

.md-content ul, .md-content ol {
  margin: 1em 0;
  padding-left: 1.4em;
}
.md-content li { margin: 0.35em 0; }

.md-content hr {
  border: none;
  border-top: 1px dashed var(--line-strong);
  margin: 2.2em 0;
}

.md-content img {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 1em 0;
}

.md-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4em 0;
  font-size: 0.92em;
}
.md-content th, .md-content td {
  border: 1px solid var(--line-strong);
  padding: 8px 10px;
  text-align: left;
}
.md-content th {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--paper-dim);
}

/* LaTeX (rendered by KaTeX after the markdown HTML is inserted) */
.md-content .math-display {
  margin: 1.4em 0;
  overflow-x: auto;
}
.md-content .katex { color: var(--ink); font-size: 1.05em; }
.md-content .katex-display { margin: 0.6em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

/* =========================================================
   Footer
   ========================================================= */
.footer {
  position: relative;
  z-index: 1;
  text-align: center;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--slate);
  padding: 22px 24px 36px;
}

/* =========================================================
   Responsiveness
   ========================================================= */

@media (max-width: 850px) {
  .topbar{
    max-width: 100%;
  }
  :root {
    --max-width: 90%;
  }
}

@media (max-width: 640px) {
  .input-row { grid-template-columns: 1fr; }
  .divider { padding: 4px 0; }
  :root {
    --max-width: 95%;
  }
}

@media (max-width: 560px) {
  .topbar-tag { 
    display: none;
  }
  .md-content {
    overflow-x: auto;
  }
}

@media (max-width: 420px) {
  .render-filename{
    display: none;
  }
}

@media (max-width: 366px) {
  .render-bar{
    max-width: 100%;
    padding-left: 10px;
    padding-right: 10px;
  }
}