/*
 * base.css —— 舞台、公共排版、演示控制区与公共页面组件
 *
 * 只消费 tokens.css 中的参数；不定义新的字号／颜色常量，不写观众文案。
 * 页面专用布局放 styles/slides/<slide-id>.css。
 */

/* ===== 1. 文档与视口 ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--letterbox);
}

body {
  font-family: var(--font-sans);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

/* 舞台可用区：扣除底部控制栏后的窗口区域（格式说明第 2.1 节：控制按钮不得覆盖内容） */
.deck-viewport {
  position: fixed;
  inset: 0 0 var(--ui-bar-height) 0;
  overflow: hidden;
  background: var(--letterbox);
}

body.is-controls-hidden .deck-viewport {
  bottom: 0;
}

/* 1920 × 1080 逻辑画布；scripts/core/stage.js 写入 --stage-scale 与左上角位置 */
.deck-stage {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--canvas-w);
  height: var(--canvas-h);
  transform-origin: 0 0;
  transform: scale(var(--stage-scale, 0));
  overflow: hidden;
  background: var(--color-page-bg);
  outline: none;
}

.deck-slide-host {
  width: 100%;
  height: 100%;
  outline: none;
}

/* ===== 2. 幻灯片公共基础 ===== */
.slide {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-weight: var(--weight-regular);
  line-height: var(--lh-body);
  color: var(--color-text);
  font-synthesis: none;
  background:
    url("../assets/brand/polygon-background.jpg") center / cover no-repeat,
    var(--color-page-bg);
}

.slide h1,
.slide h2,
.slide p,
.slide dl,
.slide dd,
.slide ol,
.slide ul {
  margin: 0;
  padding: 0;
}

.slide img {
  display: block;
}

/* 学位帽：参考 PDF 矢量路径（assets/brand/graduation-cap.svg）作遮罩，颜色取 currentColor */
/* 结构页右上校徽（F0、F1、E0 共用位置） */
.page-emblem {
  position: absolute;
  left: var(--page-emblem-x);
  top: var(--page-emblem-y);
  width: var(--page-emblem-w);
  height: auto;
}

.brand-cap {
  display: block;
  aspect-ratio: 87.8 / 78.4;
  background-color: currentColor;
  -webkit-mask: url("../assets/brand/graduation-cap.svg") center / contain no-repeat;
  mask: url("../assets/brand/graduation-cap.svg") center / contain no-repeat;
}

/* ===== 3. 标准正文模板：顶部章节栏 + 校徽 + 蓝绿双竖条小标题（格式说明第 6 节） ===== */
.chapter-bar {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--chapter-bar-top);
  height: var(--chapter-bar-height);
  /* 章节栏在校徽处断开，露出页面底纹（参考 PDF 第 3 页） */
  background: linear-gradient(
    to right,
    var(--color-brand) 0 var(--chapter-emblem-x),
    transparent var(--chapter-emblem-x) calc(var(--chapter-emblem-x) + var(--chapter-emblem-gap-w)),
    var(--color-brand) calc(var(--chapter-emblem-x) + var(--chapter-emblem-gap-w))
  );
  color: var(--color-white);
}

.chapter-bar__cap {
  position: absolute;
  left: 60px;
  top: 6px;
  width: 84px;
}

.chapter-bar__title {
  position: absolute;
  left: var(--chapter-bar-text-x);
  right: calc(var(--canvas-w) - var(--chapter-emblem-x) + var(--space-3));
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  font-size: var(--fs-chapter-bar);
  font-weight: var(--weight-bold);
  line-height: var(--lh-title);
  white-space: nowrap;
  overflow: hidden;
}

/* 右上角校徽：居中放在章节栏断口内，按原比例显示，无底框 */
.chapter-bar__emblem-box {
  position: absolute;
  left: var(--chapter-emblem-x);
  top: calc(var(--chapter-emblem-y) - var(--chapter-bar-top));
  width: var(--chapter-emblem-gap-w);
  display: flex;
  justify-content: center;
}

.chapter-bar__emblem {
  width: var(--chapter-emblem-w);
  height: auto;
}

.slide-title {
  position: absolute;
  left: var(--slide-title-x);
  right: var(--safe-x);
  top: var(--slide-title-top);
  display: flex;
  align-items: flex-start;
  gap: var(--slide-title-gap);
  min-height: var(--title-marker-main-h);
  color: var(--color-heading);
  font-size: var(--fs-slide-title);
  font-weight: var(--weight-bold);
  line-height: var(--lh-title);
}

.slide-title__marker {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  height: var(--title-marker-main-h);
}

.slide-title__marker > span {
  display: block;
  width: var(--title-marker-w);
}

.slide-title__marker > span:first-child {
  height: var(--title-marker-main-h);
  background: var(--color-brand);
}

.slide-title__marker > span:last-child {
  height: var(--title-marker-sub-h);
  background: var(--color-marker-green);
}

/* 首行与竖条垂直居中；两行标题向下自然延伸 */
.slide-title__text {
  padding-top: calc((var(--title-marker-main-h) - 1em * var(--lh-title)) / 2);
  min-width: 0;
}

