/* ============================================================
   meowmd - page styles
   tokens.css, components.css and cursor.css load before this file.
   Everything here is screen layout plus the pieces the system does
   not ship: the editor chrome, the table of contents geometry, the
   prism theme and the preview extras.
   ============================================================ */

/* ---------- shell ---------- */

/* the page never scrolls: the shell owns the viewport, the preview is
   the scroller */
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.layout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* the main column stays transparent: the sky shows in the gap around
   the card */
.main-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- app bar ---------- */

.app-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--navbar-h);
  padding-inline: var(--space-5);
  border-bottom: 1px solid var(--line-soft);
  flex-shrink: 0;
}

/* both side zones flex equally, so the title sits on the bar's centre */
.app-bar-title {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  justify-content: center;
}

.title-input {
  max-width: 22rem;
  text-align: center;
}

.app-bar-actions {
  flex: 1 1 0;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* ---------- editor shell ---------- */

.editor-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--space-5);
  overflow: hidden;
}

/* the one raised surface: the card line stays, the padding goes */
.editor-shell.card {
  flex: 1;
  min-height: 0;
  display: flex;
  padding: 0;
  overflow: hidden;
}

/* The fold is the row's own geometry, the named deviation the sidebar rail
   already carries: no transform reflows the pane beside it. */
.input-pane {
  display: flex;
  flex-direction: column;
  min-width: 240px;
  width: 50%;
  flex-shrink: 0;
  overflow: hidden;
  transition:
    width var(--dur-far) var(--ease-out),
    min-width var(--dur-far) var(--ease-out),
    opacity var(--dur-far) var(--ease-out);
}

body.resizing .input-pane { transition: none; }

.preview-pane {
  flex: 1;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition:
    opacity var(--dur-far) var(--ease-out),
    min-width var(--dur-far) var(--ease-out);
}

/* view modes: the collapsed pane folds away, the other fills the space.
   Entering a mode is an entrance, leaving it an exit at 0.6x. */
.editor-shell[data-mode="markdown"] .input-pane { width: 100%; }

.editor-shell[data-mode="markdown"] .preview-pane {
  min-width: 0;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--dur-out-far) var(--ease),
    min-width var(--dur-out-far) var(--ease),
    visibility 0s var(--dur-out-far);
}

.editor-shell[data-mode="preview"] .input-pane {
  width: 0;
  min-width: 0;
  opacity: 0;
  visibility: hidden;
  transition:
    width var(--dur-out-far) var(--ease),
    min-width var(--dur-out-far) var(--ease),
    opacity var(--dur-out-far) var(--ease),
    visibility 0s var(--dur-out-far);
}

.editor-shell[data-mode="markdown"] .resizer,
.editor-shell[data-mode="preview"] .resizer {
  width: 0;
  visibility: hidden;
  transition:
    width var(--dur-out-far) var(--ease),
    background var(--dur-tint) var(--ease),
    visibility 0s var(--dur-out-far);
}

/* ---------- pane heads ---------- */

.pane-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-3);
  border-bottom: 1px solid var(--line-soft);
  flex-shrink: 0;
}

.word-count {
  font: 400 var(--t-1)/1 var(--font-mono);
  color: var(--text-4);
  white-space: nowrap;
  margin-inline-start: auto;
}

.pane-head-actions {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* the scroll-sync toggle's on state */
.pane-head .btn[aria-pressed="true"] {
  color: var(--accent-text);
  border-color: var(--accent-line);
  background: var(--accent-quiet);
  --tint-ground: transparent;
}

/* ---------- editor overlay ---------- */

.editor-highlight-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: var(--well);
}

/* the input family's focus recipe: a 1px accent edge with the 3px halo */
.editor-highlight-wrap:focus-within {
  box-shadow:
    inset 0 0 0 1px var(--accent),
    inset 0 0 0 4px var(--accent-line);
}

/* the textarea and the overlay share every metric, or the highlight drifts */
.markdown-input,
.editor-highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: var(--space-4);
  font: 400 var(--t-3)/1.55 var(--font-mono);
  letter-spacing: normal;
  tab-size: 8;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  box-sizing: border-box;
}

.markdown-input {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--text);
  resize: none;
  outline: none;
  z-index: 1;
}

