/* ============================================================
 * base.css — 宣纸水墨基调 · 布局骨架 · 全局构件
 * 纸白 #f5f1e8 · 墨 #2b2b2b · 朱砂 #b03a2e · 鎏金 #c9a227
 * ============================================================ */

:root {
  --paper: #f5f1e8;
  --paper-deep: #ece5d6;
  --paper-card: #f8f4ec;
  --ink: #2b2b2b;
  --ink-60: rgba(43, 43, 43, .6);
  --ink-45: rgba(43, 43, 43, .45);
  --ink-25: rgba(43, 43, 43, .25);
  --ink-15: rgba(43, 43, 43, .15);
  --cinnabar: #b03a2e;
  --cinnabar-deep: #8a2f24;
  --cinnabar-soft: rgba(176, 58, 46, .09);
  --gold: #c9a227;
  --alarm: #d9a40b;
  --serif: "Songti SC", "STSong", "STZhongsong", "SimSun", "FangSong", serif;

  /* 31px + 纸页 1px 边 = 32px，使页面横线与舞台层横线(32px 节律)同相对齐 */
  --page-top: 31px;
  --page-bottom: calc(58px + env(safe-area-inset-bottom, 0px));
  --page-side: max(12px, calc(50% - 320px));
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--serif);
  color: var(--ink);
  background: var(--paper);
  /* 宣纸质感: 微纤维 + 边缘晕染 */
  background-image:
    radial-gradient(ellipse at 18% 8%, rgba(255, 255, 255, .55), transparent 46%),
    radial-gradient(ellipse at 85% 96%, rgba(160, 140, 100, .10), transparent 52%),
    repeating-linear-gradient(93deg, transparent 0 22px, rgba(120, 105, 80, .022) 22px 23px),
    repeating-linear-gradient(2deg, transparent 0 26px, rgba(120, 105, 80, .02) 26px 27px);
  opacity: 0;
  transition: opacity .8s ease;
}
body.booted { opacity: 1; }
body.dragging { user-select: none; cursor: grabbing; }

::selection { background: var(--cinnabar-soft); color: var(--cinnabar-deep); }

button {
  font-family: var(--serif);
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
}
input, textarea {
  font-family: var(--serif);
  color: var(--ink);
  outline: none;
}

/* 细雅滚动条：静止时隐去，滚动时短暂显现 */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: transparent; border-radius: 2px; }
*.is-scrolling::-webkit-scrollbar-thumb { background: var(--ink-25); }
::-webkit-scrollbar-track { background: transparent; }

/* Firefox */
@supports (-moz-appearance: none) {
  * { scrollbar-width: thin; scrollbar-color: transparent transparent; }
  *.is-scrolling { scrollbar-color: var(--ink-25) transparent; }
}

/* ================= 舞台与层 ================= */
#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; }

.layer {
  position: absolute;
  inset: 0;
  will-change: transform, opacity;
}
.layer.hidden { display: none; }
#weekview, #monthview {
  overflow-y: auto;
  padding: var(--page-top) 14px calc(var(--page-bottom) + 8px);
  -webkit-overflow-scrolling: touch;
}
#book { perspective: 2300px; }

/* ================= 纸页 ================= */
.paper {
  background: var(--paper-card);
  background-image:
    radial-gradient(ellipse at 80% 0%, rgba(255, 255, 255, .5), transparent 40%),
    repeating-linear-gradient(91deg, transparent 0 34px, rgba(120, 105, 80, .018) 34px 35px);
  border: 1px solid var(--ink-25);
  box-shadow:
    0 1px 2px rgba(60, 50, 30, .06),
    0 10px 34px rgba(60, 50, 30, .10);
}

#book > .page, .flip-leaf {
  position: absolute;
  top: var(--page-top);
  bottom: var(--page-bottom);
  left: var(--page-side);
  right: var(--page-side);
}
.page {
  border-radius: 3px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 22px 22px 34px;
  touch-action: pan-y;
}
.page.under-page::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, rgba(50, 40, 20, .10), transparent 42%);
  pointer-events: none;
}

