:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1d1b18;
  --muted: #6b665d;
  --line: #e2ddd2;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --warn: #9a5b12;
  --danger: #a83232;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --surface: #1f1d1a;
    --text: #ece8e1;
    --muted: #a39d92;
    --line: #34312c;
    --accent: #6fbf95;
    --accent-ink: #0e1a13;
    --warn: #e0a556;
    --danger: #ef7d7d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap { max-width: 640px; margin: 0 auto; padding: 24px 16px 64px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top-link { font-weight: 600; color: var(--accent); text-decoration: none; }
h1 { font-size: 1.6rem; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 1.05rem; margin: 32px 0 4px; }
.lead { color: var(--muted); margin: 8px 0 20px; }
.hint, .empty { color: var(--muted); font-size: 0.9rem; margin: 0 0 12px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

details { margin-top: 12px; }
summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
textarea, input[type="text"] {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
}
textarea { margin-top: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; resize: vertical; }

button, .open {
  font: inherit; font-size: 0.95rem; border-radius: 8px; padding: 9px 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; }
button.small, .button.small { padding: 4px 10px; font-size: 0.85rem; }
label.button {
  display: inline-block; font: inherit; border-radius: 8px; border: 1px solid var(--line);
  color: var(--text); cursor: pointer; white-space: nowrap;
}
.error { color: var(--danger); margin: 10px 0 0; font-size: 0.9rem; }

.comments { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.comment { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.comment.owner { border-color: var(--accent); }
.comment p { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-head { display: flex; gap: 8px; align-items: baseline; font-size: 0.85rem; }
.comment-head span { color: var(--muted); flex: 1; }

/* Home page */
.intro { display: block; width: 100%; aspect-ratio: 16 / 9; border-radius: var(--radius); border: 1px solid var(--line); background: #f5f3ee; margin: 4px 0 8px; }
.uses { margin: 0; padding-left: 20px; }
.uses li { margin: 4px 0; }
.home pre {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin: 0 0 12px; overflow-x: auto; font-size: 0.8rem;
}
.home code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.home .card p { margin: 0 0 10px; }
.home .card { margin-top: 12px; }
.home .card h2 { margin: 0 0 8px; }
.home a { color: var(--accent); }
.home .promise {
  margin: 0 0 6px; padding: 10px 14px; border-left: 4px solid var(--accent); border-radius: 6px;
  background: var(--surface); font-weight: 600; font-size: 1.05rem;
}
.home .lead + .promise { margin-top: -8px; }
.home .paths { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin: 0 0 10px; }
.home .paths th, .home .paths td { text-align: left; vertical-align: top; padding: 8px 6px; border-top: 1px solid var(--line); }
.home .paths th { color: var(--muted); font-weight: 600; border-top: 0; }
.home .paths td:first-child { font-weight: 600; }
@media (max-width: 560px) {
  .home .paths thead { display: none; }
  .home .paths tr { display: block; border-top: 1px solid var(--line); padding: 8px 0; }
  .home .paths td { display: block; border: 0; padding: 2px 0; }
  .home .paths td:last-child { color: var(--muted); }
  .home .paths td:last-child::before { content: "Gateway: "; }
}
.home .steps { margin: 0; padding-left: 22px; }
.home .steps > li { margin: 0 0 14px; }
.home .steps > li::marker { font-weight: 700; color: var(--accent); }
.home .steps .hint { margin: 0 0 6px; }
.home .advanced { margin: 0; }
.home .advanced dt { font-weight: 600; margin-top: 14px; }
.home .advanced dt:first-child { margin-top: 0; }
.home .advanced dd { margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }
.home .advanced code, .home .uses code, .home .hint code { overflow-wrap: anywhere; }

/* Viewer */
body.viewer { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.bar {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px;
  border-bottom: 1px solid var(--line); background: var(--surface); font-size: 0.85rem; min-height: 40px;
}
.bar[hidden] { display: none; }
.bar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-note { color: var(--muted); margin-right: auto; white-space: nowrap; }
.lock { color: var(--accent); font-size: 0.7rem; }
.viewer-body { flex: 1; display: flex; min-height: 0; position: relative; }
.viewer-body[hidden] { display: none; }
#frame { flex: 1; width: 100%; border: 0; background: #fff; }
.versions {
  font: inherit; font-size: 0.8rem; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px;
}
.versions[hidden] { display: none; }
.toast {
  position: fixed; top: 52px; left: 50%; transform: translateX(-50%); z-index: 10; margin: 0;
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 0.85rem;
  max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }
.panel {
  width: 340px; display: flex; flex-direction: column; border-left: 1px solid var(--line);
  background: var(--surface); min-height: 0;
}
.panel[hidden] { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.panel .comments { flex: 1; overflow-y: auto; margin: 0; padding: 12px; align-content: start; }
.pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pane[hidden] { display: none; }
.pane-hint { margin: 10px 12px 0; }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: transparent; padding: 4px 8px; border-radius: 6px; font-size: 0.85rem; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--bg); color: var(--text); font-weight: 600; }
.comment.mine { border-color: var(--line); background: var(--bg); }
.change-form[hidden] { display: none; }
.change-form { display: grid; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--card, #fff); }
.change-form textarea { margin: 0; width: 100%; min-height: 90px; font: inherit; font-size: 16px; }
.change-form .hint { margin: 0; }
.change-actions { display: flex; justify-content: flex-end; gap: 8px; }
.change-actions .mic { margin-right: auto; }
.mic.on { color: #fff; background: #b0623a; border-color: #b0623a; }
.comment-form { display: grid; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.comment-form textarea { margin: 0; }
.comment-form .hint { margin: 0; }
.state { flex: 1; display: grid; place-items: center; padding: 16px; }
.state[hidden] { display: none; }
.state-box { max-width: 420px; text-align: center; }
.state-box p { color: var(--muted); }

@media (max-width: 640px) {
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto; height: 65%;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
  }
}
@media (max-width: 480px) {
  .bar-note { display: none; }
  .bar strong { margin-right: auto; }
  .row { flex-direction: column; }
}
