:root {
  --camera-bg: #141212;
  --camera-panel: #242120;
  --camera-text: #f4f1ee;
  --camera-muted: #a8a19d;
  --camera-accent: #e0786c;
  --camera-action: #c8443a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--camera-bg);
  color: var(--camera-text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}
a { color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
a:focus-visible, button:focus-visible { outline: 3px solid var(--camera-accent); outline-offset: 3px; }

.camera-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(12px + env(safe-area-inset-bottom));
}
.camera-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 52px; }
.camera-back { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; justify-self: start; color: var(--camera-muted); font-size: 15px; }
.camera-bar h1 { margin: 0; font-size: 16px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.camera-stage { position: relative; display: flex; flex: 1; min-height: 0; align-items: center; justify-content: center; }
#camera-canvas { display: block; max-width: 100%; max-height: 100%; aspect-ratio: 3 / 4; border-radius: 4px; background: var(--camera-panel); }
#camera-canvas.draggable { touch-action: none; cursor: grab; }
.camera-status {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(80%, 320px);
  margin: 0;
  padding: 12px 16px;
  border-radius: 8px;
  background: rgba(20, 18, 18, .82);
  font-size: 14px;
  text-align: center;
  transform: translate(-50%, -50%);
}
.camera-hint { margin: 8px 0 0; color: var(--camera-muted); font-size: 12px; text-align: center; }
.album-diagnostic { flex-shrink: 0; margin-top: 8px; font-size: 12px; }
.album-diagnostic textarea { display: block; width: 100%; box-sizing: border-box; margin-top: 4px; color: var(--camera-text); background: var(--camera-panel); }
.album-diagnostic p { margin: 4px 0; color: var(--camera-muted); }

.camera-options { display: grid; gap: 6px; margin-top: 8px; }
.option-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.option-label { flex-shrink: 0; color: var(--camera-muted); font-size: 12px; }
.option-list { display: flex; gap: 8px; min-width: 0; padding: 2px; overflow-x: auto; scrollbar-width: none; }
.option-list::-webkit-scrollbar { display: none; }
.frame-option { flex-shrink: 0; width: 33px; height: 44px; padding: 0; border: 2px solid transparent; border-radius: 5px; background: var(--camera-panel); overflow: hidden; cursor: pointer; }
.frame-option img { display: block; width: 100%; height: 100%; object-fit: cover; }
.frame-option img:not([src]) { visibility: hidden; }
.frame-option[aria-pressed="true"] { border-color: var(--camera-text); }
.filter-option { flex-shrink: 0; min-height: 36px; padding: 0 14px; border: 1px solid #4a4542; border-radius: 18px; background: transparent; font-size: 13px; cursor: pointer; }
.filter-option[aria-pressed="true"] { border-color: var(--camera-text); background: var(--camera-text); color: var(--camera-bg); font-weight: 600; }
.frame-option:disabled, .filter-option:disabled { opacity: .4; cursor: default; }

.camera-controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 12px 8px 4px; }
.camera-tool { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; min-width: 56px; min-height: 56px; justify-content: center; border: 0; background: transparent; font-size: 12px; cursor: pointer; }
.camera-tool:first-child { justify-self: start; }
.camera-tool:not(:first-child) { justify-self: end; grid-column: 3; }
.camera-tool:disabled { opacity: .4; cursor: default; }
.camera-shutter {
  grid-column: 2;
  width: 72px;
  height: 72px;
  border: 4px solid var(--camera-text);
  border-radius: 50%;
  background: var(--camera-text);
  box-shadow: inset 0 0 0 4px var(--camera-bg);
  cursor: pointer;
  transition: transform .12s;
}
.camera-shutter:active { transform: scale(.94); }
.camera-shutter.confirm { width: auto; min-width: 112px; height: 52px; padding: 0 28px; border: 0; border-radius: 26px; background: var(--camera-action); box-shadow: 0 6px 20px rgba(200, 68, 58, .35); color: #fff; font-size: 16px; font-weight: 600; }
.camera-shutter:disabled { opacity: .4; cursor: default; }

.camera-source { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.camera-result { position: fixed; width: min(80vw, 340px); max-width: none; max-height: none; margin: auto; padding: 0; border: 0; background: transparent; overflow: visible; }
.camera-result::backdrop { background: rgba(10, 8, 8, .62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
/* 拍立得相纸：小圆角，三边窄、底边宽留白，纸面略带渐变；「重拍」和「存进相册」写在底边留白里，整张一起倾斜。 */
.result-card {
  position: relative;
  padding: 14px 14px 12px;
  border-radius: 3px;
  background: linear-gradient(170deg, #fdfcf8, #f1ede4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7), 0 2px 6px rgba(0, 0, 0, .3), 0 22px 60px rgba(0, 0, 0, .55);
  transform: rotate(var(--tilt, -4deg));
}
.result-card:focus { outline: none; }
#result-image { display: block; width: 100%; max-height: calc(100dvh - 280px); aspect-ratio: 3 / 4; object-fit: contain; border-radius: 1px; background: var(--camera-bg); -webkit-touch-callout: default; }
.result-footer { margin-top: 12px; }
.result-buttons { display: flex; align-items: center; gap: 8px; }
/* 次要操作：墨色文字加回转图标，不做成色块。 */
.result-retake { display: inline-flex; flex-shrink: 0; align-items: center; gap: 4px; min-height: 44px; padding: 0 8px 0 4px; border: 0; background: transparent; color: #3b3331; cursor: pointer; font-size: 15px; font-weight: 700; }
.result-retake span { border-bottom: 2px solid rgba(59, 51, 49, .35); }
.result-retake:active { transform: scale(.94); }
/* 主操作：取自海报的芥末黄干刷笔触，粗黑字，微微反向倾斜；按下时缩一下、颜色变深。 */
.result-save {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 50px;
  border: 0;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 64' preserveAspectRatio='none'><path fill='%23e9b824' d='M9 12C52 5 118 9 166 6C214 3 262 5 292 10L297 19L290 25L298 33L293 41L299 50C262 58 205 55 154 58C96 61 48 60 11 55L4 47L10 40L2 31L8 23L3 16Z'/><path fill='none' stroke='%23f6da74' stroke-width='2.5' stroke-linecap='round' opacity='.75' d='M24 17C90 13 170 14 268 13M30 46C110 48 190 45 276 46'/><path fill='none' stroke='%23c38f0c' stroke-width='1.6' stroke-linecap='round' opacity='.55' d='M38 30C120 27 200 31 282 28M60 38C140 36 210 39 262 37'/></svg>") center / 100% 100% no-repeat;
  color: #141212;
  cursor: pointer;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .06em;
  transform: rotate(-1.5deg);
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .28));
  transition: transform .08s, filter .08s;
}
.result-save:active { transform: rotate(-1.5deg) scale(.95); filter: brightness(.88); }
.result-retake:focus-visible, .result-save:focus-visible { outline: 3px solid #20151a; outline-offset: 2px; }
.result-hint { margin: 6px 0 0; color: #8a817c; font-size: 12px; text-align: center; }
/* 拍照和相册确认都是相纸带角度弹出；实时拍摄另有快门黑一下。 */
.camera-result[open] .result-card { animation: card-pop .55s cubic-bezier(.3, 1.45, .55, 1); }
@keyframes card-pop { from { opacity: 0; transform: scale(.88) rotate(calc(var(--tilt, -4deg) * 2.5)); } to { opacity: 1; transform: scale(1) rotate(var(--tilt, -4deg)); } }
/* 快门：取景画面短暂全黑，随后定格。 */
.shutter-curtain { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; }
.shutter-curtain.closing { animation: shutter-blink .22s ease-in-out; }
@keyframes shutter-blink { 0% { opacity: 0; } 35% { opacity: 1; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .camera-result[open] .result-card { animation: fade-in .15s ease-out; }
  .shutter-curtain.closing { animation: none; }
}
@keyframes fade-in { from { opacity: 0; } }

.tuning-panel { position: fixed; right: 8px; top: 60px; z-index: 2; display: grid; gap: 4px; width: 240px; max-height: calc(100vh - 80px); overflow-y: auto; padding: 8px; border-radius: 6px; background: rgba(0, 0, 0, .75); font-size: 11px; }
.tuning-panel label { display: grid; grid-template-columns: 1fr auto; }
.tuning-panel input { grid-column: 1 / -1; }
.tuning-panel output { word-break: break-all; color: var(--camera-muted); }