/* ================= 左上角工具栏 ================= */
#toolbar-btn {
  position: fixed;
  top: calc(20px + env(safe-area-inset-top, 0px));
  left: 16px;
  z-index: 60;
  width: 38px;
  height: 38px;
  border: 1px solid var(--ink-45);
  border-radius: 50%;
  background: var(--paper-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform .3s ease, border-color .3s, box-shadow .3s;
  box-shadow: 0 2px 8px rgba(60, 50, 30, .10);
}
#toolbar-btn:hover { border-color: var(--ink); }
#toolbar-btn.active { transform: rotate(90deg); border-color: var(--cinnabar); }
.tb-stroke {
  display: block;
  height: 1.4px;
  background: var(--ink);
  border-radius: 2px;
  transition: background .3s;
}
.tb-stroke:nth-child(1) { width: 15px; }
.tb-stroke:nth-child(2) { width: 10px; }
.tb-stroke:nth-child(3) { width: 14px; }
#toolbar-btn.active .tb-stroke { background: var(--cinnabar); }

#toolbar-panel {
  position: fixed;
  top: calc(66px + env(safe-area-inset-top, 0px));
  left: 16px;
  z-index: 55;
  transform: translateX(-130%);
  opacity: 0;
  transition: transform .42s cubic-bezier(.22, .9, .3, 1), opacity .35s;
  pointer-events: none;
}
#toolbar-panel.open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}
.tb-list {
  background: var(--paper-card);
  border: 1px solid var(--ink-25);
  border-radius: 3px;
  box-shadow: 0 10px 30px rgba(60, 50, 30, .16);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
}
.tb-group { display: flex; flex-direction: column; gap: 2px; }
.tb-group + .tb-group { margin-top: 5px; padding-top: 6px; border-top: 1px solid var(--ink-15); }
.tb-group-title { display: none; }
.tb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 8px;
  border-radius: 2px;
  font-size: 14px;
  letter-spacing: .08em;
  opacity: 0;
  transform: translateX(-8px);
  transition: opacity .3s, transform .3s, background .25s;
}
#toolbar-panel.open .tb-item { opacity: 1; transform: none; }
.tb-item:hover { background: var(--cinnabar-soft); }
.tb-icon {
  width: 26px;
  height: 26px;
  border: 1px solid var(--ink-45);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex: none;
}
.tb-item:hover .tb-icon { border-color: var(--cinnabar); color: var(--cinnabar); }

/* ================= 右上角 周结印章 ================= */
#corner-btn {
  position: fixed;
  top: calc(20px + env(safe-area-inset-top, 0px));
  right: 16px;
  z-index: 40;
  width: 38px;
  height: 38px;
  border: 1.6px solid var(--cinnabar);
  border-radius: 4px;
  color: var(--cinnabar);
  background: var(--paper-card);
  font-size: 17px;
  transform: rotate(-4deg);
  box-shadow: 0 2px 8px rgba(176, 58, 46, .14), inset 0 0 6px rgba(176, 58, 46, .07);
  transition: transform .3s ease, background .3s, color .3s, opacity .3s;
}
#corner-btn:hover { transform: rotate(-4deg) scale(1.07); }
#corner-btn.is-return { background: var(--cinnabar); color: var(--paper); }
#corner-btn.hidden { opacity: 0; pointer-events: none; }

/* ================= 桌面翻页箭头 ================= */
.edge-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  font-size: 34px;
  color: var(--ink-45);
  width: 40px;
  height: 72px;
  line-height: 68px;
  display: none;
  transition: color .25s, transform .25s;
}
#edge-prev { left: 2px; }
#edge-next { right: 2px; }
.edge-arrow:hover { color: var(--ink); transform: translateY(-50%) scale(1.15); }
.edge-arrow.hidden { display: none !important; }
@media (hover: hover) and (pointer: fine) {
  .edge-arrow { display: block; }
}

/* ================= 底部层级墨点 ================= */
#level-dots {
  position: fixed;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  gap: 10px;
}
.ld {
  width: 30px;
  height: 30px;
  border: 1px solid var(--ink-45);
  border-radius: 50%;
  font-size: 12px;
  color: var(--ink-60);
  background: var(--paper-card);
  transition: all .3s ease;
}
.ld.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  transform: scale(1.08);
}

/* ================= 轻提示 ================= */
#toast {
  position: fixed;
  bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translate(-50%, 12px);
  z-index: 120;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  letter-spacing: .1em;
  padding: 8px 18px;
  border-radius: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
  max-width: 80vw;
  text-align: center;
}
#toast.show { opacity: .94; transform: translate(-50%, 0); }
#toast.save-error {
  color: #fff8df;
  background: rgba(126, 42, 32, .94);
  border-color: rgba(255, 214, 102, .72);
}

