/* 编辑板 · 样式
   从灵感工作台的稿纸页拿过来的：象牙白的纸、墨黑的字、一点杂志红。
   颜色用 light-dark()：跟着系统深浅色；顶栏里手动换过的话改 color-scheme */

:root {
  color-scheme: light dark;
  --font: 'Segoe UI Variable Text', 'Segoe UI', 'Microsoft YaHei UI', 'Microsoft YaHei', 'PingFang SC', system-ui, sans-serif;
  --font-display: 'Segoe UI Variable Display', 'Segoe UI', 'Microsoft YaHei UI', 'Microsoft YaHei', system-ui, sans-serif;
  --font-serif: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STZhongsong', '华文中宋', Georgia, serif;
  --font-didone: 'Bodoni MT', 'Bodoni 72', Didot, 'Noto Serif SC', Georgia, serif;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.45, .64, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --page-w: clamp(1120px, 80vw, 1840px);

  --bg: light-dark(#f7f4ed, #100f0d);
  --surface: light-dark(#fcfaf5, #191714);
  --surface-2: light-dark(#efeae0, #22201c);
  --line: light-dark(rgba(20, 17, 14, .12), rgba(240, 234, 222, .11));
  --line-2: light-dark(rgba(20, 17, 14, .26), rgba(240, 234, 222, .24));
  --text: light-dark(#14110e, #efe9de);
  --text-2: light-dark(#4f4840, #b9b0a3);
  --text-3: light-dark(#968c80, #7a7167);
  --accent: light-dark(#c4361b, #ff6b4a);
  --accent-soft: light-dark(rgba(196, 54, 27, .08), rgba(255, 107, 74, .12));
  --ok: light-dark(#2c9a64, #4cc98a);
  --busy: light-dark(#c98a06, #f2bf4a);
  --danger: light-dark(#d64545, #ff6b6b);
  --shade: light-dark(rgba(60, 40, 20, .12), rgba(0, 0, 0, .5));
  --shadow-lg: 0 18px 50px -12px var(--shade), 0 2px 6px var(--shade);
  --toast-bg: light-dark(#1d1915, #ecebf1);
  --toast-fg: light-dark(#fbf7f1, #15161d);
  --toast-act: light-dark(#ffb08a, #c4361b);
}
:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }

/* ---------- 基础 ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  transition: background-color .5s;
}
html:not(.ready) #app { opacity: 0; }
html.ready #app { animation: fade-in .4s ease-out; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
textarea { font: inherit; color: inherit; }
::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); }
:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 3px; }
textarea:focus-visible, [contenteditable]:focus-visible { outline: none; }
::placeholder { color: var(--text-3); opacity: 1; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }
noscript { display: block; padding: 40px; text-align: center; color: var(--text-2); }

.ic { width: 18px; height: 18px; flex: none; }
.grow { flex: 1; }
i.sep { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .45; }

.icon-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  color: var(--text-2);
  transition: background .25s, color .25s, transform .25s var(--ease-spring), opacity .2s;
}
.icon-btn:hover { color: var(--text); }
.icon-btn:active { transform: scale(.9); }
.icon-btn.xs { width: 24px; height: 24px; border-radius: 6px; }
.icon-btn.xs .ic { width: 13px; height: 13px; }

/* ---------- 动画 ---------- */

@keyframes fade-in { from { opacity: 0; } }
@keyframes entry-in { from { opacity: 0; transform: translateY(18px); } }
@keyframes mast-in { from { clip-path: inset(0 0 100% 0); transform: translateY(.3em); } to { clip-path: inset(0 0 -10% 0); } }
@keyframes rule-in { from { transform: scaleX(0); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(18px) scale(.95); filter: blur(4px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes shrink { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }
@keyframes caret-in { from { transform: scaleY(.3); opacity: 0; } }
@keyframes clip-lift { from { opacity: 0; transform: translateY(14px) scale(.86) rotate(0); } }

/* ---------- 顶栏：名字、回实验室、存没存、下载、白天黑夜（文字为主，没有色块） ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 60px;
  padding: 0 max(28px, calc(50% - var(--page-w) / 2));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .3s, background-color .5s;
}
.topbar.scrolled { border-color: var(--line); }
.brand { display: inline-flex; align-items: flex-end; gap: 2px; font: 600 20px/1 var(--font-display); letter-spacing: .02em; color: var(--text); }
.brand i { width: 6px; height: 6px; margin-bottom: 3px; border-radius: 50%; background: var(--accent); transition: transform .45s var(--ease-spring); }
.brand:hover i { transform: scale(1.6); }
.back-link { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; font-size: 13px; color: var(--text-3); transition: color .2s; }
.back-link .ic { width: 15px; height: 15px; }
.back-link:hover { color: var(--text); }
.save-badge { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-3); white-space: nowrap; cursor: default; }
.save-badge i { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); transition: background .3s; }
.save-badge[data-s='saving'] i { background: var(--busy); animation: pulse 1s ease-in-out infinite; }
.save-badge[data-s='full'] { color: var(--danger); }
.save-badge[data-s='full'] i { background: var(--danger); }

.page { max-width: calc(var(--page-w) + 56px); margin: 0 auto; padding: 8px 28px 120px; }

/* ---------- 刊头 ---------- */

.mag-mast { padding-top: 22px; }
.mag-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-2);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .26em;
  color: var(--text-2);
  animation: fade-in .8s ease-out backwards;
}
.mag-title {
  margin: 20px 0 0;
  font: 400 clamp(60px, 7vw, 150px)/1 var(--font-didone);
  letter-spacing: -.015em;
  color: var(--text);
  animation: mast-in 1.1s var(--ease-out) .05s backwards;
}
.mag-line { position: relative; display: flex; align-items: baseline; gap: 16px; margin-top: 22px; padding-top: 14px; }
.mag-line::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 6px;
  border-top: 3px solid var(--text);
  border-bottom: 1px solid var(--text);
  transform-origin: left;
  animation: rule-in 1s var(--ease-out) .2s backwards;
}
.mag-sub { font: 400 14.5px/1.6 var(--font-serif); color: var(--text-2); animation: fade-in .8s ease-out .5s backwards; }

/* ---------- 稿纸：一整栏可以写字的纸 ---------- */

.page-draft { padding-bottom: 30vh; }
.page-draft .mag-sub { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.draft-tip { color: var(--text-3); }
.draft-paper { position: relative; max-width: min(100%, 1060px); margin: clamp(36px, 6vh, 72px) auto 0; animation: entry-in .9s var(--ease-out) .35s backwards; }
.draft-ta {
  display: block;
  width: 100%;
  min-height: 62vh;
  padding: 0;
  border: 0;
  outline: 0;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: var(--text);
  font: 400 clamp(18px, 1.05vw, 21px)/2.05 var(--font-serif);
  letter-spacing: .02em;
  caret-color: var(--accent);
}
.draft-ta::placeholder { color: var(--text-3); }
.draft-ta::selection { background: color-mix(in srgb, var(--accent) 18%, transparent); }

/* 镜像层：和正文排版一模一样但看不见，只用来定位和画「放到这里」的光标 */
.draft-mirror {
  position: absolute;
  z-index: 1;
  color: transparent;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  pointer-events: none;
  user-select: none;
}
.drop-caret { display: none; }
.draft-mirror.dropping .drop-caret {
  position: relative;
  display: inline-block;
  width: 0;
  height: 1.3em;
  vertical-align: -.28em;
}
.draft-mirror.dropping .drop-caret::before {
  content: '';
  position: absolute;
  left: -1.5px;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft), 0 0 14px color-mix(in srgb, var(--accent) 50%, transparent);
  animation: caret-in .25s var(--ease-spring);
}

/* 剪报：一张剪下来的小纸条，顶上贴着半透明胶带，略微歪着 */
.clips { position: fixed; inset: 0; z-index: 35; pointer-events: none; }
.clips.passthrough .clip { pointer-events: none; }
.clip {
  position: absolute;
  left: 0;
  top: 0;
  min-width: 170px;
  max-width: min(380px, 42vw);
  padding-bottom: 4px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  box-shadow: 0 1px 0 var(--line), 0 16px 36px -16px var(--shade);
  transform: rotate(var(--rot, -1deg));
  cursor: grab;
  user-select: none;
  pointer-events: auto;
  transition: transform .4s var(--ease-spring), box-shadow .3s, opacity .25s;
}
.clip::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 50%;
  width: 66px;
  height: 18px;
  background: color-mix(in srgb, var(--accent) 14%, rgba(255, 255, 255, .5));
  border: 1px solid color-mix(in srgb, var(--accent) 12%, transparent);
  transform: translateX(-50%) rotate(-4deg);
}
.clip:hover { transform: rotate(var(--rot, -1deg)) translateY(-2px); box-shadow: 0 1px 0 var(--line), 0 22px 44px -16px var(--shade); }
.clip.dragging { z-index: 2; cursor: grabbing; transform: rotate(0) scale(1.04); box-shadow: 0 30px 60px -18px var(--shade); transition: transform .3s var(--ease-spring), box-shadow .3s; }
.clip.over-text { opacity: .78; transform: rotate(0) scale(.92); }
.clip.lift { animation: clip-lift .6s var(--ease-spring) backwards; }
.clip-h { display: flex; align-items: center; gap: 2px; padding: 9px 6px 0 14px; }
.clip-label { font-size: 10.5px; font-weight: 700; letter-spacing: .2em; color: var(--accent); white-space: nowrap; }
.clip-h .icon-btn { opacity: 0; transition: opacity .2s, color .2s; }
.clip:hover .clip-h .icon-btn, .clip-h .icon-btn:focus-visible { opacity: 1; }
.clip-body {
  max-height: 280px;
  overflow: auto;
  padding: 4px 16px 12px 14px;
  font: 400 15.5px/1.85 var(--font-serif);
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.clip-body[contenteditable='plaintext-only'] { cursor: text; user-select: text; outline: none; box-shadow: inset 0 -1px 0 var(--accent); }
body.is-sorting, body.is-sorting * { cursor: grabbing !important; user-select: none; }

/* ---------- 提示条 ---------- */

.toasts { position: fixed; left: 50%; bottom: 24px; z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; transform: translateX(-50%); pointer-events: none; }
.toast {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 0 8px 0 18px;
  border-radius: 6px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  font-size: 14px;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in .5s var(--ease-spring) backwards;
}
.toast:not(:has(.toast-act)) { padding-right: 18px; }
.toast.out { animation: toast-out .3s var(--ease-in-out) forwards; }
.toast-act { height: 30px; padding: 0 10px; font-weight: 700; color: var(--toast-act); }
.toast-act:hover { text-decoration: underline; }
.toast-bar { position: absolute; left: 0; bottom: 0; width: 100%; height: 2px; background: var(--toast-act); opacity: .6; transform-origin: left; animation: shrink linear forwards; }
.toast.paused .toast-bar { animation-play-state: paused; }

/* ---------- 窄屏 ---------- */

@media (max-width: 720px) {
  .topbar { gap: 10px; padding: 0 14px; }
  .brand { font-size: 18px; }
  .back-link span, .save-badge span { display: none; }
  .page { padding: 4px 16px 100px; }
  .mag-top span:last-child { display: none; }
  .draft-tip, .mag-sub i.sep:last-of-type { display: none; }
  .clip { max-width: 72vw; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
