:root {
  --font-latin: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-cjk: "Songti TC", "Songti SC", "Source Han Serif TC", "Noto Serif TC", "Noto Serif CJK TC", STSong, serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 2px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

[hidden] { display: none !important; }

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0c;
  --bg-2: #101014;
  --bg-3: #16161d;
  --bg-elevated: #14141a;
  --text: #ece9e4;
  --text-strong: #ffffff;
  --muted: #a09caa;
  --faint: #6f6b79;
  --line: rgba(236, 233, 228, 0.11);
  --line-strong: rgba(236, 233, 228, 0.22);
  --accent: #9a6bff;
  --accent-2: #c3a8ff;
  --accent-soft: rgba(154, 107, 255, 0.12);
  --emphasis: #e9c46a;
  --emphasis-soft: rgba(233, 196, 106, 0.12);
  --on-accent: #0a0a0c;
  --grid: rgba(255, 255, 255, 0.035);
  --glow: rgba(121, 79, 214, 0.2);
  --selection: rgba(154, 107, 255, 0.35);
  --backdrop: rgba(4, 4, 7, 0.72);
  --shadow: 0 40px 120px rgba(0, 0, 0, 0.55);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5efe2;
  --bg-2: #efe7d6;
  --bg-3: #e8ddc8;
  --bg-elevated: #fbf7ee;
  --text: #191611;
  --text-strong: #000000;
  --muted: #5d5649;
  --faint: #8a8171;
  --line: rgba(25, 22, 17, 0.16);
  --line-strong: rgba(25, 22, 17, 0.3);
  --accent: #a87a13;
  --accent-2: #8a6208;
  --accent-soft: rgba(183, 139, 31, 0.14);
  --emphasis: #1d4ed8;
  --emphasis-soft: rgba(29, 78, 216, 0.1);
  --on-accent: #191307;
  --grid: rgba(25, 22, 17, 0.045);
  --glow: rgba(183, 139, 31, 0.16);
  --selection: rgba(29, 78, 216, 0.2);
  --backdrop: rgba(32, 27, 18, 0.5);
  --shadow: 0 40px 120px rgba(60, 48, 25, 0.18);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(900px 520px at 82% -10%, var(--glow), transparent 70%),
    radial-gradient(700px 420px at 6% 0%, var(--accent-soft), transparent 72%);
}

h1, h2, h3, h4 { font-family: var(--font-latin); font-weight: 500; letter-spacing: 0.01em; }
p { margin: 0 0 0.75em; }
a { color: var(--accent-2); }
a:hover { color: var(--accent); }
code, pre, kbd { font-family: var(--font-mono); font-size: 0.86em; }

