/* mdpage.app — minimal, reading-optimized styling. */

:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #656d76;
  --border: #d0d7de;
  --card: #ffffff;
  --accent: #1f6feb;
  --accent-fg: #ffffff;
  --code-bg: #f6f8fa;
  --banner-bg: #fff8c5;
  --banner-border: #d4a72c;
  --danger: #cf222e;
  --success: #1a7f37;
  --max-width: 760px;
}

/* Dark palette. Applied when the theme is forced to dark, OR in "auto" mode
   (no data-theme set) when the OS prefers dark. The two selectors below must
   stay in sync. data-theme="light" keeps the light :root defaults above. */
:root[data-theme='dark'] {
  --bg: #0d1117;
  --fg: #e6edf3;
  --muted: #9198a1;
  --border: #30363d;
  --card: #161b22;
  --accent: #4493f8;
  --code-bg: #161b22;
  --banner-bg: #2d2a1a;
  --banner-border: #9e8420;
  --danger: #f85149;
  --success: #3fb950;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']):not([data-theme='dark']) {
    --bg: #0d1117;
    --fg: #e6edf3;
    --muted: #9198a1;
    --border: #30363d;
    --card: #161b22;
    --accent: #4493f8;
    --code-bg: #161b22;
    --banner-bg: #2d2a1a;
    --banner-border: #9e8420;
    --danger: #f85149;
    --success: #3fb950;
  }
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must win over author display rules (flex/grid). */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif,
    'Apple Color Emoji', 'Segoe UI Emoji';
  line-height: 1.6;
  font-size: 17px;
}

/* Every page pins the footer to the bottom of short viewports. */
body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.25rem 0.5rem;
  width: 100%;
  flex: 1 0 auto;
}

/* Short pages (home upload view, message/404 pages) vertically center their
   content. The doc view can be long, so it stays top-aligned. */
body.home .container,
body.centered .container {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
body.home[data-view='doc'] .container {
  justify-content: flex-start;
}

/* On the home page the dropzone is the hero — drop the surrounding card
   chrome so it stands on its own. (Doc/result cards keep their border.) */
#input-view .card {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
}

a {
  color: var(--accent);
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.error {
  color: var(--danger) !important;
}

/* --- Hero / home --------------------------------------------------------- */
.hero {
  text-align: center;
  margin: 1rem 0 2rem;
}
.hero h1 {
  font-size: 2.8rem;
  margin: 0.2rem 0;
  letter-spacing: -0.02em;
}
.logo {
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 6px;
  padding: 0 0.25em;
}
.tagline {
  color: var(--fg);
  margin: 0.5rem 0 0;
}

/* --- Home: features / FAQ (indexable copy below the dropzone) ------------ */
.home-info {
  margin: 2.5rem auto 2rem;
  max-width: 44rem;
  border-top: 1px solid var(--border);
  padding-top: 2.5rem;
}
.home-info h2 {
  font-size: 1.3rem;
  margin: 2.5rem 0 0.75rem;
  letter-spacing: -0.01em;
}
.home-info h2:first-child {
  margin-top: 0;
}
.home-info h3 {
  font-size: 1rem;
  margin: 0 0 0.25rem;
}
.home-info p {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--muted);
}
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin: 1.5rem 0;
}
.faq-item {
  margin: 0 0 1.25rem;
}
.guide-links {
  margin: 0 0 0.75rem;
  padding-left: 1.1rem;
  font-size: 0.95rem;
  color: var(--muted);
}
.guide-links li {
  margin: 0.35rem 0;
}

/* --- Content / guide pages (indexable SEO landing pages) ----------------- */
.breadcrumb {
  max-width: 44rem;
  margin: 1rem auto 0;
  font-size: 0.9rem;
}
.breadcrumb a {
  color: var(--muted);
  text-decoration: none;
}
.breadcrumb a:hover {
  color: var(--fg);
}
.content-page {
  max-width: 44rem;
  margin: 1.25rem auto 2rem;
}
.content-page h1 {
  font-size: 2rem;
  letter-spacing: -0.02em;
  margin: 0.25rem 0 0.75rem;
}
.content-page h2 {
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  margin: 2rem 0 0.75rem;
}
.content-page h3 {
  font-size: 1rem;
  margin: 1.25rem 0 0.25rem;
}
.content-page p,
.content-page li {
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--muted);
}
.content-page ol,
.content-page ul {
  padding-left: 1.25rem;
}
.content-page li {
  margin: 0.35rem 0;
}
.content-page code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05em 0.35em;
  white-space: pre-wrap;
}
.content-page table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}
.content-page th,
.content-page td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.6rem;
  text-align: left;
  vertical-align: top;
}
.content-page th {
  background: var(--card);
}
/* Markdown-source column: render each snippet as one clean code block so
   multi-line examples don't break the inline <code> border across lines. */
