:root {
  --bg: #ffffff;
  --panel: #f4f6fa;
  --hover: #e9edf3;
  --text: #17191c;
  --muted: #656d77;
  --border: #e3e8f0;
  --accent: #0dbd8b;
  --accent-text: #ffffff;
  --selected: #e3f7f1;
  --md: #6b4fd8;
  --html: #d9622b;
  --danger: #d1242f;
  --code-bg: #f4f6fa;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15191e;
  --panel: #1d2228;
  --hover: #262c33;
  --text: #edf3ff;
  --muted: #a9b2bc;
  --border: #2f363e;
  --accent: #0dbd8b;
  --accent-text: #0b1210;
  --selected: #173a31;
  --md: #a48bff;
  --html: #ff9b66;
  --danger: #ff6b6b;
  --code-bg: #21262c;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #15191e;
    --panel: #1d2228;
    --hover: #262c33;
    --text: #edf3ff;
    --muted: #a9b2bc;
    --border: #2f363e;
    --accent: #0dbd8b;
    --accent-text: #0b1210;
    --selected: #173a31;
    --md: #a48bff;
    --html: #ff9b66;
    --danger: #ff6b6b;
    --code-bg: #21262c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.app {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  height: 100%;
}

.files {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.files-head { padding: 14px 14px 10px; }
.files-head h1 { margin: 0 0 10px; font-size: 16px; font-weight: 650; }
.count { color: var(--muted); font-weight: 500; }

.chips { display: flex; gap: 6px; }
.chips button {
  padding: 3px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
}
.chips button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }

.status { margin: 4px 14px 10px; color: var(--muted); font-size: 13px; }
.status[data-kind="error"] { color: var(--danger); }
.hint { margin: 8px 14px 14px; color: var(--muted); font-size: 12px; }

.file-list { flex: 1; min-height: 0; margin: 0; padding: 0 8px; overflow: auto; list-style: none; }

.file {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.file:hover { background: var(--hover); }
.file[aria-current="true"] { background: var(--selected); }

.badge {
  flex: none;
  min-width: 40px;
  padding: 3px 6px;
  border-radius: 5px;
  background: var(--muted);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-align: center;
}
.badge[data-kind="markdown"] { background: var(--md); }
.badge[data-kind="html"] { background: var(--html); }

.file-body { display: flex; flex-direction: column; min-width: 0; }
.file-name, .name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 600; }
.file-meta, .meta { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); font-size: 12px; }

.viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.back { display: none; padding: 4px 8px; border: 0; border-radius: 6px; background: transparent; font-size: 18px; cursor: pointer; }
.back:hover { background: var(--hover); }

.toggle { display: inline-flex; flex: none; padding: 2px; border: 1px solid var(--border); border-radius: 8px; }
.toggle button { padding: 4px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.toggle button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.btn {
  flex: none;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }

.stage { position: relative; flex: 1; min-height: 0; overflow: auto; }
.html-frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; }

.placeholder { display: grid; place-content: center; height: 100%; padding: 24px; color: var(--muted); text-align: center; }
.placeholder p { margin: 4px 0; }
.placeholder-title { color: var(--text); font-size: 16px; font-weight: 600; }

.note { padding: 24px; color: var(--muted); }
.note-error { color: var(--danger); }

pre.source { margin: 0; padding: 16px 20px; min-height: 100%; background: var(--code-bg); font: 13px/1.55 ui-monospace, "Cascadia Code", Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
pre.source code.hljs { padding: 0; background: transparent; }

.landing { display: grid; place-items: center; min-height: 100%; padding: 24px 16px; }
.landing-card { max-width: 640px; }
.landing-card h1 { margin: 12px 0 8px; font-size: 24px; }
.landing-card h2 { margin: 24px 0 8px; font-size: 16px; }
.landing-card ol { padding-left: 20px; }
.landing-card li + li { margin-top: 8px; }
.command { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.command code { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; background: var(--code-bg); font-size: 12px; overflow-wrap: anywhere; }
.muted { color: var(--muted); font-size: 13px; }

@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .files { border-right: 0; }
  .app[data-view="list"] .viewer,
  .app[data-view="viewer"] .files { display: none; }
  .back { display: inline-block; }
  .toolbar { flex-wrap: wrap; }
  .title { flex-basis: calc(100% - 120px); }
}