/* ---------- plaque ---------- */
.plaque {
  position: relative;
  border: 1px solid var(--line-strong);
  outline: 1px solid var(--line);
  outline-offset: 4px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg-elevated) 96%, transparent), var(--bg-2));
  padding: 1.1rem 1.6rem;
  text-align: center;
}
.plaque-corner {
  position: absolute;
  width: 10px; height: 10px;
  border: 1px solid var(--emphasis);
  opacity: 0.8;
}
.plaque-corner--tl { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.plaque-corner--tr { top: -1px; right: -1px; border-left: 0; border-bottom: 0; }
.plaque-corner--bl { bottom: -1px; left: -1px; border-right: 0; border-top: 0; }
.plaque-corner--br { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }
.plaque-eyebrow {
  margin: 0 0 0.35rem;
  font-family: var(--font-ui);
  font-size: 0.66rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--emphasis);
}
.plaque-name {
  margin: 0;
  font-family: var(--font-latin);
  font-size: 1.5rem;
  letter-spacing: 0.06em;
  color: var(--text-strong);
}
.plaque-domain {
  margin: 0.3rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.plaque--large { padding: 1.6rem 2rem; }
.plaque--large .plaque-name { font-size: 2rem; }

/* ---------- gate ---------- */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 3rem 1.25rem;
}
.gate-card { width: min(440px, 100%); display: grid; gap: 1.6rem; }
.gate-form { display: grid; gap: 0.9rem; }
.gate-note { color: var(--muted); font-size: 0.9rem; }
.gate-foot { color: var(--faint); font-size: 0.78rem; text-align: center; }
.form-error { color: #ff8d8d; font-size: 0.85rem; margin: 0; }
html[data-theme="light"] .form-error { color: #b3261e; }

/* ---------- layout ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.mini-plaque { display: grid; text-decoration: none; line-height: 1.15; }
.mini-plaque-name { font-family: var(--font-latin); font-size: 1.02rem; letter-spacing: 0.05em; color: var(--text-strong); }
.mini-plaque-domain { font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.12em; color: var(--faint); }
.topbar-actions { display: flex; align-items: center; gap: 0.6rem; }

.shell { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 232px;
  flex: 0 0 auto;
  padding: 1.2rem 0.9rem 2rem;
  border-right: 1px solid var(--line);
  position: sticky;
  top: 61px;
  align-self: flex-start;
  height: calc(100vh - 61px);
  overflow-y: auto;
}
.sidebar-label {
  margin: 1.1rem 0 0.4rem;
  padding-left: 0.6rem;
  font-size: 0.64rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
}
.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border: 0;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.16s var(--ease), color 0.16s var(--ease), border-color 0.16s var(--ease);
}
.nav-item:hover { background: var(--bg-2); color: var(--text); }
.nav-item.is-active { color: var(--text-strong); background: var(--accent-soft); border-left-color: var(--accent); }

.view { flex: 1; min-width: 0; padding: clamp(1rem, 2.5vw, 2rem) clamp(1rem, 3vw, 2.4rem) 4rem; }

/* ---------- common ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
.page-kicker { margin: 0; font-size: 0.68rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--emphasis); }
.page-title { margin: 0.2rem 0 0; font-size: clamp(1.5rem, 3vw, 2rem); color: var(--text-strong); }
.page-note { color: var(--muted); font-size: 0.86rem; max-width: 62ch; margin: 0; }
.page-head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.52rem 1rem;
  border: 1px solid var(--line-strong);
  background: var(--bg-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.86rem;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.16s var(--ease), background 0.16s var(--ease), color 0.16s var(--ease);
}
.btn:hover { border-color: var(--accent); color: var(--text-strong); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: var(--on-accent); }
.btn--danger { border-color: color-mix(in srgb, #d04a4a 60%, transparent); color: #e57373; }
.btn--danger:hover { background: rgba(208, 74, 74, 0.12); border-color: #d04a4a; }
.btn--ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn--ghost:hover { color: var(--text); background: var(--bg-2); }
.btn--small { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.icon-btn {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  width: 34px; height: 34px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.95rem;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.16rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--bg-2);
}
.badge--ok { color: #7fd0a1; border-color: rgba(127, 208, 161, 0.4); }
.badge--warn { color: var(--emphasis); border-color: color-mix(in srgb, var(--emphasis) 40%, transparent); }
.badge--err { color: #e57373; border-color: rgba(229, 115, 115, 0.4); }

.panel {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-elevated) 70%, transparent);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
}
.panel + .panel { margin-top: 1rem; }
.panel-title { margin: 0 0 0.3rem; font-size: 1.05rem; color: var(--text-strong); }
.panel-note { color: var(--muted); font-size: 0.84rem; margin: 0 0 0.9rem; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.9rem; }
.stat-card {
  border: 1px solid var(--line);
  background: var(--bg-2);
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
}
.stat-label { margin: 0; font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); }
.stat-value { margin: 0.3rem 0 0; font-family: var(--font-latin); font-size: 1.8rem; color: var(--text-strong); }
.stat-sub { margin: 0.2rem 0 0; font-size: 0.76rem; color: var(--muted); }

.list { display: grid; gap: 0.55rem; }
.row-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  background: var(--bg-2);
  border-radius: var(--radius);
}
.row-item:hover { border-color: var(--line-strong); }
.row-main { flex: 1; min-width: 0; }
.row-title { margin: 0; font-size: 0.94rem; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { margin: 0.1rem 0 0; font-size: 0.76rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.tag { display: inline-block; padding: 0.05rem 0.45rem; border: 1px solid var(--line); border-radius: 999px; font-size: 0.68rem; color: var(--muted); margin-right: 0.25rem; }
.tag--accent { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }

/* forms */
.field { display: grid; gap: 0.3rem; font-size: 0.82rem; color: var(--muted); }
.field > span { font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }
input, textarea, select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.88rem;
}
textarea { resize: vertical; min-height: 90px; font-family: var(--font-mono); font-size: 0.82rem; line-height: 1.55; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.8rem; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.check-row { display: flex; align-items: center; gap: 0.45rem; font-size: 0.86rem; color: var(--text); }
.check-row input { width: auto; }

/* tables */
.table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.table th, .table td { text-align: left; padding: 0.5rem 0.55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); font-weight: 500; }
.table td .btn { margin-right: 0.2rem; }

/* split editor */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.preview {
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 1rem 1.15rem;
  min-height: 240px;
  max-height: 60vh;
  overflow: auto;
  border-radius: var(--radius);
  font-family: var(--font-latin);
  font-size: 0.95rem;
  line-height: 1.75;
}
.preview h1, .preview h2, .preview h3 { color: var(--text-strong); margin: 1em 0 0.4em; }
.preview p { margin: 0 0 0.8em; }
.preview img { max-width: 100%; }
.preview table { border-collapse: collapse; }
.preview td, .preview th { border: 1px solid var(--line); padding: 0.25rem 0.5rem; }
.preview blockquote { margin: 0 0 0.8em; padding-left: 0.8rem; border-left: 2px solid var(--accent); color: var(--muted); }

.editor-tabs { display: flex; gap: 0.3rem; margin-bottom: 0.5rem; }
.tab {
  padding: 0.28rem 0.7rem;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
  border-radius: var(--radius);
}
.tab.is-active { color: var(--text-strong); border-color: var(--accent); background: var(--accent-soft); }
.tab-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 0.35rem;
  border-radius: 50%;
  background: var(--emphasis);
  vertical-align: middle;
}
.tab-dot[hidden] { display: none; }