.markdown-input::placeholder {
  color: var(--text-placeholder);
  -webkit-text-fill-color: var(--text-placeholder);
}

.markdown-input::selection {
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  background: var(--accent-quiet);
}

/* without prism the overlay is not painted, so the field's own text shows */
.editor-highlight-wrap.no-highlight .markdown-input {
  color: var(--text);
  -webkit-text-fill-color: var(--text);
}

.editor-highlight {
  background: transparent;
  border: none;
  color: var(--text);
  pointer-events: none;
  overflow: hidden;
}

.editor-highlight code {
  font: inherit;
  color: inherit;
  background: transparent;
}

/* ---------- resizer ---------- */

.resizer {
  width: 1px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  background: var(--line-soft);
  transition:
    width var(--dur-far) var(--ease-out),
    background var(--dur-tint) var(--ease);
}

/* the hit area is wider than the painted line */
.resizer::after {
  content: "";
  position: absolute;
  inset: 0 -4px;
}

.resizer:hover,
.resizer:focus-visible {
  background: var(--accent);
}

/* no cursor override here: the shipped hidden-cursor rule must win */
body.resizing,
body.resizing * { user-select: none; }

/* ---------- preview ---------- */

.preview-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-5) var(--space-6);
  padding-bottom: var(--space-16);
}

.preview-content .prose { margin-inline: auto; }

/* a focusable scroller inside the card: the global outline is clipped by the
   card's edge, so the ring moves inside the scrollport */
.preview-content:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* ---------- table of contents ---------- */

.toc-empty {
  padding: 0 var(--space-2) var(--space-3);
  font-size: var(--t-2);
  color: var(--text-4);
}

/* the level indent rides the rail: full when the column is expanded,
   gone when folded, so the rail's 40px pills keep their centred dots */
.sidebar .nav-item {
  --indent: 0px;
  padding-inline-start: calc(var(--space-2) + 9px * (1 - var(--rail)) + var(--indent) * var(--rail));
}

.sidebar .toc-level-2 { --indent: var(--space-3); }
.sidebar .toc-level-3 { --indent: var(--space-6); }

/* ---------- heading anchors ---------- */

.heading-anchor {
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--text-4);
  margin-inline-start: var(--space-2);
  vertical-align: middle;
  opacity: 0;
  transition: opacity var(--dur-tint) var(--ease);
}

.prose :is(h1, h2, h3):hover .heading-anchor,
.heading-anchor:focus-visible { opacity: 1; }

/* no hover to reveal them on touch: they stay visible, and the box takes
   the tap floor the way the shipped controls do */
@media (hover: none) {
  .heading-anchor { opacity: 1; }
}

@media (pointer: coarse) {
  .heading-anchor {
    width: var(--ctl-lg);
    min-width: var(--ctl-lg);
    height: var(--ctl-lg);
    min-height: var(--ctl-lg);
  }
  /* the head grows to fit its floor-sized control */
  .pane-head {
    height: auto;
    min-height: var(--ctl-lg);
  }
}

/* ---------- code blocks ---------- */

.code-block { margin-block: var(--space-4); }

.code-head { cursor: pointer; }

.collapse-arrow {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  color: var(--text-4);
  transition: transform var(--dur-tint) var(--ease);
}

.collapse-arrow.collapsed { transform: rotate(-90deg); }

/* the collapse's travel is its own block size, the accordion's named
   deviation: a transform on the body would not shorten the flow around it */
.code-content {
  overflow: hidden;
  transition: max-height var(--dur-far) var(--ease);
}

.code-content.mermaid-rendered {
  padding: var(--space-4);
  background: var(--well);
  --tint-ground: transparent;
}

.code-content.mermaid-rendered svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

/* ---------- callouts ---------- */

.callout { margin-block: var(--space-4); }

/* ---------- footnotes ---------- */

.prose section.footnotes {
  margin-top: var(--space-12);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
  font-size: var(--t-2);
  color: var(--text-3);
}

.prose section.footnotes ol {
  padding-inline-start: 1.4em;
  margin-bottom: 0;
}

.prose section.footnotes li { margin-bottom: var(--space-2); }
.prose section.footnotes li > p { margin-bottom: 0; }

.prose sup a[data-footnote-ref] {
  color: var(--accent-text);
  text-decoration: none;
  font-weight: 500;
  padding: 0 1px;
  margin-left: 1px;
}

