/* =========================================================
   3color · 三色影相 — 早期彩色摄影复古风格
   ========================================================= */
:root {
  --bg: #12100d;
  --panel: #1e1915;
  --panel-2: #26201a;
  --line: #3a2f25;
  --line-hi: #57452f;
  --brass: #c8a45c;
  --brass-hi: #e0c184;
  --brass-dim: rgba(200, 164, 92, .35);
  --cream: #efe6d8;
  --muted: #a3937d;
  --red: #d9534f;
  --green: #7cb26a;
  --blue: #6f8fd1;
  --danger: #c6554d;
  --serif: Georgia, "Times New Roman", "Noto Serif SC", "Songti SC", SimSun, serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(120% 90% at 50% 0%, #211a14 0%, var(--bg) 55%, #0e0c0a 100%);
  color: var(--cream);
  font-family: var(--serif);
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* film grain overlay */
body::before {
  content: "";
  position: fixed; inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

.hidden { display: none !important; }
.disabled { opacity: .45; pointer-events: none; }

/* ---------------- top bar ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 18px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.emblem { width: 38px; height: 38px; filter: drop-shadow(0 2px 6px rgba(200,164,92,.35)); }
.brand-text h1 {
  font-size: 20px; letter-spacing: .18em; font-weight: 600; color: var(--brass-hi);
  line-height: 1.1;
}
.brand-text span { display: block; font-size: 11px; letter-spacing: .22em; color: var(--muted); }

/* ---------------- buttons ---------------- */
.primary-btn {
  display: block; width: 100%;
  padding: 15px 20px; border-radius: 30px;
  border: 1px solid var(--brass);
  background: linear-gradient(180deg, #e8cd8d 0%, var(--brass) 55%, #a9833f 100%);
  color: #241b0e; font-family: var(--serif);
  font-size: 17px; font-weight: 700; letter-spacing: .3em;
  box-shadow: 0 4px 18px rgba(200,164,92,.35), inset 0 1px 0 rgba(255,255,255,.45);
  cursor: pointer; text-indent: .3em;
}
.primary-btn:active { transform: scale(.97); }
.primary-btn:disabled { opacity: .6; }

.ghost-btn {
  padding: 8px 14px; border-radius: 18px;
  border: 1px solid var(--line-hi);
  background: rgba(38,32,26,.6);
  color: var(--cream); font-family: var(--serif);
  font-size: 13px; letter-spacing: .12em; cursor: pointer;
}
.ghost-btn:active { transform: scale(.96); }

.side-btn {
  min-width: 62px; padding: 10px 14px; border-radius: 20px;
  border: 1px solid var(--line-hi);
  background: var(--panel-2);
  color: var(--cream); font-family: var(--serif);
  font-size: 14px; letter-spacing: .08em; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
}
.side-btn:active { transform: scale(.94); }
.side-btn.toggle.on, .ghost-btn.toggle.on {
  border-color: var(--brass); color: var(--brass-hi);
  box-shadow: 0 0 12px rgba(200,164,92,.25);
}
.danger-ghost { color: #d98a82; border-color: #6e3a34; }

/* ---------------- screens ---------------- */
.screen { animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------- intro ---------------- */
#screen-intro { padding: 18px 22px calc(24px + env(safe-area-inset-bottom)); }
.intro-card {
  max-width: 460px; margin: 0 auto;
  background: linear-gradient(180deg, var(--panel) 0%, #18130f 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px 22px;
  box-shadow: 0 18px 50px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.05);
}
.quote {
  font-size: 15px; font-style: italic; color: var(--brass);
  text-align: center; margin-bottom: 16px; line-height: 1.7;
  animation: floaty 4s ease-in-out infinite;
}
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.intro-text { font-size: 14px; line-height: 1.85; color: #d8cdbb; margin-bottom: 18px; }
.intro-text b.cr { color: var(--red); } .intro-text b.cg { color: var(--green); } .intro-text b.cb { color: var(--blue); }

.steps { list-style: none; margin: 0 0 22px; }
.steps li {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; letter-spacing: .05em; color: var(--cream);
  padding: 7px 0; border-bottom: 1px dashed var(--line);
}
.steps li:last-child { border-bottom: none; }
.dot {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 1px solid rgba(255,255,255,.15);
}
.dot.r { background: var(--red); } .dot.g { background: var(--green); }
.dot.b { background: var(--blue); } .dot.w { background: #efe6d8; }
.hint { margin-top: 14px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.7; }

/* ---------------- camera ---------------- */
#screen-camera {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 20px calc(16px + env(safe-area-inset-bottom));
}
.stage-wrap { width: 100%; max-width: 480px; }
.stage {
  position: relative; width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: #050403;
  border: 1px solid var(--line-hi);
  box-shadow: 0 10px 34px rgba(0,0,0,.55), inset 0 0 0 1px rgba(0,0,0,.6);
}
.stage video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover;
}
.corners i {
  position: absolute; width: 22px; height: 22px;
  border: 2px solid var(--brass);
  opacity: .9;
  filter: drop-shadow(0 0 4px rgba(200,164,92,.6));
}
.corners i:nth-child(1) { top: 10px; left: 10px; border-right: none; border-bottom: none; }
.corners i:nth-child(2) { top: 10px; right: 10px; border-left: none; border-bottom: none; }
.corners i:nth-child(3) { bottom: 10px; left: 10px; border-right: none; border-top: none; }
.corners i:nth-child(4) { bottom: 10px; right: 10px; border-left: none; border-top: none; }

.guide { position: absolute; inset: 0; pointer-events: none; }
.chip {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(12,10,8,.72);
  border: 1px solid var(--brass);
  border-radius: 20px;
  padding: 6px 14px;
  backdrop-filter: blur(4px);
}
.chip i { width: 10px; height: 10px; border-radius: 50%; display: block; }
.chip b { font-size: 15px; letter-spacing: .05em; }
.chip span { font-size: 13px; color: var(--cream); letter-spacing: .1em; }

.spring-timer {
  position: absolute;
  bottom: 14px; left: 14px;
  width: 38px; height: 38px;
  z-index: 4;
  pointer-events: none;
  animation: timerIn .3s ease;
}
@keyframes timerIn {
  from { opacity: 0; transform: scale(.6); }
  to { opacity: 1; transform: scale(1); }
}
.spring-timer svg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  transform: rotate(-90deg); /* 从 12 点方向起 */
}
.spring-timer .st-bg {
  fill: none; stroke: rgba(255, 255, 255, .18); stroke-width: 4;
}
.spring-timer .st-fg {
  fill: none; stroke: var(--brass); stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 163.4; /* 2πr，r=26 */
  stroke-dashoffset: 0;
  filter: drop-shadow(0 0 4px rgba(200, 164, 92, .7));
}

.hold-msg {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  font-size: 13px; letter-spacing: .3em; color: #fff;
  background: rgba(12,10,8,.6); border-radius: 14px; padding: 6px 14px;
  animation: springpulse 1.1s ease-in-out infinite;
}
@keyframes springpulse { 0%,100% { opacity: .75; } 50% { opacity: 1; } }

/* plates + progress */
.plates { display: flex; gap: 14px; margin-top: 16px; }
.plate {
  position: relative; width: 58px; height: 58px;
  border-radius: 6px;
  background: #0b0907;
  overflow: hidden;
}
.plate .pl-label {
  position: absolute; top: 3px; left: 6px;
  font-size: 12px; font-weight: 700; letter-spacing: .04em;
  z-index: 2; color: var(--muted);
  text-shadow: 0 1px 2px rgba(0,0,0,.8);
}
.plate:nth-child(1) .pl-label { color: var(--red); }
.plate:nth-child(2) .pl-label { color: var(--green); }
.plate:nth-child(3) .pl-label { color: var(--blue); }
.pl-img {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  opacity: 0; transition: opacity .5s ease;
}
.plate.pending { border: 1px dashed var(--line-hi); }
.plate.active {
  border: 2px solid var(--brass);
  box-shadow: 0 0 0 3px rgba(200,164,92,.18), 0 0 14px rgba(200,164,92,.4);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 3px rgba(200,164,92,.14); } 50% { box-shadow: 0 0 0 5px rgba(200,164,92,.3); } }
.plate.done { border: 1px solid var(--brass); }
.plate.done .pl-img { opacity: 1; }

.progress {
  margin-top: 12px; width: min(100%, 480px);
  height: 3px; border-radius: 2px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.progress span {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--red), var(--green), var(--blue));
  border-radius: 2px;
  transition: width .7s cubic-bezier(.4,0,.2,1);
}

/* controls */
.controls {
  margin-top: 18px;
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 14px;
}
.controls .group-left { grid-column: 1; justify-self: start; display: flex; align-items: center; gap: 10px; }
.controls .shutter { grid-column: 2; }
.controls #btn-flip { grid-column: 3; justify-self: end; }

/* 相册入口按钮（图标圆形） */
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line-hi);
  background: var(--panel-2); color: var(--cream);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { transform: scale(.94); }
.icon-btn.disabled { pointer-events: none; opacity: .5; }

/* 最近照片预览小窗（圆角小方图） */
.preview-thumb {
  width: 44px; height: 44px; border-radius: 11px; padding: 0;
  border: 1px solid var(--line-hi); background: #0b0907;
  position: relative; overflow: hidden; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
}
.preview-thumb .preview-img {
  position: absolute; inset: 0;
  background-size: cover; background-position: center; background-color: #0b0907;
}
.preview-thumb .preview-empty {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center; color: var(--muted);
}
.preview-thumb .preview-empty svg { width: 22px; height: 22px; }
.preview-thumb.is-empty .preview-empty { display: flex; }
.preview-thumb:active { transform: scale(.94); }
.preview-thumb.disabled { pointer-events: none; opacity: .5; }

.shutter {
  width: 76px; height: 76px; border-radius: 50%;
  border: none; cursor: pointer; position: relative;
  background: radial-gradient(circle at 50% 32%, #efd9a4 0%, var(--brass) 48%, #8a6a2f 100%);
  box-shadow: 0 6px 22px rgba(200,164,92,.4), inset 0 2px 4px rgba(255,255,255,.5), inset 0 -4px 8px rgba(0,0,0,.35);
}
.shutter span {
  position: absolute; inset: 12px; border-radius: 50%;
  border: 2px solid rgba(80,60,25,.8);
  background: radial-gradient(circle at 50% 34%, #6b5a3a 0%, #3a2f1d 70%);
  box-shadow: inset 0 3px 6px rgba(0,0,0,.6);
}
.shutter:active { transform: scale(.92); }
.shutter.disabled { pointer-events: none; opacity: .6; }

.cancel-btn {
  margin-top: 14px; padding: 8px 18px; border-radius: 16px;
  border: 1px solid #6e3a34; background: rgba(60,26,22,.5);
  color: #d98a82; font-family: var(--serif); font-size: 13px; letter-spacing: .1em;
  cursor: pointer;
}

/* ---------------- 自动/手动模式切换（与滑轨同行右端） ---------------- */
.mode-btn {
  flex: none;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 18px;
  border: 1px solid var(--line-hi);
  background: var(--panel-2);
  color: var(--muted);
  font-family: var(--serif);
  font-size: 13px; letter-spacing: .18em;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,.35);
}
.mode-btn::before {
  content: "";
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.mode-btn.on {
  border-color: var(--brass);
  color: var(--brass-hi);
  box-shadow: 0 0 12px rgba(200,164,92,.25), 0 3px 10px rgba(0,0,0,.35);
}
.mode-btn.on::before {
  background: var(--brass);
  box-shadow: 0 0 6px rgba(200,164,92,.7);
}
.mode-btn:active { transform: scale(.95); }
.mode-btn.disabled { opacity: .4; pointer-events: none; }

/* ---------------- modals ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8,6,4,.72);
  backdrop-filter: blur(6px);
  animation: fade .25s ease;
}
.modal-panel {
  width: min(92vw, 480px);
  max-height: 84dvh;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--panel) 0%, #16110d 100%);
  border: 1px solid var(--line-hi);
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0,0,0,.6);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  flex-shrink: 0;   /* 头部不被压缩，网格独立滚动 */
}
.modal-head h2 { font-size: 16px; letter-spacing: .22em; color: var(--brass-hi); font-weight: 600; }

.hist-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 14px; overflow-y: auto; min-height: 0;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.hist-item {
  position: relative;
  /* 用 padding-top:100% 撑出正方形，比 aspect-ratio 跨浏览器更稳，
     避免某些浏览器下行高塌陷导致缩略图被压扁、上下行重叠只露顶部 */
  padding-top: 100%;
  border-radius: 6px; overflow: hidden;
  border: 3px solid var(--line); background: #0b0907;
  cursor: pointer;
  -webkit-touch-callout: none;   /* 拦截 iOS 长按图片菜单 */
  -webkit-user-select: none; user-select: none;
  touch-action: pan-y;
}
.hist-item .hist-thumb {
  position: absolute; inset: 0;
  background-size: cover; background-position: center; background-color: #0b0907;
  pointer-events: none;
}
.hist-item:active { transform: scale(.95); border-color: var(--brass); }

/* 选择模式：加粗高亮边框 + 外发光；未选图片不再半透明（保持原亮度） */
.hist-item.sel {
  border-color: var(--brass-hi);
  box-shadow: 0 0 0 3px rgba(200,164,92,.45), 0 0 16px rgba(200,164,92,.55);
  z-index: 1;
}

/* 选择模式下：未选图片左上角显示空勾选圈，提示可点选 */
.hist-grid.selecting .hist-item:not(.sel)::before {
  content: "";
  position: absolute; top: 6px; left: 6px;
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid rgba(239,230,216,.6);
  background: rgba(18,16,13,.4);
  z-index: 2;
}

/* 选中图片左上角：实心黄铜勾选框 */
.hist-item.sel::after {
  content: "\2713";
  position: absolute; top: 6px; left: 6px;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--brass);
  color: #16110d;
  font-size: 14px; font-weight: 800; line-height: 1;
  border: 2px solid #16110d;
  box-shadow: 0 1px 4px rgba(0,0,0,.6);
  z-index: 3;
}
.hist-tools { display: flex; gap: 8px; align-items: center; }
.hist-tools .ghost-btn { min-width: 0; padding: 6px 10px; }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); font-size: 14px; padding: 40px 0; letter-spacing: .1em; }

