/* 光谱暗房 SpektraLab — 暗色胶片实验室风格 */
:root {
  --bg: #100e0b;
  --bg-raise: #1a1713;
  --bg-chip: #241f1a;
  --ink: #f2ece1;
  --ink-dim: #9c948a;
  --amber: #e8a852;
  --amber-soft: rgba(232, 168, 82, 0.16);
  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: var(--amber); }

/* ---------- 首页 ---------- */
#screen-home {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--sat) + 24px) 24px calc(var(--sab) + 24px);
}
.home-inner { text-align: center; max-width: 420px; width: 100%; }
.logo-mark {
  width: 84px; height: 84px; margin: 0 auto 26px;
  border-radius: 22px;
  background: var(--bg-raise);
  border: 1px solid #2c261f;
  position: relative;
  overflow: hidden;
}
.logo-mark::before, .logo-mark::after {
  content: ""; position: absolute; left: 10px; right: 10px; height: 5px;
  border-radius: 3px;
  background-image: radial-gradient(circle, #4d443a 2.2px, transparent 2.6px);
  background-size: 13px 5px;
}
.logo-mark::before { top: 9px; }
.logo-mark::after { bottom: 9px; }
.logo-mark .strip {
  position: absolute; left: 12px; right: 12px; top: 50%; height: 22px;
  transform: translateY(-50%);
  border-radius: 5px;
  background: linear-gradient(90deg,
    #b3402f, #d98a3d, #d9c04a, #7da65a, #4a94b8, #7a5aa8, #b3402f);
  box-shadow: 0 0 26px rgba(217, 138, 61, 0.35);
}
h1 { font-size: 34px; letter-spacing: 6px; font-weight: 600; }
.tagline { color: var(--amber); margin-top: 10px; font-size: 14px; letter-spacing: 1px; }
.sub { color: var(--ink-dim); margin: 18px 0 34px; font-size: 13.5px; line-height: 1.8; }
.home-actions { display: flex; gap: 14px; justify-content: center; }
.btn {
  padding: 14px 30px; border-radius: 999px; font-size: 16px; font-weight: 600;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--amber); color: #241a0e; }
.btn.ghost { border: 1px solid #3a332a; color: var(--ink); }
.btn.small { padding: 9px 16px; font-size: 13px; }
.btn:disabled { opacity: 0.5; }
.demo-link {
  display: inline-block; margin-top: 18px;
  font-size: 13px; color: var(--ink-dim);
  text-decoration: underline; text-underline-offset: 3px;
}
.demo-link:active { color: var(--amber); }
.credit { margin-top: 36px; font-size: 11px; color: #6d655c; line-height: 1.7; }

/* ---------- 编辑页 ---------- */
#screen-edit {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.bar {
  background: linear-gradient(to bottom, rgba(16, 14, 11, 0.96), rgba(16, 14, 11, 0.88));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  flex-shrink: 0;
}
.bar.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 8px) 14px 8px;
  border-bottom: 1px solid #221d17;
  z-index: 5;
}
.title-wrap { text-align: center; min-width: 0; flex: 1; padding: 0 8px; }
#film-title {
  font-size: 16px; font-weight: 600; letter-spacing: 0.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#film-desc {
  font-size: 11.5px; color: var(--ink-dim); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 20px; line-height: 1; color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.icon-btn:active { background: var(--bg-chip); }
.icon-btn.big { font-size: 17px; border: 1px solid #3a332a; }

#canvas-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  min-height: 0;
  position: relative;
  background:
    radial-gradient(120% 90% at 50% 0%, #17140f 0%, var(--bg) 70%);
  touch-action: none;
}
#view {
  display: block;
  border-radius: 4px;
  box-shadow: 0 8px 44px rgba(0, 0, 0, 0.55);
  touch-action: none;
}
.compare-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  font-size: 11px; color: var(--ink-dim);
  background: rgba(16, 14, 11, 0.72);
  padding: 5px 12px; border-radius: 999px;
  pointer-events: none;
  opacity: 0; transition: opacity 0.4s ease;
}
#canvas-wrap:active .compare-hint { opacity: 1; }

/* ---------- 调参抽屉 ---------- */
#adjust-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  transform: translateY(calc(100% + 2px));
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0.22, 1);
  background: rgba(26, 23, 19, 0.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 18px 18px 0 0;
  border-top: 1px solid #2c261f;
  padding: 18px 18px calc(var(--sab) + 150px);
  z-index: 8;
}
#adjust-panel.open { transform: translateY(0); }
.adj-row {
  display: grid; grid-template-columns: 44px 1fr 64px;
  align-items: center; gap: 12px; margin-bottom: 16px;
}
.adj-row label { font-size: 13px; color: var(--ink-dim); }
.adj-row output { font-size: 12px; color: var(--amber); text-align: right; font-variant-numeric: tabular-nums; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 30px; background: transparent; width: 100%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: #3a332a;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px; height: 24px; margin-top: -10px;
  border-radius: 50%; background: var(--ink);
  border: 5px solid var(--amber);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}
