:root {
  --paper: #f6f3ea;
  --card: #ffffff;
  --ink: #22262b;
  --ink-soft: #5c6470;
  --accent: #0f6e63;
  --accent-dark: #0a4d45;
  --accent-soft: #e3f2ef;
  --err-bg: #fdecec;
  --err-ink: #9c2b2b;
  --line: #e6e0d2;
  --code-bg: #1e2430;
  --code-ink: #e8e6df;
  --radius: 14px;
  --shadow: 0 12px 34px rgba(30, 40, 50, 0.10);
  --serif: Georgia, Cambria, "Times New Roman", serif;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: Consolas, "SF Mono", Menlo, Monaco, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 24px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.2rem;
}
.logo {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.15rem;
}
.topbar-tag { color: var(--ink-soft); font-size: 0.88rem; }

/* ---------- Home ---------- */
.home {
  max-width: 720px;
  margin: 0 auto;
  padding: 36px 24px 30px;
  text-align: center;
}
.home h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.6rem, 4.4vw, 2.5rem);
  line-height: 1.25;
  margin: 0 0 14px;
}
.hl { color: var(--accent); }
.lead {
  color: var(--ink-soft);
  font-size: 1.02rem;
  margin: 0 auto 28px;
  max-width: 580px;
}
.story-form {
  display: flex;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: var(--shadow);
}
.story-form:focus-within { border-color: var(--accent); }
#url-input, .story-form input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 1.02rem;
  padding: 12px 14px;
  color: var(--ink);
}
.story-form input::placeholder { color: #9aa1ab; }
.story-form button[type="submit"] {
  border: 0;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  border-radius: 10px;
  padding: 12px 26px;
  white-space: nowrap;
  transition: background 0.18s ease, transform 0.12s ease;
}
.story-form button[type="submit"]:hover { background: var(--accent-dark); }
.story-form button[type="submit"]:active { transform: translateY(1px); }

.status {
  max-width: 620px;
  margin: 18px auto 0;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.95rem;
  text-align: left;
}
.status.err {
  background: var(--err-bg);
  color: var(--err-ink);
  border: 1px solid #f3caca;
}

.hints {
  margin-top: 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.hints-label { color: var(--ink-soft); font-size: 0.88rem; margin-right: 2px; }
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--accent);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Reader ---------- */
.reader { max-width: 900px; margin: 0 auto; padding: 8px 20px 70px; }
.reader-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 820px;
  margin: 0 auto 18px;
}
.ghost {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 8px;
}
.ghost:hover { background: var(--accent-soft); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  max-width: 820px;
  margin: 0 auto 20px;
  border-bottom: 1px solid var(--line);
}
.tab {
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 0.98rem;
  font-weight: 500;
  color: var(--ink-soft);
  padding: 10px 16px;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--accent); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---------- Article ---------- */
.story {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(26px, 5vw, 64px);
  max-width: 820px;
  margin: 0 auto;
}
.story-head { text-align: center; }
.story-domain {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 4px 12px;
}
.story h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.6rem, 4vw, 2.3rem);
  line-height: 1.25;
  margin: 18px 0 12px;
}
.story-excerpt {
  color: var(--ink-soft);
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.08rem;
  margin: 0 auto 8px;
  max-width: 640px;
}
.story-meta { color: var(--ink-soft); font-size: 0.85rem; margin: 0; }
.story-figure { margin: 30px 0; text-align: center; }
.story-figure img { max-width: 100%; height: auto; border-radius: 10px; box-shadow: 0 4px 16px rgba(30, 40, 50, 0.12); }
.story-figure figcaption { color: var(--ink-soft); font-size: 0.84rem; margin-top: 8px; }