.detail-panel { align-items: center; padding: 0 0 16px; }
.detail-head { display: flex; justify-content: flex-end; padding: 12px 14px 4px; }
.detail-album-btn { color: var(--brass-hi); border-color: var(--brass); }
.detail-panel img {
  width: 100%; max-height: 56dvh; object-fit: contain;
  background: #050403;
  -webkit-touch-callout: none;   /* 拦截 iOS/Android 长按图片弹出的原生「保存/分享」菜单 */
  -webkit-user-select: none; user-select: none;
}
.detail-meta {
  margin-top: 10px; display: flex; gap: 12px; justify-content: center;
  font-size: 12px; color: var(--muted); letter-spacing: .12em;
}
.detail-actions {
  display: flex; gap: 6px; width: 100%; justify-content: center;
  padding: 12px 10px 0;
}
.detail-actions button { flex: 1; min-width: 0; max-width: 90px; font-size: 13px; padding: 8px 6px; }
#btn-detail-delete.danger { border-color: var(--danger); color: #fff; background: rgba(198,85,77,.25); }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  z-index: 90;
  max-width: 86vw;
  background: rgba(20,16,12,.94);
  border: 1px solid var(--brass-dim);
  color: var(--cream);
  font-size: 13px; letter-spacing: .06em;
  padding: 10px 18px; border-radius: 20px;
  text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
  box-shadow: 0 8px 26px rgba(0,0,0,.5);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-height: 640px) {
  .plate { width: 50px; height: 50px; }
  .controls { margin-top: 12px; }
  .shutter { width: 66px; height: 66px; }
}

