:root {
  --bg: #f3f4f6; --card: #ffffff; --text: #1b2129; --muted: #5f6b78; --line: #d9dee5;
  --accent: #b3261e; --accent-text: #ffffff; --stage: #1a1d21;
  --ok: #1e7d3a; --warn: #9a5b00; --bad: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101317; --card: #1a1f25; --text: #e8ebef; --muted: #9aa5b1; --line: #2c333c;
    --accent: #e5534b; --accent-text: #ffffff; --stage: #000000;
    --ok: #5cc27a; --warn: #e0a23a; --bad: #f2786e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101317; --card: #1a1f25; --text: #e8ebef; --muted: #9aa5b1; --line: #2c333c;
  --accent: #e5534b; --accent-text: #ffffff; --stage: #000000;
  --ok: #5cc27a; --warn: #e0a23a; --bad: #f2786e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  display: flex; flex-direction: column; min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 1.15rem; margin: 0; letter-spacing: .05em; }
.chip { font-size: .8rem; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.ok { color: var(--ok); border-color: currentColor; }
.chip.warn { color: var(--warn); border-color: currentColor; }
.chip.bad { color: var(--bad); border-color: currentColor; }

.layout { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.stage { position: relative; flex: 1; min-height: 55vh; background: var(--stage); overflow: hidden; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: #c9d0d8; padding: 24px; pointer-events: none; }
.empty p { margin: 4px 0; }
.empty .big { font-size: 1.25rem; color: #fff; }
.hint { position: absolute; left: 0; right: 0; top: 8px; margin: 0; text-align: center; font-size: .8rem; color: #fff; text-shadow: 0 1px 3px #000; pointer-events: none; }
/* 按住看原圖：照片右下角。不能被長按選字、叫出選單，也不能捲動頁面 */
.peek {
  position: absolute; right: 12px; bottom: 12px; min-height: 44px; padding: 0 16px; border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, .4); background: rgba(0, 0, 0, .55); color: #fff;
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.peek.on { background: var(--accent); border-color: var(--accent); }
.busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .35); }
.busy-box { background: var(--card); color: var(--text); border-radius: 14px; padding: 14px 16px; width: min(320px, calc(100% - 32px)); display: grid; gap: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .3); }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
#busyBar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.panel { background: var(--card); border-top: 1px solid var(--line); padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); display: grid; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.actions .btn { flex: 1; }
.controls { border: 0; margin: 0; padding: 0; display: grid; gap: 10px; min-width: 0; }
.controls:disabled { opacity: .45; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; user-select: none; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.small { min-height: 38px; padding: 0 14px; }
.btn.ghost { background: transparent; }
.btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
input[type=file] { display: none; }

.update { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--warn); color: var(--warn); font-size: .9rem; }
.update .btn { white-space: nowrap; flex: none; }
.status { font-size: .9rem; color: var(--muted); min-height: 1.5em; }
.status.ok { color: var(--ok); } .status.warn { color: var(--warn); } .status.bad { color: var(--bad); }

.toggle { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); }
.toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.slider input { flex: 1; min-width: 120px; accent-color: var(--accent); }
.period input { width: 9em; font: inherit; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }

.info summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.info dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 8px 0; font-size: .85rem; font-variant-numeric: tabular-nums; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }
.note { font-size: .8rem; color: var(--muted); margin: 4px 0 0; }

.btn.wide { width: 100%; }

.sheet {
  border: 0; border-radius: 16px; padding: 16px; width: min(420px, calc(100% - 32px));
  background: var(--card); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
}
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet h2 { font-size: 1.1rem; margin: 0 0 4px; }
.sheet-list { display: grid; gap: 8px; margin: 8px 0; }
.sheet-list .btn { flex-direction: column; align-items: flex-start; padding: 8px 14px; text-align: left; }
.sheet-list .btn small { font-weight: 400; font-size: .8rem; opacity: .8; }
.sheet-list .btn:disabled { opacity: .45; cursor: default; }

/* 寬螢幕（電腦、iPad 橫放）：照片在左、操作在右 */
@media (min-width: 900px) {
  .layout { flex-direction: row; }
  .stage { min-height: 0; }
  .panel { width: 360px; border-top: 0; border-left: 1px solid var(--line); align-content: start; overflow-y: auto; }
}
