/* CRT 屏幕效果：轻扫描线、暗角、静态角落色差与局部器物色散。
   2026-10-01 用户确认 SNAPTIC 独立预览后接入；正文不加重影。
   pointer-events: none，不挡任何点击；开关见 js/crt-toggle.js。 */
:root {
  --crt-fringe-red: #C16262;
  --crt-fringe-cyan: #6A9C9B;
  --crt-fringe-edge: #A1BABB;
  --crt-fringe-opacity: .04;
  /* 扫描线与暗角的底色（RGB 三个数）；深色模式在 css/dark-mode.css 改成纯黑。 */
  --crt-line-rgb: 30, 22, 12;
  --crt-line-opacity: .016;
  --crt-vignette-rgb: 40, 30, 20;
}
html.crt-on::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(var(--crt-line-rgb), var(--crt-line-opacity)) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 70%, rgba(var(--crt-vignette-rgb), .025) 100%);
}

.crt-filter-defs { position: absolute; pointer-events: none; }
#crtCornerFringe { display: none; position: fixed; inset: 0; z-index: 2147483646; pointer-events: none; opacity: var(--crt-fringe-opacity); background:
  radial-gradient(ellipse at -4% -4%, var(--crt-fringe-red) 0, transparent 36%),
  radial-gradient(ellipse at 104% 4%, var(--crt-fringe-cyan) 0, transparent 36%),
  radial-gradient(ellipse at -4% 96%, var(--crt-fringe-cyan) 0, transparent 36%),
  radial-gradient(ellipse at 104% 104%, var(--crt-fringe-red) 0, transparent 36%); }