/* ---------------- 换版间隔滑轨 ---------------- */
.interval-row {
  margin-top: 14px;
  width: min(100%, 420px);  /* 缩短，给自动/手动按钮让出空间 */
}
.interval-head { margin-bottom: 6px; }
.interval-label {
  font-size: 12px; color: var(--muted); letter-spacing: .22em;
}
.interval-body {
  display: flex;
  align-items: center; /* 滑轨与按钮垂直居中对齐 */
  gap: 12px;
}

.slider-track {
  flex: 1; min-width: 0;
  position: relative;
  height: 52px;
  padding: 0 26px;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.slider-track:focus-visible .slider-thumb {
  box-shadow: 0 3px 14px rgba(200,164,92,.65),
              inset 0 1px 2px rgba(255,255,255,.55),
              inset 0 -2px 4px rgba(0,0,0,.25),
              0 0 0 4px rgba(200,164,92,.22);
}
.slider-rail,
.slider-fill {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  height: 6px; border-radius: 3px;
}
.slider-rail {
  left: 26px; right: 26px;
  background: #33281d;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.6);
}
.slider-fill {
  left: 26px; width: 26px;
  background: linear-gradient(90deg, #8a6a2f, var(--brass));
  box-shadow: 0 0 8px rgba(200,164,92,.35);
}
.slider-thumb {
  position: absolute;
  top: 50%; left: 26px;
  transform: translate(-50%, -50%);
  min-width: 58px; height: 42px; padding: 0 12px;
  border-radius: 21px;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #efd9a4 0%, var(--brass) 55%, #8a6a2f 100%);
  box-shadow: 0 3px 12px rgba(200,164,92,.5),
              inset 0 1px 2px rgba(255,255,255,.55),
              inset 0 -2px 4px rgba(0,0,0,.25);
  transition: left .08s linear, box-shadow .15s ease;
  pointer-events: none; /* 由 track 处理 pointer */
}
.slider-thumb span {
  font-size: 13px; font-weight: 700; color: #241b0e;
  letter-spacing: .02em; white-space: nowrap;
  font-feature-settings: "tnum"; /* 表格数字，等宽对齐秒数宽度 */
}

/* ---------------- footer ---------------- */
.footer {
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .14em;
}
.footer a {
  color: var(--brass-hi);
  text-decoration: none;
  border-bottom: 1px solid var(--brass-dim);
  transition: color .2s ease;
}
.footer a:active { color: #fff; }