.prose sup a[data-footnote-ref]:hover {
  text-decoration: underline;
  background: var(--accent-quiet);
}

.prose a[data-footnote-backref] {
  color: var(--text-4);
  text-decoration: none;
  font-size: var(--t-1);
  margin-left: var(--space-1);
}

.prose a[data-footnote-backref]:hover { color: var(--accent-text); }

/* ---------- task lists ---------- */

.prose input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.prose input[type="checkbox"]:hover {
  outline: 2px solid var(--accent-line);
  outline-offset: 1px;
}

/* ---------- scroll to top ---------- */

.scroll-to-top {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition:
    background var(--dur-tint) var(--ease),
    border-color var(--dur-tint) var(--ease),
    color var(--dur-tint) var(--ease),
    opacity var(--dur-near) var(--ease-out),
    transform var(--dur-near) var(--ease-out),
    visibility 0s var(--dur-near);
}

.scroll-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ---------- the brand mark ---------- */

/* the cat replaces the striped placeholder and takes the accent */
.sidebar-logo .sona {
  width: 28px;
  height: 28px;
  background-image: none;
  color: var(--accent);
}

.sidebar-logo .sona svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- the prism theme ---------- */

:root {
  --prism-comment: var(--text-4);
  --prism-punctuation: var(--text-3);
  --prism-keyword: var(--cat-mauve);
  --prism-string: var(--cat-green);
  --prism-number: var(--cat-peach);
  --prism-function: var(--cat-blue);
  --prism-class: var(--cat-sapphire);
  --prism-tag: var(--cat-red);
  --prism-attr: var(--cat-teal);
  --prism-operator: var(--cat-sky);
  --prism-boolean: var(--cat-yellow);
  --prism-regex: var(--cat-yellow);
  --prism-builtin: var(--cat-lavender);
  --prism-property: var(--cat-blue);
  --prism-interpolation: var(--cat-pink);
  --prism-atrule: var(--cat-green);
}

/* the ramp's light values sit under the 4.5:1 floor on --well, so the
   ramp-derived tokens clamp their lightness there; the two text-token
   steps are already theme-aware and stay */