/* ================= 水墨模态 ================= */
.ink-modal-mask {
  position: fixed;
  inset: 0;
  z-index: 95;
  background: rgba(43, 43, 43, .28);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .26s ease;
  padding: 20px;
}
.ink-modal-mask.show { opacity: 1; }
.ink-modal {
  background: var(--paper-card);
  border: 1px solid var(--ink-25);
  border-radius: 3px;
  box-shadow: 0 16px 50px rgba(40, 30, 10, .25);
  width: min(88vw, 400px);
  max-height: 82vh;
  overflow-y: auto;
  padding: 24px 22px 18px;
  transform: scale(.94) translateY(8px);
  transition: transform .3s cubic-bezier(.22, .9, .3, 1);
}
.ink-modal-mask.show .ink-modal { transform: none; }
.ink-modal.wide { width: min(92vw, 560px); }
.ink-modal-body {
  font-size: 14.5px;
  line-height: 1.9;
  letter-spacing: .05em;
  text-align: center;
}
.ink-modal-body b { color: var(--cinnabar); font-weight: 600; }
.modal-note { font-size: 12px; color: var(--ink-60); }
.ink-modal-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
  flex-wrap: wrap;
}
.ink-btn {
  border: 1px solid var(--ink-45);
  border-radius: 2px;
  padding: 7px 18px;
  font-size: 13.5px;
  letter-spacing: .12em;
  transition: all .25s ease;
  background: transparent;
}
.ink-btn:hover { border-color: var(--ink); background: rgba(43, 43, 43, .04); }
.ink-btn.primary { border-color: var(--cinnabar); color: var(--cinnabar); }
.ink-btn.primary:hover { background: var(--cinnabar); color: var(--paper); }
.ink-btn.disabled { opacity: .4; pointer-events: none; }

.backup-ta {
  width: 100%;
  height: 180px;
  border: 1px solid var(--ink-25);
  border-radius: 2px;
  background: rgba(255, 255, 255, .4);
  font-size: 11px;
  font-family: monospace;
  padding: 8px;
  resize: vertical;
  text-align: left;
}
.backup-file { margin-top: 10px; font-size: 12px; width: 100%; }

/* 关于 */
.about-box { padding: 4px 0; }
.about-title { font-size: 17px; letter-spacing: .25em; margin-bottom: 10px; }
.about-line { font-size: 13px; color: var(--ink-60); letter-spacing: .1em; line-height: 2; }
.about-rule { height: 1px; background: var(--ink-15); margin: 12px 20px; }
.about-ps { font-size: 12.5px; color: var(--cinnabar); letter-spacing: .04em; line-height: 1.9; }

/* ================= 覆盖层(总统计/赠语集/转盘) ================= */
.overlay-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(236, 229, 214, .55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity .38s ease;
}
.overlay-mask.show { opacity: 1; }
.overlay-sheet {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translate(-50%, 26px);
  width: min(680px, calc(100vw - 22px));
  border-radius: 3px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 26px 22px 40px;
  opacity: 0;
  transition: transform .45s cubic-bezier(.22, .9, .3, 1), opacity .4s;
}
.overlay-mask.show .overlay-sheet { transform: translate(-50%, 0); opacity: 1; }
.overlay-close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 5;
  width: 32px;
  height: 32px;
  border: 1px solid var(--ink-45);
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  background: var(--paper-card);
  transition: all .25s;
}
.overlay-close:hover { border-color: var(--cinnabar); color: var(--cinnabar); transform: rotate(90deg); }

.overlay-title {
  font-size: 22px;
  font-weight: 500;
  text-align: center;
  letter-spacing: .4em;
  text-indent: .4em;
  margin: 8px 0 4px;
}
.overlay-sub {
  text-align: center;
  font-size: 12px;
  color: var(--ink-60);
  letter-spacing: .2em;
  margin-bottom: 14px;
}
.quiet-note {
  text-align: center;
  color: var(--ink-60);
  font-size: 12.5px;
  letter-spacing: .1em;
  margin: 16px 0;
}

/* ================= 响应式：移动端顶部留白 =================
 * 固定的工具栏(左上)与课堂小结圈(右上)在窄屏会压住正文，
 * 页面顶部让出空间。主题若自带 .page 规则(如 classroom)特指度更高，
 * 会覆盖此处，故此处仅兜底无专属样式的主题(如 botanical)。 */
@media (max-width: 820px) {
  .page { padding-top: 56px; }
  #weekview,
  #monthview { padding-top: calc(60px + env(safe-area-inset-top, 0px)); }
}
