/* MDView viewer styling. ASCII only, by project convention. */

:root {
  --content-max: 50rem;
  --toc-width: 17rem;
  --toolbar-height: 3rem;
  --font-sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  --font-mono: "Cascadia Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  --radius: 8px;
}

html[data-theme="light"] {
  --bg: #faf9f7;
  --bg-raised: #ffffff;
  --bg-toolbar: #f4f2ee;
  --text: #1f1e1d;
  --text-muted: #6b6864;
  --text-faint: #94908a;
  --border: #e4e0da;
  --border-strong: #d3cec6;
  --code-bg: #f3f1ec;
  --quote-bg: #f4f2ed;
  --accent: #c15f3c;
  --accent-soft: rgba(193, 95, 60, 0.12);
  --table-stripe: #f8f6f3;
  --shadow: 0 1px 2px rgba(31, 30, 29, 0.06);
}

html[data-theme="dark"] {
  --bg: #262624;
  --bg-raised: #2f2f2c;
  --bg-toolbar: #201f1e;
  --text: #eceae7;
  --text-muted: #a8a49e;
  --text-faint: #837f79;
  --border: #3b3a37;
  --border-strong: #4a4844;
  --code-bg: #1c1b1a;
  --quote-bg: #2c2b28;
  --accent: #d97757;
  --accent-soft: rgba(217, 119, 87, 0.16);
  --table-stripe: #2b2a28;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

/* Author rules beat the user agent's [hidden] rule, so a display value on a
   panel would otherwise un-hide it. Keep the attribute authoritative. */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------- toolbar --- */

.toolbar {
  flex: 0 0 auto;
  height: var(--toolbar-height);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.6rem;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.doc-title {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button {
  flex: 0 0 auto;
  width: 2.1rem;
  height: 2.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.icon-button:hover {
  background: var(--accent-soft);
  color: var(--text);
}

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

.icon-button svg {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

html[data-theme="light"] .icon-moon { display: block; }
html[data-theme="light"] .icon-sun { display: none; }
html[data-theme="dark"] .icon-moon { display: none; }
html[data-theme="dark"] .icon-sun { display: block; }

/* ------------------------------------------------------------------ toc --- */

.body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.toc {
  flex: 0 0 var(--toc-width);
  width: var(--toc-width);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.1rem 0.5rem 3rem 1rem;
  border-right: 1px solid var(--border);
  background: var(--bg-toolbar);
  user-select: none;
}

body.toc-collapsed .toc {
  display: none;
}

.toc-head {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 0 0.5rem 0.6rem;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-list a {
  display: block;
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
  border-left: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.45;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.toc-list a:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.toc-list a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.toc-level-1 a { padding-left: 0.5rem; }
.toc-level-2 a { padding-left: 1.4rem; font-size: 0.83rem; }
.toc-level-3 a { padding-left: 2.3rem; font-size: 0.81rem; color: var(--text-faint); }

/* Addressed by id, not by class: "no-headings" below is a state flag on <body>,
   and a bare .toc-empty class selector would match the body too and hide the
   whole page. */
#toc-empty {
  display: none;
  padding: 0.3rem 0.5rem;
  font-size: 0.82rem;
  color: var(--text-faint);
}

body.no-headings #toc-empty { display: block; }

/* ------------------------------------------------------------- scroller --- */

.scroller {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  outline: none;
}

.content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 2.5rem 2rem 6rem;
}

body.no-document .content { display: none; }

/* --------------------------------------------------------- state panels --- */

.state-panel {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.state-card {
  max-width: 34rem;
  width: 100%;
  text-align: center;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.state-card-error {
  border-left: 3px solid var(--accent);
  text-align: left;
}

.state-title {
  margin: 0 0 0.6rem;
  font-size: 1.35rem;
  font-weight: 650;
  border: none;
  padding: 0;
}

.state-text {
  margin: 0 0 1.4rem;
  color: var(--text-muted);
}

.state-path {
  margin: 0 0 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-faint);
  word-break: break-all;
}

.state-hint {
  margin: 1.4rem 0 0;
  font-size: 0.82rem;
  color: var(--text-faint);
}

.primary-button {
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.5rem 1.2rem;
  border-radius: 7px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
}

.primary-button:hover { filter: brightness(1.07); }
.primary-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* -------------------------------------------------------- markdown body --- */

.markdown-body > *:first-child { margin-top: 0; }

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  line-height: 1.3;
  font-weight: 650;
  margin: 2.2rem 0 0.85rem;
  scroll-margin-top: 1.5rem;
}

.markdown-body h1 {
  font-size: 1.85rem;
  letter-spacing: -0.015em;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.markdown-body h2 {
  font-size: 1.45rem;
  letter-spacing: -0.01em;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}

.markdown-body h3 { font-size: 1.2rem; }
.markdown-body h4 { font-size: 1.03rem; }
.markdown-body h5 { font-size: 0.95rem; color: var(--text-muted); }
.markdown-body h6 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.markdown-body p { margin: 0 0 1.15rem; }

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-soft);
}

.markdown-body a:hover { border-bottom-color: var(--accent); }

.markdown-body strong { font-weight: 650; }
.markdown-body del { color: var(--text-faint); }

.markdown-body ul,
.markdown-body ol {
  margin: 0 0 1.15rem;
  padding-left: 1.6rem;
}

.markdown-body li { margin: 0.3rem 0; }
.markdown-body li > ul,
.markdown-body li > ol { margin: 0.3rem 0 0.35rem; }

.markdown-body li::marker { color: var(--text-faint); }

.markdown-body ul.task-list,
.markdown-body ul li.task-item { list-style: none; }

.markdown-body li.task-item {
  position: relative;
  padding-left: 0.15rem;
}

.markdown-body li.task-item > input[type="checkbox"] {
  position: absolute;
  left: -1.4rem;
  top: 0.42rem;
  margin: 0;
  width: 0.95rem;
  height: 0.95rem;
  accent-color: var(--accent);
}

.markdown-body li.task-item.task-done { color: var(--text-muted); }

.markdown-body blockquote {
  margin: 0 0 1.15rem;
  padding: 0.7rem 1.1rem;
  border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--quote-bg);
  color: var(--text-muted);
}

.markdown-body blockquote > *:last-child { margin-bottom: 0; }

.markdown-body hr {
  height: 1px;
  border: 0;
  background: var(--border);
  margin: 2.2rem 0;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  display: block;
  margin: 0.4rem 0;
}

.markdown-body img.image-broken {
  min-width: 12rem;
  min-height: 3rem;
  padding: 0.7rem 1rem;
  border: 1px dashed var(--border-strong);
  background: var(--code-bg);
}

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

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

.markdown-body :not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1em 0.35em;
  white-space: break-spaces;
}

.markdown-body pre {
  margin: 0 0 1.3rem;
  padding: 0;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.markdown-body pre > code,
.markdown-body pre > code.hljs {
  display: block;
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  background: transparent;
  color: inherit;
  line-height: 1.6;
  font-size: 0.85rem;
  white-space: pre;
  tab-size: 4;
}

.code-block { position: relative; margin-bottom: 1.3rem; }
.code-block > pre { margin-bottom: 0; }

.code-lang {
  position: absolute;
  top: 0.35rem;
  right: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
  pointer-events: none;
}

/* --------------------------------------------------------------- table --- */

.table-wrap {
  margin: 0 0 1.3rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.92rem;
}

.markdown-body th,
.markdown-body td {
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  font-weight: 650;
  color: var(--text-muted);
  background: var(--table-stripe);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.markdown-body tbody tr:last-child td { border-bottom: none; }
.markdown-body tbody tr:nth-child(even) { background: var(--table-stripe); }

/* ------------------------------------------------------------- mermaid --- */

.mermaid-block {
  margin: 0 0 1.4rem;
  padding: 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  text-align: center;
}

.mermaid-block svg {
  max-width: 100%;
  height: auto;
}

.mermaid-block.mermaid-failed {
  text-align: left;
  padding: 0;
  background: var(--code-bg);
}

.mermaid-error-note {
  padding: 0.5rem 1.1rem;
  font-size: 0.78rem;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
}

/* ------------------------------------------------------- render failure --- */

.render-failure {
  margin: 0 0 1.3rem;
  padding: 0.75rem 1.1rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 0.88rem;
}

.raw-fallback {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

/* ------------------------------------------------------------ drag drop --- */

body.drag-active::after {
  content: "Drop to open";
  position: fixed;
  inset: 0.5rem;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 650;
  color: var(--accent);
  background: var(--accent-soft);
  border: 2px dashed var(--accent);
  border-radius: 12px;
  pointer-events: none;
}

/* ------------------------------------------------------------ scrollbar --- */

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 6px;
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
.toc::-webkit-scrollbar-thumb { border-color: var(--bg-toolbar); }

@media print {
  .toolbar, .toc { display: none; }
}