[data-theme="light"] {
  --prism-keyword: oklch(from var(--cat-mauve) min(l, 0.48) c h);
  --prism-string: oklch(from var(--cat-green) min(l, 0.48) c h);
  --prism-number: oklch(from var(--cat-peach) min(l, 0.48) c h);
  --prism-function: oklch(from var(--cat-blue) min(l, 0.48) c h);
  --prism-class: oklch(from var(--cat-sapphire) min(l, 0.48) c h);
  --prism-tag: oklch(from var(--cat-red) min(l, 0.48) c h);
  --prism-attr: oklch(from var(--cat-teal) min(l, 0.48) c h);
  --prism-operator: oklch(from var(--cat-sky) min(l, 0.48) c h);
  --prism-boolean: oklch(from var(--cat-yellow) min(l, 0.48) c h);
  --prism-regex: oklch(from var(--cat-yellow) min(l, 0.48) c h);
  --prism-builtin: oklch(from var(--cat-lavender) min(l, 0.48) c h);
  --prism-property: oklch(from var(--cat-blue) min(l, 0.48) c h);
  --prism-interpolation: oklch(from var(--cat-pink) min(l, 0.48) c h);
  --prism-atrule: oklch(from var(--cat-green) min(l, 0.48) c h);
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata { color: var(--prism-comment); }
.token.punctuation { color: var(--prism-punctuation); }
.token.namespace { color: var(--prism-comment); }
.token.keyword,
.token.selector,
.token.important { color: var(--prism-keyword); }
.token.string,
.token.char,
.token.attr-value,
.token.inserted,
.token.template-string { color: var(--prism-string); }
.token.number { color: var(--prism-number); }
.token.function,
.token.maybe-class-name,
.token.function-variable { color: var(--prism-function); }
.token.class-name,
.token.type-name { color: var(--prism-class); }
.token.tag,
.token.deleted { color: var(--prism-tag); }
.token.attr-name,
.token.attribute,
.token.variable,
.token.parameter { color: var(--prism-attr); }
.token.operator,
.token.entity { color: var(--prism-operator); }
.token.boolean { color: var(--prism-boolean); }
.token.regex { color: var(--prism-regex); }
.token.builtin,
.token.constant { color: var(--prism-builtin); }
.token.property { color: var(--prism-property); }
.token.interpolation,
.token.template-punctuation { color: var(--prism-interpolation); }
.token.atrule,
.token.url { color: var(--prism-atrule); }
.token.url .token.function { color: var(--prism-attr); }
.token.url .token.punctuation { color: var(--prism-punctuation); }

/* markdown tokens in the editor overlay */
.editor-highlight .token.title { color: var(--prism-function); }
.editor-highlight .token.bold { font-weight: 600; color: var(--prism-keyword); }
.editor-highlight .token.italic { font-style: italic; color: var(--prism-builtin); }
.editor-highlight .token.strike { text-decoration: line-through; color: var(--prism-comment); }
.editor-highlight .token.code-snippet { color: var(--prism-string); }
.editor-highlight .token.code-language { color: var(--prism-comment); }

/* ---------- mobile ---------- */

@media (max-width: 768px) {
  .mobile-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  /* the app bar wraps to two rows: title full width, then modes + actions */
  .app-bar {
    flex-wrap: wrap;
    height: auto;
    padding-block: var(--space-2);
    justify-content: space-between;
    gap: var(--space-2);
  }
  /* the segment's side padding is costume, not the tap floor: trimmed so the
     modes and actions share one row from 390px of viewport up */
  .app-bar .tab-box { padding-inline: var(--space-2); }
  .app-bar-title { flex: 1 0 100%; order: -1; }
  .app-bar-actions { flex: 0 0 auto; }

  .editor-area { padding: var(--space-3); }
  .preview-content {
    padding: var(--space-5) var(--space-4);
    padding-bottom: var(--space-16);
  }
  .scroll-to-top { bottom: var(--space-4); right: var(--space-4); }

  /* the panes stack and the split moves vertically */
  .editor-shell { flex-direction: column; }
  .editor-shell[data-mode] .input-pane { width: 100%; }
  .input-pane {
    height: 45vh;
    min-width: 0;
    flex-shrink: 0;
    transition:
      height var(--dur-far) var(--ease-out),
      opacity var(--dur-far) var(--ease-out);
  }
  .editor-shell[data-mode="markdown"] .input-pane { height: 100%; }
  .editor-shell[data-mode="preview"] .input-pane {
    height: 0;
    min-height: 0;
    opacity: 0;
    visibility: hidden;
    transition:
      height var(--dur-out-far) var(--ease),
      opacity var(--dur-out-far) var(--ease),
      visibility 0s var(--dur-out-far);
  }
  .preview-pane { min-width: 0; min-height: 0; }
  .resizer { display: none; }

  /* 16px so iOS does not auto-zoom on focus; both layers stay identical */
  .markdown-input,
  .editor-highlight { font-size: var(--t-4); }
}

/* ---------- reduced motion: fades stay, travel snaps ---------- */

@media (prefers-reduced-motion: reduce) {
  .scroll-to-top,
  .collapse-arrow,
  .code-content,
  .heading-anchor,
  .editor-shell[data-mode] .input-pane,
  .editor-shell[data-mode] .preview-pane,
  .editor-shell[data-mode] .resizer {
    transition: none;
  }
  .scroll-to-top { transform: translateY(8px); }
  .scroll-to-top.visible { transform: translateY(0); }
}

/* ---------- print: the preview, flattened ---------- */

@media print {
  .sidebar,
  .app-bar,
  .mobile-topbar,
  .sidebar-overlay,
  .pane-head,
  .input-pane,
  .resizer,
  .toast-stack,
  .scroll-to-top,
  .skip-link {
    display: none !important;
  }

  body { display: block; height: auto; overflow: visible; }

  .layout,
  .main-col,
  .editor-area,
  .editor-shell,
  .preview-pane,
  .preview-content {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* whatever mode is active, the preview prints */
  .preview-pane {
    opacity: 1 !important;
    visibility: visible !important;
  }

  .editor-shell.card { box-shadow: none; }
  .editor-area { padding: 0; }
  .preview-content { padding: 0 !important; }
  .preview-content .prose { max-width: none; }

  pre { white-space: pre-wrap !important; }
  pre code { overflow-wrap: anywhere; }
}
