:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --border: #e3e0da;
  --text: #23201c;
  --muted: #857f76;
  --accent: #9a5b2c;
  --accent-soft: #f6e9dc;
  --danger: #a8342b;
  --radius: 8px;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --serif: "Songti SC", "Source Han Serif SC", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1917;
    --surface: #232120;
    --border: #363330;
    --text: #e8e4de;
    --muted: #9a938a;
    --accent: #d99b62;
    --accent-soft: #3a2c1e;
    --danger: #e0796d;
  }
}

* {
  box-sizing: border-box;
}

/* 下面几个容器要用 display:grid/flex 布局，而作者样式优先级高于 UA 的
   [hidden] { display: none }，不写这条 hidden 属性会整个失效——全屏的评论
   浮层会一直盖在页面上，把所有点击都吃掉。 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
}

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

button {
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

button.ghost:hover {
  color: var(--text);
  border-color: var(--muted);
  filter: none;
}

select,
input,
textarea {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

textarea {
  width: 100%;
  resize: vertical;
  font-family: var(--sans);
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin: 4px 0 0;
}

/* ------------------------------------------------------------------ 口令门 */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.gate-card h1 {
  margin: 0;
  font-size: 20px;
}

.gate-card p {
  margin: 0;
}

/* -------------------------------------------------------------------- 布局 */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* ------------------------------------------------------------ 左侧内容导航 */

.nav {
  position: sticky;
  top: 60px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-group h3 {
  margin: 0 0 4px 10px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  text-align: left;
}

.nav button:hover {
  background: var(--accent-soft);
  color: var(--text);
  filter: none;
}

.nav button[aria-current="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.nav-count {
  flex: none;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

.notice {
  margin: 0;
  padding: 8px 20px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
}

.body {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr) 300px;
  gap: 28px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 20px 96px;
}

/* 素材库没有右侧评论栏，把那 300px 让给内容。 */
.body[data-view="assets"] {
  grid-template-columns: 168px minmax(0, 1fr);
}

/* ------------------------------------------------------------------ 正文渲染 */

.doc {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.95;
  min-width: 0;
}

.doc [data-block] {
  position: relative;
  scroll-margin-top: 80px;
}

.doc [data-block][data-commented="true"]::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 4px;
  bottom: 4px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}

.doc [data-block].flash {
  background: var(--accent-soft);
  transition: background 1.2s;
}

.doc h1 {
  font-size: 24px;
  margin: 0 0 20px;
}

.doc h2 {
  font-size: 19px;
  margin: 36px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.doc h3 {
  font-size: 16px;
  margin: 28px 0 8px;
  color: var(--accent);
}

.doc p {
  margin: 0 0 16px;
}

.doc blockquote {
  margin: 0 0 16px;
  padding: 8px 14px;
  border-left: 2px solid var(--border);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 14px;
}

.doc blockquote p:last-child {
  margin-bottom: 0;
}

.doc hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

.doc img,
.doc video {
  display: block;
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 0 0 16px;
}

/* 竖屏素材按原始尺寸能顶掉一整屏，限高让一页里能同时看到镜头和它的提示词。 */
.doc img,
.doc video {
  max-height: 70vh;
  width: auto;
  background: var(--surface);
}

.doc code {
  font-size: 0.9em;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--accent-soft);
}

.doc .missing {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
}

::highlight(commented) {
  background: var(--accent-soft);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

/* -------------------------------------------------------------------- 评论 */

.side {
  min-width: 0;
}

.side-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  position: sticky;
  top: 60px;
  background: var(--bg);
  padding-bottom: 8px;
}

.side-head h2 {
  margin: 0;
  font-size: 15px;
}

.comment-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.comment {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
}

.comment:hover {
  border-color: var(--accent);
}

.comment-quote {
  margin: 0 0 8px;
  padding-left: 8px;
  border-left: 2px solid var(--accent);
  color: var(--muted);
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.comment-body {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.comment-meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* ------------------------------------------------------------------ 素材库 */

.assets {
  min-width: 0;
}

.asset-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 28px;
}

.asset-form h2 {
  margin: 0;
  font-size: 17px;
}

.asset-form p.muted {
  margin: 0;
}

.asset-form input[type="file"] {
  padding: 6px;
}

.asset-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.asset-actions .error {
  margin: 0;
}

.asset-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.asset {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.asset a {
  display: block;
}

/* 竖屏参考图很常见，统一高度让网格不会参差，点开看原图。 */
.asset img {
  display: block;
  width: 100%;
  height: 220px;
  object-fit: contain;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.asset figcaption {
  padding: 10px 12px;
}

.asset-note {
  margin: 0;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.asset-meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

/* -------------------------------------------------------- 划选与评论输入框 */

.select-action {
  position: absolute;
  z-index: 20;
  padding: 5px 12px;
  font-size: 13px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.18);
}

.composer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(0 0 0 / 0.4);
}

.composer-card {
  width: 100%;
  max-width: 460px;
  padding: 20px;
  background: var(--surface);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.composer-target {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.composer-card blockquote {
  margin: 0;
  padding-left: 10px;
  border-left: 2px solid var(--accent);
  color: var(--muted);
  font-size: 13px;
  max-height: 90px;
  overflow: auto;
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* 这两档都要连 [data-view] 一起写：属性选择器特异性更高，只改 .body 压不住它。 */
@media (max-width: 1100px) {
  .body,
  .body[data-view="assets"] {
    grid-template-columns: 150px minmax(0, 1fr);
    max-width: 900px;
  }

  .side {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .body,
  .body[data-view="assets"] {
    grid-template-columns: minmax(0, 1fr);
    padding: 16px 16px 80px;
  }

  /* 窄屏竖排会被几十集顶得很高，改成横向滚动一条。 */
  .nav {
    position: static;
    flex-direction: row;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 6px;
  }

  .nav-group {
    flex-direction: row;
    align-items: center;
    gap: 4px;
  }

  .nav-group h3 {
    margin: 0 2px 0 0;
    flex: none;
  }

  .nav button {
    width: auto;
    white-space: nowrap;
  }

  .side-head {
    position: static;
  }

  .doc [data-block][data-commented="true"]::before {
    left: -10px;
  }
}