.adj-actions { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }

/* ---------- 底栏 ---------- */
.bar.bottom {
  border-top: 1px solid #221d17;
  padding: 8px 0 calc(var(--sab) + 6px);
  z-index: 10;
}
.bar-actions {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px 8px;
}
.bar-actions #btn-save { padding: 10px 34px; font-size: 15px; }
#btn-adjust.active { background: var(--amber-soft); border-color: var(--amber); }

#chips {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 0 14px 8px; scrollbar-width: none;
}
#chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 6px 14px; border-radius: 999px;
  font-size: 12.5px; color: var(--ink-dim);
  background: var(--bg-chip);
  border: 1px solid transparent;
}
.chip.active { color: #241a0e; background: var(--amber); font-weight: 600; }

#tray {
  display: flex; gap: 10px;
  overflow-x: auto;
  padding: 2px 14px 4px;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
#tray::-webkit-scrollbar { display: none; }
.film-card {
  flex: 0 0 auto; min-width: 82px;
  scroll-snap-align: start;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 4px 2px;
  border-radius: 12px;
}
.film-card .thumb {
  width: 78px; height: 78px;
  border-radius: 12px; overflow: hidden;
  border: 2px solid #322b23;
  position: relative;
  background: var(--bg-chip);
}
.film-card.active .thumb {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}
.film-card .thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity 0.3s ease;
}
.film-card .thumb img[src]:not([src=""]) { opacity: 1; }
.film-card .swatch {
  position: absolute; inset: 0;
}
.film-card .thumb img[src] { z-index: 1; position: relative; }
.film-label {
  font-size: 10.5px; color: var(--ink-dim);
  max-width: 108px; min-width: 58px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: center;
}
.film-card.active .film-label { color: var(--amber); font-weight: 600; }

/* ---------- 保存浮层 ---------- */
#save-overlay {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(8, 7, 5, 0.96);
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
#save-overlay.show { opacity: 1; pointer-events: auto; }
.save-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 12px) 16px 8px;
  color: var(--ink-dim); font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.save-head .icon-btn { color: var(--ink); }
.save-body {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 8px 14px;
  touch-action: none;
}
#save-img {
  max-width: 100%; max-height: 100%;
  border-radius: 6px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: default; /* 长按出系统菜单，才能「存储到照片」 */
}
.save-foot {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 14px 16px calc(var(--sab) + 18px);
}
.save-foot p { font-size: 12.5px; color: var(--ink-dim); text-align: center; }

/* ---------- 关于 ---------- */
#about-modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 7, 5, 0.72);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
}
#about-modal.show { opacity: 1; pointer-events: auto; }
.modal-card {
  position: relative;
  width: 100%; max-width: 560px;
  max-height: 82vh; overflow-y: auto;
  background: var(--bg-raise);
  border-radius: 20px 20px 0 0;
  padding: 26px 24px calc(var(--sab) + 30px);
  transform: translateY(30px);
  transition: transform 0.25s ease;
  font-size: 14px; line-height: 1.85; color: var(--ink-dim);
}
#about-modal.show .modal-card { transform: translateY(0); }
.modal-card h2 { color: var(--ink); font-size: 20px; margin-bottom: 12px; letter-spacing: 1px; }
.modal-card h3 { color: var(--amber); font-size: 14px; margin: 18px 0 6px; }
.modal-card #about-close { position: absolute; top: 14px; right: 14px; color: var(--ink-dim); }
.modal-card .ver { margin-top: 20px; font-size: 11px; color: #6d655c; }
.modal-card b { color: var(--ink); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--sab) + 132px);
  transform: translateX(-50%) translateY(8px);
  background: #f2ece1; color: #241f1a;
  font-size: 13px; font-weight: 600;
  padding: 10px 20px; border-radius: 999px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
  max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 桌面端 */
@media (min-width: 720px) {
  #adjust-panel { left: 50%; right: auto; width: 520px; margin-left: -260px; border-radius: 18px; bottom: 118px; border: 1px solid #2c261f; transform: translateY(24px); opacity: 0; pointer-events: none; }
  #adjust-panel.open { transform: translateY(0); opacity: 1; pointer-events: auto; }
}