.content-page td pre {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  overflow-x: auto;
}
.content-page td pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: none;
  border: 0;
  border-radius: 0;
  padding: 0;
  white-space: pre;
}
.cta-row {
  margin: 1.5rem 0;
}
.cta {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
}
.cta:hover {
  filter: brightness(1.05);
}
.page-nav {
  max-width: 44rem;
  margin: 0 auto 2.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
}
.page-nav h2 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
}
.page-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.page-nav li {
  margin: 0.3rem 0;
}

/* --- Cards --------------------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin: 1.25rem 0;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 2.5rem 1rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover,
.dropzone:focus-visible,
.dropzone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  outline: none;
}

.paste-box {
  margin-top: 1rem;
}
.paste-box summary {
  cursor: pointer;
  color: var(--muted);
}
textarea#paste {
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
}

.drop-icon {
  color: var(--muted);
  opacity: 0.7;
  margin-bottom: 0.25rem;
}

/* Text-styled buttons (act like links). */
button.linklike {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
}
button.linklike:hover {
  text-decoration: underline;
}

/* "Load an example · Paste or type" row under the dropzone. */
.input-alt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 1rem;
  font-size: 0.95rem;
}
.input-alt .sep {
  color: var(--muted);
}
@media (max-width: 420px) {
  .input-alt {
    flex-direction: column;
    gap: 0.4rem;
  }
  .input-alt .sep {
    display: none;
  }
}

#paste-area {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
}
.paste-actions {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

/* Right side of the doc-view toolbar: meta + Turnstile + Create button. */
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.toolbar-right .create-btn {
  padding: 0.45rem 0.9rem;
  font-size: 0.95rem;
}
/* The invisible Turnstile widget shouldn't reserve an empty gap;
   it expands automatically only if an interactive challenge appears. */
.cf-turnstile:empty {
  display: none;
}

.create-status {
  margin: 0.75rem 0 0;
}
.create-status:empty {
  display: none;
}

/* Spinner badge shown on a code block while Shiki lazy-loads. */
pre.code-loading {
  position: relative;
}
.hl-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 9px 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.hl-badge::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: hl-spin 0.7s linear infinite;
}
@keyframes hl-spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .hl-badge::before {
    animation: none;
  }
}

/* Doc-view toolbar reuses .doc-toolbar from the shared page. */
#doc-view .doc-toolbar {
  margin-bottom: 1rem;
}

button.primary,
.primary-link {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button.danger {
  background: var(--danger);
}

/* --- Result -------------------------------------------------------------- */
.result h2 {
  margin-top: 0;
}
.result-back {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}
.result .success-check {
  color: var(--success);
  margin-right: 0.35rem;
}
.link-row {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0;
}
.link-row input {
  flex: 1;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
}
.link-row button {
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
  font-weight: 600;
}
.delete-box {
  margin-top: 1rem;
}
.delete-box summary {
  cursor: pointer;
}

/* --- Document view ------------------------------------------------------- */
.ugc-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  background: var(--banner-bg);
  border: 1px solid var(--banner-border);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.ugc-notice {
  flex: 1 1 18rem;
}
.ugc-expiry {
  flex-shrink: 0;
  color: var(--muted);
  white-space: nowrap;
}
.doc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}
.doc-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.doc-actions .report {
  color: var(--muted);
}

/* Download dropdown. */
.download-menu {
  position: relative;
}
.download-menu > summary {
  cursor: pointer;
  color: var(--accent);
  list-style: none;
}
.download-menu > summary::-webkit-details-marker {
  display: none;
}
.download-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 170px;
  padding: 0.35rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}
.download-list > a,
.download-list > button {
  text-align: left;
  background: none;
  border: none;
  font: inherit;
  color: var(--fg);
  text-decoration: none;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
}
.download-list > a:hover,
.download-list > button:hover {
  background: var(--code-bg);
}
.download-list > button:disabled {
  opacity: 0.6;
  cursor: default;
}

.message h1 {
  margin-top: 0;
}