.rich {
  min-height: 260px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font-latin);
  font-size: 0.95rem;
  line-height: 1.75;
  overflow: auto;
}
.rich:focus { outline: none; border-color: var(--accent); }
.rich h2, .rich h3 { color: var(--text-strong); }
.rich a { color: var(--accent-2); }
.toolbar { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.toolbar button {
  min-width: 30px;
  padding: 0.2rem 0.45rem;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
  border-radius: var(--radius);
}
.toolbar button:hover { color: var(--text); border-color: var(--accent); }

/* modal */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1.2rem;
  background: var(--backdrop);
  backdrop-filter: blur(6px);
}
.modal {
  width: min(880px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  z-index: 1;
}
.modal-title { margin: 0; font-size: 1.1rem; color: var(--text-strong); }
.modal-body { padding: 1.1rem 1.2rem 1.3rem; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.8rem 1.2rem;
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 0;
  background: var(--bg-elevated);
}
.modal--wide { width: min(1080px, 100%); }

/* toasts */
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 80; display: grid; gap: 0.5rem; }
.toast {
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--line-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.84rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 380px;
}
.toast--ok { border-color: rgba(127, 208, 161, 0.5); }
.toast--err { border-color: rgba(229, 115, 115, 0.6); }

.loading { color: var(--faint); padding: 2rem 0; font-size: 0.9rem; }
.empty { color: var(--faint); font-size: 0.86rem; padding: 1.2rem 0; }
.hint { color: var(--faint); font-size: 0.76rem; }
.mono { font-family: var(--font-mono); font-size: 0.8em; }
.spacer { flex: 1; }
.inline { display: inline-flex; align-items: center; gap: 0.4rem; }
.stack { display: grid; gap: 0.9rem; }

/* library grid */
.library-grid {
  display: grid;
  gap: 0.5rem;
  grid-auto-rows: 82px;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}
.shelf-cell {
  border: 1px solid var(--line);
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 0.45rem 0.55rem;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: border-color 0.16s var(--ease);
}
.shelf-cell:hover { border-color: var(--accent); }
.shelf-cell.is-empty { border-style: dashed; color: var(--faint); align-items: center; justify-content: center; font-size: 0.74rem; }
.shelf-name { font-size: 0.78rem; color: var(--text-strong); line-height: 1.3; }
.shelf-meta { font-size: 0.68rem; color: var(--faint); }

/* academic */
.acad-tabs { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-bottom: 1rem; }
.acad-section { border: 1px solid var(--line); background: var(--bg-2); border-radius: var(--radius); margin-bottom: 0.8rem; }
.acad-section-head {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--line);
}
.acad-section-title { font-size: 0.9rem; color: var(--text-strong); margin: 0; }
.acad-section-body { padding: 0.8rem; }
.acad-section-body .rich { min-height: 120px; }

@media (max-width: 820px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0.6rem;
  }
  .sidebar-label { display: none; }
  .nav-item { width: auto; }
  .shell { flex-direction: column; }
  .topbar { position: static; }
}