/* ===== 4. 占位页模板：所属章节、大纲编号、页面状态与统一提示 ===== */
.placeholder-card {
  position: absolute;
  left: var(--content-x);
  right: var(--content-x);
  top: 320px;
  padding: var(--space-5) var(--space-6);
  border: var(--border-regular) dashed var(--color-brand);
  border-radius: var(--radius-card);
  background: color-mix(in srgb, var(--color-white) 72%, transparent);
}

.placeholder-card__facts {
  display: grid;
  gap: var(--space-3);
}

.placeholder-card__row {
  display: grid;
  grid-template-columns: 7em 1fr;
  gap: var(--space-4);
  align-items: baseline;
}

.placeholder-card__row dt {
  color: var(--color-heading);
  font-weight: var(--weight-bold);
}

.placeholder-card__row dd {
  color: var(--color-text-secondary);
}

.placeholder-card__review-id {
  font-weight: var(--weight-bold);
  letter-spacing: 0.04em;
}

.placeholder-card__status {
  display: inline-block;
  padding: 0 var(--space-2);
  border-radius: var(--space-1);
  background: var(--color-ribbon);
  color: var(--color-heading);
  font-weight: var(--weight-bold);
}

.placeholder-card .placeholder-card__notice {
  margin-top: var(--space-5);
  padding: var(--space-3) var(--space-4);
  border-left: var(--space-1) solid var(--color-brand);
  background: var(--color-takeaway-bg);
  color: var(--color-heading);
}

/* ===== 5. 楷体署名（封面与封底共用） ===== */
.signature {
  display: grid;
  grid-template-columns: auto minmax(224px, max-content); /* 封面第三行“汇报时间”日期较宽 */
  grid-auto-rows: 60px;
  column-gap: 18px;
  font-family: var(--font-kai);
  font-size: var(--fs-signature);
  font-weight: var(--weight-regular);
  line-height: var(--lh-title);
  color: var(--color-text);
}

.signature__row {
  display: contents;
}

.signature__label {
  display: flex;
  align-items: center;
}

/* 标签两端对齐，冒号单独成列，使“汇报人／导师”对齐 */
.signature__label-text {
  display: inline-block;
  width: 4em; /* 适配封面 4 字标签“汇报时间”；2–3 字标签按同宽两端对齐 */
  text-align: justify;
  text-align-last: justify;
}

.signature__sep {
  display: inline-block;
  width: 1em;
  text-align: center;
}

.signature__name {
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: var(--border-regular) solid var(--color-text);
  white-space: nowrap;
}

/* 汇报时间：运行时由页级模块写入当天日期（数据不是手写文案）；与姓名行一致加下划线 */
.signature__date {
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: var(--border-regular) solid var(--color-text);
  white-space: nowrap;
}

/* ===== 6. 公共提示页（缺页、无效页面 ID、加载失败） ===== */
.slide--notice {
  display: flex;
  align-items: center;
  justify-content: center;
}

.notice {
  display: grid;
  justify-items: center;
  gap: var(--space-4);
  max-width: 1400px;
  padding: var(--space-6);
  text-align: center;
}

.notice__title {
  color: var(--color-heading);
  font-size: var(--fs-slide-title);
  font-weight: var(--weight-bold);
  line-height: var(--lh-title);
}

.notice__hint {
  color: var(--color-text-secondary);
}

.notice__actions {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-3);
}

.notice__button {
  padding: var(--space-2) var(--space-5);
  border: var(--border-regular) solid var(--color-brand);
  border-radius: var(--space-1);
  background: var(--color-white);
  color: var(--color-heading);
  font: inherit;
  font-weight: var(--weight-bold);
  cursor: pointer;
}

.notice__button:hover {
  background: var(--color-ribbon);
}

.notice__button:focus-visible {
  outline: var(--stroke-arrow) solid var(--color-interactive);
  outline-offset: 4px;
}

.slide--loading {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-heading);
}

/* ===== 7. 画布外演示控制区（屏幕 CSS px，不随画布缩放） ===== */
.deck-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--ui-bar-height);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--ui-bg);
  color: var(--ui-fg);
  font-size: var(--ui-font-size);
  line-height: 1.2;
  visibility: hidden;
}

body.is-ready .deck-controls {
  visibility: visible;
}

body.is-controls-hidden .deck-controls {
  display: none;
}

.deck-controls__group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.deck-controls__group--center {
  justify-content: center;
}

.deck-controls__group--end {
  justify-content: flex-end;
}

.deck-btn {
  display: inline-flex;
  align-items: center;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--color-muted);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}

.deck-btn:hover:not(:disabled) {
  border-color: var(--ui-accent);
  background: var(--ui-accent);
}

.deck-btn:focus-visible,
.deck-show-controls:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 2px;
}

.deck-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.deck-counter {
  min-width: 6.5em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.deck-preview-badge {
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--color-highlight);
  color: var(--color-text);
  font-weight: var(--weight-bold);
  white-space: nowrap;
}