/* --- Footer -------------------------------------------------------------- */
.site-footer p {
  margin: 0.3rem 0;
}
.site-footer .version {
  white-space: nowrap;
  opacity: 0.7;
}
.site-footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.5rem 1.25rem 2rem;
  width: 100%;
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
.site-footer.bordered {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
/* Keep footer text clear of the floating theme toggle on narrow screens
   (symmetric padding so the centered text stays centered). */
@media (max-width: 600px) {
  .site-footer {
    padding-left: 4rem;
    padding-right: 4rem;
  }
}

/* --- Rendered markdown --------------------------------------------------- */
.markdown-body {
  word-wrap: break-word;
}
.markdown-body > *:first-child {
  margin-top: 0;
}
.markdown-body h1,
.markdown-body h2 {
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
}
/* A doc that starts with a heading would draw its rule right under the
   toolbar's border — two lines a few pixels apart. Drop the first one.
   Screen only: print hides the toolbar, so the underline stays there. */
@media screen {
  .markdown-body > h1:first-child,
  .markdown-body > h2:first-child {
    padding-bottom: 0;
    border-bottom: none;
  }
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 1.6em 0 0.6em;
  line-height: 1.25;
  font-weight: 600;
}
.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body table {
  margin: 0 0 1rem;
}
.markdown-body blockquote {
  margin-left: 0;
  padding: 0 1em;
  color: var(--muted);
  border-left: 0.25em solid var(--border);
}
.markdown-body img {
  max-width: 100%;
  height: auto;
}
.markdown-body table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
}
.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 0.4em 0.75em;
}
.markdown-body th {
  background: var(--code-bg);
}
.markdown-body :not(pre) > code {
  background: var(--code-bg);
  padding: 0.2em 0.4em;
  border-radius: 6px;
  font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.markdown-body pre {
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.5;
}
/* Plain (un-highlighted) preview code blocks. */
.markdown-body pre:not(.shiki) {
  background: var(--code-bg);
}
/* Shiki's github-light background is #fff — invisible against the page.
   Use the standard code background instead (the dark-mode swap rules below
   are more specific, so the dark Shiki background still wins there). */
.markdown-body pre.shiki {
  background: var(--code-bg) !important;
}
.markdown-body pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.markdown-body input[type='checkbox'] {
  margin-right: 0.4em;
}
.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* Shiki dual-theme: swap to the dark token colors when the theme is dark.
   Mirrors the palette selectors above (forced-dark OR auto + system dark). */
:root[data-theme='dark'] .shiki,
:root[data-theme='dark'] .shiki span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']):not([data-theme='dark']) .shiki,
  :root:not([data-theme='light']):not([data-theme='dark']) .shiki span {
    color: var(--shiki-dark) !important;
    background-color: var(--shiki-dark-bg) !important;
  }
}

/* Floating light/dark/auto toggle (shared across pages via the layout). */
.theme-toggle {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 50;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}
/* All three icons are in the markup; show the one matching the current theme
   (no data-theme attribute = auto, same convention as the palette rules). */
.theme-toggle svg {
  display: none;
}
:root:not([data-theme='light']):not([data-theme='dark']) .theme-toggle .icon-auto,
:root[data-theme='light'] .theme-toggle .icon-light,
:root[data-theme='dark'] .theme-toggle .icon-dark {
  display: block;
}
.theme-toggle:hover {
  border-color: var(--accent);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Print / "Save as PDF": print ONLY the rendered document — no banner,
   toolbar, footer, or theme toggle. Forced to a light, ink-friendly look. */
@media print {
  .ugc-banner,
  .doc-toolbar,
  .site-footer,
  .theme-toggle {
    display: none !important;
  }
  body {
    background: #fff !important;
    color: #000 !important;
    /* The flex-column body (footer pinning) confuses WebKit's print
       fragmentation and can truncate long docs to one page. Paper needs
       no footer pinning; restore plain block flow. */
    display: block;
    min-height: 0;
  }
  .container {
    max-width: none;
    margin: 0;
    padding: 0;
  }
  .markdown-body {
    font-size: 11.5pt;
  }
  .markdown-body a {
    color: #000;
    text-decoration: underline;
  }
  /* Keep code/light Shiki colors; just avoid awkward page breaks. */
  .markdown-body pre,
  .markdown-body table,
  .markdown-body img {
    break-inside: avoid;
  }
  .markdown-body h1,
  .markdown-body h2,
  .markdown-body h3 {
    break-after: avoid;
  }
}