.story-body {
  font-family: var(--serif);
  font-size: 1.18rem;
  line-height: 1.85;
  color: #262b31;
  word-wrap: break-word;
}
.story-body > *:first-child { margin-top: 0; }
.story-body p { margin: 0 0 1.25em; }
.story-body div { margin: 0 0 1.25em; }
.story-body h2 { font-size: 1.5rem; margin: 1.6em 0 0.6em; line-height: 1.3; }
.story-body h3 { font-size: 1.25rem; margin: 1.4em 0 0.5em; }
.story-body a { color: var(--accent); }
.story-body img { max-width: 100%; height: auto; border-radius: 8px; }
.story-body figure { margin: 1.6em 0; text-align: center; }
.story-body figcaption { font-size: 0.85rem; color: var(--ink-soft); margin-top: 6px; font-style: italic; }
.story-body blockquote { margin: 1.5em 0; padding: 0.1em 1em; border-left: 4px solid var(--accent); color: #3c4249; font-style: italic; }
.story-body ul, .story-body ol { margin: 0 0 1.25em; padding-left: 1.5em; }
.story-body li { margin-bottom: 0.4em; }
.story-body pre { background: #f2efe6; border: 1px solid var(--line); border-radius: 8px; padding: 14px; overflow-x: auto; font-size: 0.9rem; }
.story-body code { font-family: var(--mono); font-size: 0.92em; }
.story-body table { border-collapse: collapse; width: 100%; margin: 0 0 1.25em; }
.story-body th, .story-body td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; }

/* ---------- Source code ---------- */
.src-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  max-width: 900px;
  margin: 0 auto 10px;
}
.src-meta { color: var(--ink-soft); font-size: 0.88rem; }
.src-actions { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mini-toggle { color: var(--ink-soft); font-size: 0.85rem; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.btn2 { border: 1px solid var(--line); background: var(--card); }

.code {
  background: var(--code-bg);
  color: var(--code-ink);
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
  padding: 20px;
  border-radius: var(--radius);
  overflow: auto;
  max-height: 72vh;
  white-space: pre;
  word-break: normal;
  box-shadow: var(--shadow);
}
.code.wrap { white-space: pre-wrap; word-break: break-word; }
.code code { font-family: inherit; }

/* ---------- Debug ---------- */
.dbg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}
.dbg-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.dbg-k { color: var(--ink-soft); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.dbg-v { font-size: 1.05rem; font-weight: 600; word-break: break-all; }
.dbg-v.small { font-size: 0.9rem; font-weight: 500; }
.dbg-v .dim, .dim { color: var(--ink-soft); font-weight: 400; }
.data-status[data-status^="2"], .dbg-v[data-status^="2"] { color: var(--accent); }
.dbg-v.err-code { color: var(--err-ink); }
.db-g .small { font-size: 0.85rem; }
.mono { font-family: var(--mono); font-size: 0.85rem; word-break: break-all; }

.dbg-section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 18px;
  overflow-x: auto;
}
.dbg-section h3 { margin: 0 0 12px; font-size: 1rem; }
.hops { margin: 0; padding-left: 22px; }
.hops li { margin-bottom: 4px; }
.hop-code { display: inline-block; min-width: 34px; font-family: var(--mono); font-weight: 600; }
table.hdr { border-collapse: collapse; width: 100%; }
table.hdr th, table.hdr td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.hdr th:first-child { width: 180px; font-size: 0.82rem; color: var(--ink-soft); text-transform: uppercase; }

.empty-note {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 30px;
  text-align: center;
  color: var(--ink-soft);
}

/* ---------- Data zote ---------- */
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.badge-in { background: var(--accent-soft); color: var(--accent-dark); }
.badge-out { background: #eef1f5; color: #4c5563; }
.kv-list { margin: 0; padding-left: 0; list-style: none; }
.kv-list li { padding: 5px 0; border-bottom: 1px solid var(--line); }
.kv-list li:last-child { border-bottom: 0; }
.small { font-size: 0.85rem; }
.note { font-size: 0.85rem; margin-top: 10px; }
.img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.img-card {
  display: block;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
  background: #fff;
}
.img-card:hover { border-color: var(--accent); }
.img-thumb {
  display: block;
  height: 90px;
  background-color: #ede9dd;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}
.img-cap {
  display: block;
  padding: 6px 8px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1.3;
  max-height: 2.6em;
  overflow: hidden;
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
  padding: 24px 20px 40px;
  max-width: 820px;
  margin: 0 auto;
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .story-form { flex-direction: column; }
  .story-form button[type="submit"] { width: 100%; }
  .topbar-tag { display: none; }
  .reader-nav { flex-direction: column; align-items: flex-start; }
  .src-toolbar { flex-direction: column; align-items: flex-start; }
}