:root {
  --bg: #0d2350;
  --surface: #17377a;
  --line: #2c4f96;
  --text: #ffffff;
  --muted: #b4c3e6;
  --brand: #ffc928;
  --brand-ink: #13306b;
  --accent: #f0642d;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- 按鈕 ---------- */

.btn {
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  font-weight: 700;
  font-size: 17px;
}
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border: 2px solid var(--line); }
.btn-big { font-size: 22px; padding: 18px 48px; }

/* ---------- 開始畫面 ---------- */

#screen-start {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 201, 40, .18), transparent 55%),
    var(--bg);
}
.start-inner {
  width: 100%;
  max-width: 480px;
  padding: 24px 16px;
  text-align: center;
}
.badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 900;
  letter-spacing: .1em;
}
h1 {
  margin: 18px 0 8px;
  font-size: clamp(44px, 13vw, 72px);
  font-weight: 900;
  line-height: 1.1;
  color: var(--text);
  letter-spacing: .06em;
  font-style: italic;
  transform: skewX(-6deg);
}
h1 span { display: block; margin-top: 6px; color: var(--brand); font-size: .42em; letter-spacing: .12em; }
.lead { color: var(--muted); margin: 0 0 32px; }
.note { color: var(--muted); font-size: 13px; margin-top: 28px; }

/* ---------- 拍照畫面 ---------- */

.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
}
.seg {
  display: inline-flex;
  background: var(--surface);
  border-radius: 999px;
  padding: 4px;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 700;
}
.seg button.active { background: var(--brand); color: var(--brand-ink); }
.chip-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
}

.preview-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#preview {
  display: block;
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  touch-action: none;
}
[data-source="image"] #preview { cursor: grab; }
/* 相機畫面只當作畫布的來源，不直接顯示（不用 display:none，iOS 會停止更新畫面） */
#video {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(40vw, 40vh);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 6px 30px rgba(0, 0, 0, .6);
  pointer-events: none;
}
.countdown.pop { animation: pop 1s ease-out; }
@keyframes pop {
  0% { transform: scale(1.6); opacity: 0; }
  20% { transform: scale(1); opacity: 1; }
  100% { transform: scale(.9); opacity: .2; }
}
.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.flash.on { animation: flash .45s ease-out; }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }

.stage-status {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(8, 20, 43, .9);
  border: 1px solid var(--line);
  text-align: center;
}

.adjust {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 6px 16px 0;
  color: var(--muted);
  font-size: 13px;
}
.adjust input { flex: 1; accent-color: var(--brand); }
[data-source="image"] .adjust { display: flex; }

.strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px 16px;
  scrollbar-width: none;
}
.strip::-webkit-scrollbar { display: none; }
.tpl {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 0;
  background: none;
  padding: 0;
  font-size: 12px;
  color: var(--muted);
}
.tpl img {
  display: block;
  height: 72px;
  width: auto;
  border-radius: 6px;
  background: #c9ced6;
  outline: 3px solid transparent;
  outline-offset: 1px;
}
[data-orient="landscape"] .tpl img { height: 56px; }
.tpl.active { color: var(--text); font-weight: 700; }
.tpl.active img { outline-color: var(--brand); }

.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 6px 16px 18px;
}
.side-btn {
  justify-self: center;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
}
#back-to-cam { visibility: hidden; }
[data-source="image"] #back-to-cam { visibility: visible; }

.shutter {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 5px solid #fff;
  background: transparent;
  padding: 5px;
}
.shutter span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 900;
  transition: transform .1s;
}
.shutter:active span { transform: scale(.9); }
[data-source="image"] .shutter span::before { content: "完成"; }
.busy .controls, .busy .strip, .busy .stage-bar { pointer-events: none; opacity: .5; }

/* ---------- 成品畫面 ---------- */

.result-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.result-wrap img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.print-done {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 0 16px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}
.print-done strong { font-size: 40px; font-weight: 900; color: var(--brand); line-height: 1.1; }
.print-done small { color: var(--muted); font-size: 12px; text-align: center; }
.result-status { margin: 0 16px; color: var(--accent); text-align: center; }
.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px 16px 18px;
  width: 100%;
  max-width: 560px;
  align-self: center;
}
.result-actions .btn-ghost,
#print-btn,
#save-btn:has(+ #share-btn[hidden]) { grid-column: 1 / -1; }
.btn-share { background: var(--surface); border: 2px solid var(--line); }
.save-hint {
  margin: 0 16px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--brand);
  color: var(--brand-ink);
  text-align: center;
  font-weight: 700;
}
.result-wrap img { -webkit-touch-callout: default; }

/* 現場筆電模式：不提供下載，只送印 */
.kiosk #save-btn, .kiosk #share-btn { display: none !important; }
