:root {
  color-scheme: light;
  --bg: #fbf7eb;
  --paper: #fffdf7;
  --ink: #1f2523;
  --muted: #68706c;
  --line: #ddd7c9;
  --accent: #0f7b83;
  --accent-2: #8f3f58;
  --button: #f1eadc;
  --button-hover: #e5dcc8;
  --shadow: 0 18px 50px rgba(40, 38, 30, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
.button-link {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--button);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  text-decoration: none;
}

button:hover,
.button-link:hover {
  background: var(--button-hover);
}

button.icon {
  width: 36px;
  min-width: 36px;
  padding: 0;
}

button.subtle,
.button-link.subtle {
  background: transparent;
}

button.danger {
  border-color: rgba(143, 63, 88, 0.35);
  color: #8f254d;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  padding: 8px 9px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 340px;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(15, 123, 131, 0.7);
  box-shadow: 0 0 0 3px rgba(15, 123, 131, 0.12);
}

.hidden-admin {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 50;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 0;
  color: var(--muted);
  background: transparent;
  opacity: 0.2;
  text-decoration: none;
  display: grid;
  place-items: center;
  transition: opacity 160ms ease, background 160ms ease;
}

.hidden-admin:hover {
  opacity: 0.8;
  background: rgba(127, 127, 127, 0.08);
}

.empty-state,
.login-shell,
.not-found {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-box,
.empty-box {
  width: min(420px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.login-box h1,
.empty-box h1 {
  margin: 0 0 16px;
  font-size: 1.05rem;
}

.stack {
  display: grid;
  gap: 12px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row.wrap {
  flex-wrap: wrap;
}

.muted {
  color: var(--muted);
}

.error-text {
  color: #a12f4f;
  min-height: 1.2em;
}

.reader {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  transition: background 180ms ease, color 180ms ease;
}

.reader.dark {
  color-scheme: dark;
  --bg: #111513;
  --paper: #171c1a;
  --ink: #e9eee8;
  --muted: #a3aba5;
  --line: #303832;
  --accent: #69d0d5;
  --accent-2: #e198a9;
  --button: #1d2421;
  --button-hover: #27302c;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

.reader-top {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 52px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 48px 8px 16px;
}

.breadcrumbs {
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  color: var(--muted);
  font-size: 0.85rem;
}

.breadcrumbs::-webkit-scrollbar {
  display: none;
}

.breadcrumbs a {
  color: inherit;
  text-decoration: none;
}

.breadcrumbs a:hover {
  color: var(--accent);
}

.crumb-sep {
  color: color-mix(in srgb, var(--muted) 55%, transparent);
  padding: 0 7px;
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 28px;
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 38px 22px 80px;
}

.reader-article {
  width: min(720px, 100%);
  margin: 0 auto;
}

.reader-title {
  margin: 0 0 22px;
  font-size: clamp(
    var(--reader-title-min, 2rem),
    var(--reader-title-mid, 6vw),
    var(--reader-title-max, 4.2rem)
  );
  line-height: 0.96;
  letter-spacing: 0;
}

.reader-content {
  font-size: var(--reader-body-size, 1.08rem);
  line-height: 1.8;
}

.reader-content h1,
.reader-content h2,
.reader-content h3 {
  line-height: 1.12;
  margin: 1.7em 0 0.55em;
  letter-spacing: 0;
}

.reader-content h1 {
  font-size: 1.85em;
}

.reader-content h2 {
  font-size: 1.34em;
}

.reader-content h3 {
  font-size: 1.05em;
}

.reader-content p {
  margin: 0 0 1.15em;
}

.reader-content ul,
.reader-content ol {
  padding-left: 1.4em;
}

.reader-content code {
  background: color-mix(in srgb, var(--line) 45%, transparent);
  border-radius: 4px;
  padding: 0.1em 0.25em;
}

.reader-content pre {
  overflow-x: auto;
  background: color-mix(in srgb, var(--paper) 86%, var(--ink) 4%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.story-link {
  color: color-mix(in srgb, var(--ink) 86%, var(--accent));
  text-decoration: none;
  background: linear-gradient(
    105deg,
    currentColor 0%,
    currentColor 32%,
    color-mix(in srgb, var(--accent) 72%, white) 44%,
    color-mix(in srgb, var(--accent-2) 78%, white) 50%,
    color-mix(in srgb, var(--accent) 72%, white) 56%,
    currentColor 68%,
    currentColor 100%
  );
  background-clip: text;
  -webkit-background-clip: text;
  background-size: 320% 100%;
  -webkit-text-fill-color: transparent;
  animation: idleSheen 9s ease-in-out infinite;
}

.story-link:hover {
  color: color-mix(in srgb, var(--ink) 72%, var(--accent));
  animation: hoverSheen 850ms ease-out;
}

.font-step {
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0;
}

@keyframes idleSheen {
  0%,
  80%,
  100% {
    background-position: 140% 0;
  }
  88% {
    background-position: -60% 0;
  }
}

@keyframes hoverSheen {
  from {
    background-position: 140% 0;
  }
  to {
    background-position: -60% 0;
  }
}

.chapter-nav {
  position: sticky;
  top: 78px;
  align-self: start;
  border-left: 1px solid var(--line);
  padding-left: 16px;
}

.chapter-nav.collapsed {
  display: none;
}

.chapter-nav a {
  display: block;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 0;
  font-size: 0.88rem;
}

.chapter-nav a.active,
.chapter-nav a:hover {
  color: var(--accent);
}

.admin {
  min-height: 100vh;
  background: #f5f1e6;
  color: #202521;
}

.admin-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
}

.admin-top {
  height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid #d8d1c2;
  background: #fbf8ef;
}

.admin-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.admin-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-main {
  min-height: 0;
  display: grid;
  grid-template-columns: 245px minmax(0, 1fr);
}

.admin-sidebar {
  border-right: 1px solid #d8d1c2;
  background: #eee8d9;
  padding: 12px;
  overflow: auto;
}

.admin-content {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.section-title {
  margin: 16px 0 8px;
  color: #6a6d67;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.list {
  display: grid;
  gap: 5px;
}

.list button {
  justify-content: flex-start;
  width: 100%;
  background: transparent;
  border-color: transparent;
  text-align: left;
  min-height: 32px;
  overflow: hidden;
}

.list button:hover,
.list button.active {
  background: #fffaf0;
  border-color: #d8d1c2;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.panel {
  background: #fffaf0;
  border: 1px solid #d8d1c2;
  border-radius: 8px;
  padding: 14px;
}

.panel h2,
.panel h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.field {
  display: grid;
  gap: 5px;
}

.field label,
.check-label {
  color: #5e635f;
  font-size: 0.83rem;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.check-label input {
  width: auto;
}

.meta-list {
  display: grid;
  gap: 6px;
  color: #626760;
  font-size: 0.83rem;
  word-break: break-word;
}

.chapter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: #202521;
  color: #fffaf0;
  padding: 9px 12px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 100;
}

.toast.visible {
  opacity: 1;
}

.graph-shell {
  height: calc(100vh - 90px);
  min-height: 520px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.graph-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 360px) auto;
  justify-content: space-between;
  gap: 10px;
}

.graph-canvas-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid #d8d1c2;
  border-radius: 8px;
  background: #fbf8ef;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

@media (max-width: 860px) {
  .reader-top {
    grid-template-columns: minmax(0, 1fr);
    padding-right: 44px;
  }

  .reader-controls {
    justify-content: flex-end;
  }

  .reader-layout {
    grid-template-columns: 1fr;
    padding-top: 22px;
  }

  .chapter-nav {
    position: fixed;
    top: 58px;
    right: 10px;
    left: auto;
    z-index: 30;
    width: min(260px, calc(100vw - 20px));
    max-height: calc(100vh - 72px);
    overflow: auto;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 12px;
  }

  .admin-main,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    border-right: 0;
    border-bottom: 1px solid #d8d1c2;
    max-height: 300px;
  }

  .admin-top {
    height: auto;
    grid-template-columns: 1fr;
  }

  .chapter-row {
    grid-template-columns: 1fr;
  }
}