/* 预览模式：只保留预览标识、进入完整演示与全屏 */
body.is-preview [data-action="prev"],
body.is-preview [data-action="next"],
body.is-preview [data-action="toc"] {
  display: none;
}

/* 控制栏隐藏后，右下角保留一个低干扰的恢复按钮 */
.deck-show-controls {
  position: fixed;
  right: 8px;
  bottom: 8px;
  padding: 4px 10px;
  border: 1px solid var(--color-muted);
  border-radius: 6px;
  background: var(--ui-bg);
  color: var(--ui-fg);
  font: inherit;
  font-size: var(--ui-font-size-small);
  opacity: 0.35;
  cursor: pointer;
}

.deck-show-controls:hover,
.deck-show-controls:focus-visible {
  opacity: 1;
}

.deck-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--ui-bar-height) + 16px);
  transform: translateX(-50%);
  max-width: min(90vw, 720px);
  padding: 10px 18px;
  border-radius: 8px;
  background: var(--ui-bg);
  color: var(--ui-fg);
  font-size: var(--ui-font-size);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-duration) var(--motion-ease);
}

.deck-toast.is-visible {
  opacity: 1;
}

/* ===== 8. 启动兜底（内容由 tools/sync_boot_fallback.py 从 texts.json 生成） ===== */
.boot-fallback {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 24px;
  background: var(--color-page-bg);
  color: var(--color-text-secondary);
  font-size: var(--ui-boot-font-size);
  line-height: var(--ui-line-height);
  text-align: center;
}

.boot-fallback__title {
  margin: 0;
  color: var(--color-heading);
  font-size: var(--ui-boot-title-size);
  font-weight: var(--weight-bold);
}

.boot-fallback__hint {
  margin: 0;
}

/* ===== 9. 分层翻页过渡（人类 2026-11-25 要求“高级一点的动效”） =====
 * scripts/app.js 在离页时保留旧页 DOM 作为退场层，并在 .deck-slide-host 上切换
 * data-transition="next|prev"；.is-transitioning 期间旧页与新页绝对定位重叠。
 *   next：旧页向左侧淡出缩小，新页从右侧滑入并落定；prev 方向相反。
 *   新页的页内一级元素（章节栏、标题、卡片区、底栏）再错峰轻微上浮。
 * 首次进入、同页导航与系统“减少动态效果”下不启用分层动画。
 */
.deck-slide-host {
  position: relative;
}

.deck-slide-host.is-transitioning > .slide {
  position: absolute;
  inset: 0;
}

.deck-slide-host.is-transitioning > .slide--leaving {
  z-index: 1;
  pointer-events: none;
  will-change: transform, opacity, filter;
  animation-duration: var(--motion-duration-leave);
  animation-timing-function: var(--motion-ease-in);
  animation-fill-mode: forwards;
}

.deck-slide-host.is-transitioning > .slide--entering {
  z-index: 2;
  will-change: transform, opacity, filter;
  animation-duration: var(--motion-duration-enter);
  animation-timing-function: var(--motion-ease-out);
  animation-fill-mode: both;
}

.deck-slide-host[data-transition="next"] > .slide--leaving {
  animation-name: slide-leave-next;
}

.deck-slide-host[data-transition="next"] > .slide--entering {
  animation-name: slide-enter-next;
  box-shadow: -36px 0 64px rgb(0 0 0 / 0.16);
}

.deck-slide-host[data-transition="prev"] > .slide--leaving {
  animation-name: slide-leave-prev;
}

.deck-slide-host[data-transition="prev"] > .slide--entering {
  animation-name: slide-enter-prev;
  box-shadow: 36px 0 64px rgb(0 0 0 / 0.16);
}

/* 页内一级元素错峰上浮：只作用于入场层，结束后随类名移除 */
.deck-slide-host.is-transitioning > .slide--entering > * {
  animation: slide-part-in var(--motion-duration-part) var(--motion-ease-out) 70ms backwards;
}

/* 入场页保持不透明：像一张新纸从侧边盖上来，避免与旧页文字重影 */
@keyframes slide-enter-next {
  from {
    transform: translateX(84px) scale(1.01);
    filter: blur(1.6px);
  }
  to {
    transform: none;
    filter: blur(0);
  }
}

@keyframes slide-enter-prev {
  from {
    transform: translateX(-84px) scale(1.01);
    filter: blur(1.6px);
  }
  to {
    transform: none;
    filter: blur(0);
  }
}

@keyframes slide-leave-next {
  from {
    opacity: 1;
    transform: none;
    filter: blur(0);
  }
  to {
    opacity: 0;
    transform: translateX(-40px) scale(0.985);
    filter: blur(1.6px);
  }
}

@keyframes slide-leave-prev {
  from {
    opacity: 1;
    transform: none;
    filter: blur(0);
  }
  to {
    opacity: 0;
    transform: translateX(40px) scale(0.985);
    filter: blur(1.6px);
  }
}

/* 内容只做轻微上浮与由半透明到清晰的“落定”，避免过渡中段出现空白闪帧 */
@keyframes slide-part-in {
  from {
    opacity: 0.6;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }
}