html.dark #crtCornerFringe { opacity: calc(var(--crt-fringe-opacity) * 1.5); }
/* 历史对照预览自行接管同一层，避免与生产效果叠加。 */
html.crt-on:not([data-screen-preview]) #crtCornerFringe { display: block; }
html.crt-on:not([data-screen-preview]) #ritualShell > img,
html.crt-on:not([data-screen-preview]) #ritualCoinCanvas { filter: url('#crtColorSplit'); }
.crt-action-fringe { position: absolute !important; inset: 0; z-index: 3 !important; pointer-events: none; border-radius: inherit; opacity: 0; }
.crt-action-fringe::before, .crt-action-fringe::after { content: ''; position: absolute; inset: 0; border-radius: inherit; }
.crt-action-fringe::before { box-shadow: inset 1px 0 var(--crt-fringe-red), inset 0 1px var(--crt-fringe-red); transform: translateX(-1px); clip-path: inset(0 0 58% 0); }
.crt-action-fringe::after { box-shadow: inset -1px 0 var(--crt-fringe-edge), inset 0 -1px var(--crt-fringe-edge); transform: translateX(1px); clip-path: inset(58% 0 0 0); }
html.crt-on:not([data-screen-preview]) .crt-glitch > .crt-action-fringe { animation: crt-action-glitch var(--crt-glitch-duration, 280ms) steps(1, end) both; }
.crt-hover-glitch { --crt-glitch-duration: 380ms; }
@keyframes crt-action-glitch {
  0% { opacity: 0; transform: translateX(0); }
  15% { opacity: .65; transform: translateX(1px); }
  45% { opacity: .4; transform: translateX(-1px); }
  75% { opacity: .2; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
  html.crt-on .crt-glitch > .crt-action-fringe { animation: none !important; }
}
@media (forced-colors: active), print {
  #crtCornerFringe, .crt-action-fringe { display: none !important; }
  html.crt-on #ritualShell > img, html.crt-on #ritualCoinCanvas { filter: none !important; }
}

/* 左下入口高于舞台，低于原生 dialog top layer。 */
:root {
  --display-surface: var(--figma-base-colours-white-02);
  --display-edge: var(--figma-base-colours-black-01-50);
  --display-shadow: var(--figma-base-colours-black-01-25);
  --display-rule: var(--figma-base-colours-grey-02);
  --display-muted: var(--figma-text-p-normal-colour-description);
  --display-switch-off: var(--figma-base-colours-black-01-50);
  --display-switch-on: var(--figma-deco-green);
  --display-thumb: var(--figma-base-colours-white-01);
  --display-scrim: var(--figma-base-colours-black-01-50);
  /* 固定真实纸／墨绿样本，不随当前模式反转。 */
  --display-preview-light: var(--figma-base-colours-white-02);
  --display-preview-light-ink: var(--figma-base-colours-black-01);
  --display-preview-dark: #173435;
  --display-preview-dark-ink: #EDE6DC;
}
.display-settings {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 40;
  color: var(--figma-text-p-normal-colour-normal);
  font: 400 14px/1.5 'Noto Sans SC', sans-serif;
}
.display-settings *, .display-settings *::before, .display-settings *::after { box-sizing: border-box; }
.display-settings[hidden], .display-panel[hidden], .display-scrim[hidden] { display: none; }
.display-settings button { color: inherit; font: inherit; cursor: pointer; touch-action: manipulation; }
.display-settings .display-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 4px;
  background: var(--display-surface);
  font: 400 12px/1.5 'Fusion Pixel 12px Prop zh_hans', sans-serif;
  box-shadow: inset 0 1px 0 var(--figma-button-general-inner-glow), inset 0 -1px 0 var(--figma-button-general-inner-shadow), inset 0 0 0 1px var(--display-edge);
}
.display-trigger svg { width: 16px; height: 16px; fill: currentColor; shape-rendering: crispEdges; }
.display-trigger[aria-expanded='true'] { background: var(--figma-button-general-fill-unavailable); }
.display-panel {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  width: 272px;
  max-height: calc(100dvh - 88px - env(safe-area-inset-bottom) - env(safe-area-inset-top));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--figma-deco-green) var(--display-surface);
  padding: 12px 16px 16px;
  border-radius: 4px;
  background: var(--display-surface);
  box-shadow: 0 8px 24px var(--display-shadow), inset 0 1px 0 var(--figma-button-general-inner-glow), inset 0 0 0 1px var(--display-edge);
  animation: display-enter 150ms ease-out;
}
.display-heading { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.display-settings .display-heading h2 { margin: 0; font: 400 24px/1.2 'Fusion Pixel 12px Prop zh_hans', sans-serif; }
.display-settings .display-close { min-width: 44px; min-height: 44px; margin-right: -8px; padding: 0 8px; border: 0; border-radius: 4px; background: transparent; color: var(--display-muted); }
.display-panel fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.display-panel legend { padding: 0; margin-bottom: 10px; color: var(--display-muted); font-size: 14px; }
.display-appearance { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.display-settings .display-choice {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100px;
  margin: 0;
  padding: 6px;
  border-radius: 4px;
  background: var(--display-choice-surface);
  color: var(--display-choice-ink);
  box-shadow: inset 0 0 0 1px var(--display-edge);
  cursor: pointer;
  touch-action: manipulation;
}
.display-choice:has(input[value='light']) { --display-choice-surface: var(--display-preview-light); --display-choice-ink: var(--display-preview-light-ink); }
.display-choice:has(input[value='dark']) { --display-choice-surface: var(--display-preview-dark); --display-choice-ink: var(--display-preview-dark-ink); }
.display-choice:has(input:checked) { box-shadow: inset 0 0 0 2px var(--display-choice-ink); }
/* 原生 radio 保留读屏、Tab 与方向键，只隐藏默认灰色圆点。 */
.display-choice input { position: absolute; width: 1px; height: 1px; margin: 0; padding: 0; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.display-swatch { display: flex; align-items: center; padding-left: 12px; height: 52px; font: 400 24px/1 'Fusion Pixel 12px Prop zh_hans', sans-serif; }
.display-choice-caption { display: flex; align-items: center; justify-content: flex-end; padding: 0 6px 2px; line-height: 20px; }
.display-check { display: inline-flex; align-items: center; visibility: hidden; color: var(--display-choice-ink); }
.display-check svg { width: 16px; height: 16px; fill: currentColor; shape-rendering: crispEdges; }
.display-choice:has(input:checked) .display-check { visibility: visible; }
.display-effect-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--display-rule); }
.display-settings .display-effect { display: flex; align-items: center; justify-content: center; min-width: 48px; min-height: 44px; padding: 0 2px; border: 0; border-radius: 4px; background: transparent; }
.display-switch-track { display: flex; align-items: center; width: 40px; height: 24px; padding: 3px; border-radius: 12px; background: var(--display-switch-off); box-shadow: inset 0 1px 2px var(--figma-button-general-inner-shadow); }
.display-switch-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--display-thumb); box-shadow: 0 1px 2px var(--display-shadow); transition: transform 150ms ease-out; }
.display-effect[aria-checked='true'] .display-switch-track { background: var(--display-switch-on); }
.display-effect[aria-checked='true'] .display-switch-thumb { transform: translateX(16px); }
.display-settings :focus-visible { outline: 2px solid var(--figma-deco-green); outline-offset: 3px; }
.display-choice:has(input:focus-visible) { outline: 2px solid var(--figma-deco-green); outline-offset: 3px; }
.display-settings .display-choice input:focus-visible { outline: none; }
.display-settings button:active { transform: translateY(1px); }
.display-choice:active { transform: translateY(1px); }
@media (hover: hover) { .display-close:hover, .display-trigger:hover, .display-effect:hover { background: var(--figma-button-general-fill-unavailable); } .display-choice:hover { filter: brightness(1.06); } }
.display-scrim { position: fixed; inset: 0; background: var(--display-scrim); }
@media (max-width: 759px) {
  .display-panel { position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: calc(100dvh - max(16px, env(safe-area-inset-top))); padding: 16px max(20px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); border-radius: 8px 8px 0 0; box-shadow: 0 -8px 32px var(--display-shadow), inset 0 1px 0 var(--display-edge); }
  .display-heading { margin-bottom: 16px; }
  .display-swatch { height: 56px; }
  .display-settings[data-open='true'] .display-trigger { visibility: hidden; }
}
@keyframes display-enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .display-panel { animation: none; } .display-switch-thumb { transition: none; } }
@media (forced-colors: active), print { html.crt-on::after { display: none; } }
@media (forced-colors: active) { .display-trigger, .display-choice, .display-panel, .display-switch-track { outline: 1px solid CanvasText; } .display-choice:has(input:checked) { outline: 2px solid Highlight; } .display-check { color: Highlight; } .display-switch-thumb { background: ButtonText; } .display-effect[aria-checked='true'] .display-switch-track { background: Highlight; } }
@media print { .display-settings { display: none; } }
