/* logi.tim945.com｜G 拍照合成
   版面依照示意圖：深藍標題列 + 置中 Logo、白底、圓形按鈕、上拉式產品選單。 */

:root {
  --brand: #156082;
  --brand-dark: #0f4c69;
  --cyan: #00b8fc;
  --cyan-soft: #e3f6fe;
  --ink: #12171c;
  --ink-2: #3c4852;
  --muted: #6c7a86;
  --line: #dbe2e8;
  --stage-bg: #eef2f5;
  --danger: #d23b3b;
  --topbar-h: 52px;
  --tools-h: 48px;
  --peek-h: 56px;
  --pill-h: 42px;
  --actions-h: 98px;
  --sheet-open-h: min(60vh, 560px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(.22, .8, .24, 1);
  --font: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  color-scheme: light;
}
@supports (height: 100dvh) { :root { --sheet-open-h: min(60dvh, 560px); } }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation; /* 雙擊空白處不會放大頁面；兩指縮放仍可用 */
}
@supports (height: 100dvh) { body { height: 100dvh; } }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.icon-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 1.25em; height: 1.25em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- 標題列 ---------- */
.topbar {
  flex: none;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--brand);
  border-bottom: 1px solid var(--brand-dark);
  overflow: hidden;
  transition: height .3s var(--ease), padding .3s var(--ease), border-color .3s;
}
.brand { display: block; line-height: 0; border-radius: 4px; }
.brand img { height: 30px; width: auto; }
.topbar-end { justify-self: end; padding-right: max(12px, env(safe-area-inset-right, 0px)); }
.topbar-button {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .65); background: transparent; color: #fff;
  font-weight: 700; font-size: 15px; line-height: 1; display: grid; place-items: center;
}
@media (hover: hover) { .topbar-button:hover { border-color: #fff; background: rgba(255, 255, 255, .1); } }

.app { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }

/* ---------- 圓形按鈕（示意圖的相機 / 相簿 / 返回 / 儲存 / 分享） ---------- */
.round-button {
  --size: 62px;
  display: inline-flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 0; border: 0; background: none; color: var(--ink);
  font-size: 13px; font-weight: 600; letter-spacing: .04em;
}
.round-button > .icon {
  width: var(--size); height: var(--size);
  padding: calc(var(--size) * .25);
  border: 3px solid currentColor; border-radius: 50%;
  background: #fff;
  stroke-width: 1.9;
  transition: transform .12s, background-color .15s, border-color .15s, box-shadow .2s;
}
@media (hover: hover) { .round-button:hover:not(:disabled) > .icon { background: var(--cyan-soft); } }
.round-button:active:not(:disabled) > .icon { transform: scale(.93); }
.round-button:disabled { opacity: .32; }
.round-button:focus-visible { outline: none; }
.round-button:focus-visible > .icon { outline: 3px solid var(--cyan); outline-offset: 3px; }
.round-button.shutter { --size: 84px; }
.round-button.shutter > .icon { border-width: 4px; padding: calc(var(--size) * .24); }
body[data-camera="live"] .round-button.shutter > .icon { box-shadow: 0 0 0 6px rgba(0, 184, 252, .22); }

.pill-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: 999px;
  border: 2px solid var(--brand); background: var(--brand); color: #fff;
  font-size: 15px; font-weight: 600;
}
@media (hover: hover) { .pill-button:hover:not(:disabled) { background: var(--brand-dark); border-color: var(--brand-dark); } }
.pill-button.ghost { background: #fff; color: var(--brand); }
@media (hover: hover) { .pill-button.ghost:hover:not(:disabled) { background: var(--cyan-soft); } }
.pill-button:disabled { opacity: .4; }

/* 「← 重拍」「繼續 →」：白底粗黑框膠囊（示意圖 3、4） */
.nav-pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  height: var(--pill-h); padding: 0 16px; border-radius: 999px;
  border: 3px solid var(--ink); background: #fff; color: var(--ink);
  font-size: 17px; font-weight: 800; letter-spacing: .06em; white-space: nowrap;
  transition: transform .12s, background-color .15s;
}
.nav-pill .icon { width: 22px; height: 22px; stroke-width: 2.8; }
@media (hover: hover) { .nav-pill:hover:not(:disabled) { background: var(--cyan-soft); } }
.nav-pill:active:not(:disabled) { transform: scale(.95); }
.nav-pill:disabled { opacity: .45; }
.nav-pill:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

.square-button {
  width: 44px; height: 44px; border-radius: 8px; border: 0;
  display: grid; place-items: center; background: #fff; color: var(--ink);
}
.square-button > .icon { width: 32px; height: 32px; padding: 5px; border: 2px solid currentColor; border-radius: 50%; stroke-width: 2.2; }
@media (hover: hover) { .square-button:hover > .icon { background: var(--cyan-soft); } }
.square-button.small { width: 36px; height: 36px; background: #f1f4f7; }
.square-button.small > .icon { width: 22px; height: 22px; padding: 0; border: 0; }

.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid rgba(21, 96, 130, .2); border-top-color: var(--cyan);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 1. 拍照畫面 ---------- */
.capture {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 14px;
  padding: 16px 16px calc(8px + var(--safe-bottom));
}
.viewfinder-area { container-type: size; min-height: 0; display: grid; place-items: center; }
.viewfinder {
  --ar: .75;
  position: relative;
  width: 100%; height: 100%;
  overflow: hidden;
  border-radius: 6px;
  background: #0d1418;
  box-shadow: 0 12px 32px rgba(12, 38, 54, .2);
}
@supports (width: 1cqw) {
  .viewfinder { width: min(100cqw, calc(100cqh * var(--ar))); height: min(100cqh, calc(100cqw / var(--ar))); }
}
.viewfinder video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
body[data-camera="live"] .viewfinder video { display: block; }
.viewfinder video.mirrored { transform: scaleX(-1); }
.viewfinder-idle {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 24px; border: 0; color: #fff; text-align: center;
  background:
    radial-gradient(120% 80% at 50% 38%, rgba(21, 96, 130, .55), transparent 70%),
    linear-gradient(#0f1b22, #0a1115);
}
.viewfinder-idle::before, .viewfinder-idle::after {
  content: ""; position: absolute; width: 34px; height: 34px; border: 3px solid rgba(255, 255, 255, .5);
}
.viewfinder-idle::before { top: 18px; left: 18px; border-right: 0; border-bottom: 0; }
.viewfinder-idle::after { right: 18px; bottom: 18px; border-left: 0; border-top: 0; }
.viewfinder-icon { width: 76px; height: 76px; color: var(--cyan); stroke-width: 1.4; margin-bottom: 4px; transition: transform .2s; }
@media (hover: hover) { .viewfinder-idle:hover .viewfinder-icon { transform: scale(1.05); } }
.viewfinder-idle strong { font-size: 19px; letter-spacing: .06em; }
.viewfinder-idle span { font-size: 13.5px; color: #a9bfcc; max-width: 22em; }
body:not([data-camera="idle"]) .viewfinder-idle { display: none; }
.viewfinder-message {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 24px; text-align: center; color: #fff; background: rgba(10, 17, 21, .94);
}
.viewfinder-message p { margin: 0; max-width: 22em; line-height: 1.6; }
.viewfinder-message > .icon { width: 44px; height: 44px; color: #ffb648; }
.viewfinder-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 4px; }
.viewfinder-actions .pill-button.ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .7); }
.viewfinder-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.viewfinder-flash.go { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }

.capture-controls {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; justify-items: center;
  width: 100%; max-width: 440px; margin: 0 auto;
}
.fine-print {
  margin: 0; display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 12px; color: var(--muted); text-align: center;
}
.fine-print .icon { width: 14px; height: 14px; }

/* ---------- 2. 合成畫面 ---------- */
.editor {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "tools" "stage" "sheet" "actions";
}
.edit-tools {
  grid-area: tools;
  height: var(--tools-h);
  display: flex; align-items: center; gap: 4px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  overflow: hidden;
  transition: height .3s var(--ease), border-color .3s;
}
.tool-group { display: flex; align-items: center; gap: 2px; flex: none; }
.tool-button {
  width: 40px; height: 40px; border-radius: 10px; border: 0;
  display: grid; place-items: center; background: transparent; color: var(--ink-2);
}
.tool-button .icon { width: 22px; height: 22px; }
@media (hover: hover) { .tool-button:hover:not(:disabled) { background: #edf3f7; color: var(--ink); } }
.tool-button:disabled { opacity: .28; }
.tool-button.danger { color: var(--danger); }
.edit-hint {
  flex: 1; min-width: 0; margin: 0;
  font-size: 13px; color: var(--muted); text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.edit-hint strong { color: var(--brand); font-weight: 700; }
.selection-tools { margin-left: auto; }

.stage-shell {
  grid-area: stage;
  position: relative; min-height: 0; min-width: 0;
  display: grid; place-items: center;
  padding: 14px;
  background: var(--stage-bg);
  overflow: hidden;
  transition: padding .3s var(--ease);
}
#stageContainer { line-height: 0; box-shadow: 0 8px 26px rgba(12, 38, 54, .2); touch-action: none; outline-offset: 4px; }
#stageContainer:focus { outline: none; }
#stageContainer:focus-visible { outline: 3px solid var(--cyan); }
body.drag-over #stageContainer { outline: 3px dashed var(--cyan); outline-offset: 5px; }
.drop-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px;
  background: var(--cyan); color: #00283a; font-size: 14px; font-weight: 700; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 120, 170, .3); pointer-events: none; z-index: 3;
}
.final-image {
  display: block; max-width: none;
  box-shadow: 0 8px 26px rgba(12, 38, 54, .2);
  -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto;
}
.stage-busy {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(238, 242, 245, .72); color: var(--ink-2); font-size: 14px;
}

/* 上拉式產品選單 */
.sheet {
  grid-area: sheet;
  position: relative; z-index: 5;
  display: flex; flex-direction: column;
  height: calc(var(--peek-h) + var(--safe-bottom));
  background: #fff;
  box-shadow: 0 -6px 22px rgba(12, 38, 54, .14);
  overflow: hidden;
  transition: height .32s var(--ease);
}
/* 收起時：整條藍色列是「選擇羅技產品」把手，左右兩端是重拍／繼續 */
.sheet-peek {
  flex: none; width: 100%;
  height: calc(var(--peek-h) + var(--safe-bottom)); padding: 0 0 var(--safe-bottom);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 0; background: var(--brand); color: #fff;
  font-size: 15px; font-weight: 700; letter-spacing: .08em;
  touch-action: none;
}
.sheet-peek-label { display: flex; align-items: center; gap: 6px; }
.sheet-peek-label .icon { width: 18px; height: 18px; stroke-width: 2.6; }
.grip { display: block; width: 40px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .55); flex: none; }
.sheet-nav { position: absolute; z-index: 2; top: calc((var(--peek-h) - var(--pill-h)) / 2); }
.sheet-nav.retake { left: 8px; }
.sheet-nav.continue { right: 8px; }
.sheet-panel { display: none; flex: 1; min-height: 0; flex-direction: column; }
/* 拉開時：藍色列中間是 Logo（點一下或往下滑可收起），重拍／繼續留在左右兩端 */
.sheet-bar {
  position: relative; flex: none;
  height: var(--peek-h);
  display: flex; align-items: center;
  background: var(--brand);
  touch-action: none;
}
.sheet-bar-toggle { width: 100%; height: 100%; padding: 0; border: 0; background: none; display: grid; place-items: center; }
.sheet-bar .grip { position: absolute; top: 5px; left: 50%; transform: translateX(-50%); }
.sheet-logo { height: 26px; width: auto; }
.sheet-bar-title { display: none; margin: 0; color: #fff; font-size: 16px; font-weight: 700; letter-spacing: .06em; }
.sheet-body { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px 14px 0; }
.search-field {
  flex: none; display: flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 6px 0 12px;
  border: 2px solid var(--line); border-radius: 10px; background: #fff;
}
.search-field:focus-within { border-color: var(--brand); }
.search-field > .icon { color: var(--muted); }
.search-field input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-size: 16px; }
.search-field input::-webkit-search-cancel-button { display: none; }
.search-clear { width: 32px; height: 32px; border: 0; border-radius: 50%; background: #eef2f5; display: grid; place-items: center; color: var(--ink-2); }
.search-clear .icon { width: 16px; height: 16px; }
.sheet-heading { flex: none; display: flex; align-items: center; gap: 8px; min-height: 36px; margin: 8px 2px 0; }
.sheet-heading h3 { flex: 1; margin: 0; font-size: 17px; font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-heading span { flex: none; font-size: 13px; color: var(--muted); }
.level-back {
  flex: none; width: 36px; height: 36px; margin-left: -4px;
  border: 0; border-radius: 50%; background: #eef2f5; color: var(--ink);
  display: grid; place-items: center;
}
.level-back .icon { width: 20px; height: 20px; stroke-width: 2.4; }
@media (hover: hover) { .level-back:hover { background: var(--cyan-soft); } }
.sheet-tip { flex: none; display: flex; align-items: center; gap: 6px; margin: 2px 2px 10px; font-size: 12.5px; color: var(--brand); }
.sheet-tip .icon { width: 16px; height: 16px; }
.sheet-scroll {
  flex: 1; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 2px 2px calc(18px + var(--safe-bottom));
}
.catalog-state { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 36px 16px; text-align: center; color: var(--muted); }
.catalog-state p { margin: 0; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 16px 12px; }
.variant-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; }
.card {
  display: flex; flex-direction: column; gap: 7px; min-width: 0;
  padding: 0; border: 0; background: none; text-align: center;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.card img { pointer-events: none; -webkit-user-drag: none; user-select: none; }
.card-art {
  position: relative; display: block;
  border: 4px solid var(--brand); border-radius: 4px; background: #fff;
  overflow: hidden;
  transition: transform .12s, border-color .15s, box-shadow .2s;
}
@media (hover: hover) { .card:hover .card-art { border-color: #1c7aa6; box-shadow: 0 6px 16px rgba(21, 96, 130, .18); } }
.card:active .card-art { transform: scale(.97); }
.card.pressing .card-art { box-shadow: 0 0 0 4px var(--cyan); transition: box-shadow .26s ease-in; }
.card.lifted .card-art { opacity: .45; }
.card-name { font-size: 15px; font-weight: 700; color: var(--ink); }
.card-meta { font-size: 12px; color: var(--muted); font-weight: 500; }

.category-card .card-art { aspect-ratio: 4 / 3; }
.category-card .card-art img { position: absolute; object-fit: contain; filter: drop-shadow(0 4px 5px rgba(0, 0, 0, .18)); }
.category-card .card-art[data-n="1"] img { left: 10%; top: 10%; width: 80%; height: 80%; }
.category-card .card-art[data-n="2"] img:nth-child(1) { left: 5%; top: 6%; width: 56%; height: 56%; }
.category-card .card-art[data-n="2"] img:nth-child(2) { right: 4%; bottom: 5%; width: 62%; height: 62%; }
.category-card .card-art[data-n="3"] img:nth-child(1) { left: 4%; top: 5%; width: 52%; height: 50%; }
.category-card .card-art[data-n="3"] img:nth-child(2) { right: 4%; top: 10%; width: 46%; height: 46%; }
.category-card .card-art[data-n="3"] img:nth-child(3) { left: 20%; bottom: 4%; width: 60%; height: 52%; }

.product-card { text-align: left; touch-action: pan-y; }
.product-card .card-art, .variant-card .card-art { aspect-ratio: 1; border-width: 3px; display: grid; place-items: center; }
.product-card .card-art img, .variant-card .card-art img {
  width: 84%; height: 84%; object-fit: contain; filter: drop-shadow(0 4px 5px rgba(0, 0, 0, .16));
}
.product-card .card-name {
  font-size: 13.5px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-badge {
  position: absolute; left: 6px; bottom: 6px;
  padding: 1px 8px; border-radius: 999px;
  background: rgba(21, 96, 130, .92); color: #fff; font-size: 11px; font-weight: 600; line-height: 1.7;
}
.variant-card { touch-action: pan-y; }
.variant-card .card-art { border-width: 2px; }
.variant-card .card-badge { left: 4px; bottom: 4px; padding: 0 6px; font-size: 10.5px; }
.img-failed .card-art::after {
  content: "圖片暫時無法載入"; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 12px; color: var(--muted); background: #f6f8fa;
}

/* 下方按鈕列：編輯中是「重拍｜繼續」（電腦／橫向手機），按了繼續之後是三顆圓形按鈕「返回｜儲存｜分享」（示意圖 5） */
.action-bar {
  grid-area: actions;
  height: calc(var(--actions-h) + var(--safe-bottom));
  display: flex; align-items: center; justify-content: center;
  padding: 0 12px var(--safe-bottom);
  background: #fff;
  overflow: hidden;
}
.edit-actions { flex: 1; max-width: 560px; display: flex; align-items: center; justify-content: space-between; }
.final-actions { flex: 1; max-width: 520px; display: flex; align-items: center; justify-content: space-evenly; }
body[data-mode="edit"] .final-actions, body[data-mode="final"] .edit-actions { display: none; }
/* 手機直向：編輯中的重拍／繼續在產品選單的藍色列上，下方不放按鈕；完成後收掉產品選單 */
body[data-mode="edit"] .action-bar { display: none; }
body[data-mode="final"] .sheet { display: none; }
body[data-mode="final"] .edit-tools .tool-group { display: none; }

/* 手機：選單拉起時，照片在上、選單在下（示意圖 3） */
body[data-sheet="open"] .topbar { height: 0; padding-top: 0; border-bottom-width: 0; }
body[data-sheet="open"] .edit-tools { height: 0; border-bottom-color: transparent; }
body[data-sheet="open"] .sheet { height: var(--sheet-open-h); }
body[data-sheet="open"] .sheet-peek { display: none; }
body[data-sheet="open"] .sheet-panel { display: flex; }
body[data-sheet="open"] .stage-shell { padding: 8px; }

/* 拖曳中的產品 */
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 60;
  width: 120px; height: 120px; margin: -60px 0 0 -60px;
  pointer-events: none; will-change: transform;
}
.drag-ghost img {
  width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .35));
  transform: scale(.9); opacity: .85; transition: transform .15s, opacity .15s;
}
.drag-ghost.over img { transform: scale(1.08); opacity: 1; }
body.dragging, body.dragging * { cursor: grabbing !important; user-select: none !important; -webkit-user-select: none !important; }

/* 提示訊息 */
.toast {
  position: fixed; left: 50%; z-index: 90;
  bottom: calc(var(--peek-h) + 14px + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  width: max-content; max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 12px;
  background: rgba(18, 23, 28, .93); color: #fff; font-size: 14px; line-height: 1.45;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .25);
  animation: toast-in .22s var(--ease);
}
.toast .icon { color: var(--cyan); }
.toast.is-error { background: #b3261e; }
.toast.is-error .icon { color: #fff; }
body[data-mode="final"] .toast { bottom: calc(var(--actions-h) + 14px + var(--safe-bottom)); }
body[data-screen="capture"] .toast { bottom: calc(150px + var(--safe-bottom)); }
body[data-sheet="open"] .toast { top: calc(14px + var(--safe-top)); bottom: auto; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* 對話框 */
.app-dialog {
  width: min(92vw, 440px); max-height: 90vh; padding: 20px;
  border: 0; border-radius: 16px; color: var(--ink); background: #fff;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .3);
}
.app-dialog::backdrop { background: rgba(6, 22, 32, .55); }
.app-dialog h2 { margin: 0; font-size: 19px; font-weight: 800; }
.app-dialog p { color: var(--ink-2); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.dialog-actions.stacked { flex-direction: column; align-items: stretch; margin-top: 12px; }
.share-preview { display: grid; place-items: center; min-height: 160px; border-radius: 10px; background: var(--stage-bg); overflow: hidden; }
.share-preview img { display: block; max-width: 100%; max-height: 46vh; object-fit: contain; -webkit-touch-callout: default; }
.share-message { margin: 12px 2px 0; font-size: 14px; line-height: 1.6; }
.help-steps { margin: 4px 0 0; padding: 0; list-style: none; counter-reset: step; display: grid; gap: 12px; }
.help-steps li { counter-increment: step; display: grid; grid-template-columns: 30px 1fr; column-gap: 10px; }
.help-steps li::before {
  content: counter(step); grid-row: span 2; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 700; font-size: 14px;
}
.help-steps strong { font-size: 15px; }
.help-steps span { color: var(--ink-2); font-size: 14px; }
.help-note { display: flex; gap: 8px; margin: 16px 0 0; padding: 12px; border-radius: 10px; background: #f1f6f9; font-size: 13px; }
.help-note .icon { color: var(--brand); margin-top: 2px; }
.noscript { position: fixed; inset: auto 16px 16px; padding: 14px; border-radius: 12px; background: #b3261e; color: #fff; text-align: center; z-index: 99; }

/* 清單圖片放大：沿用原生 dialog 的焦點圈限、Esc 與遮罩，不載入外部套件。 */
.gallery-dialog { width: min(94vw, 760px); max-height: calc(100dvh - 24px); padding: 16px; overscroll-behavior: contain; }
.gallery-dialog .dialog-heading { margin-bottom: 4px; align-items: start; }
.gallery-dialog h2 { font-size: 17px; line-height: 1.4; overflow-wrap: anywhere; }
.gallery-dialog .dialog-heading button { flex: none; }
.gallery-dialog .gallery-variant { margin: 0 0 12px; color: var(--brand); font-size: 14px; font-weight: 700; }
.gallery-stage { height: min(52vh, 500px); height: min(52dvh, 500px); min-height: 100px; position: relative; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #f1f6f9; touch-action: pan-y pinch-zoom; }
/* 圖片絕對定位填滿展示框，直式圖（耳機）才不會撐出框外被裁掉 */
.gallery-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 12px; user-select: none; -webkit-user-drag: none; transition: filter .2s; }
.gallery-stage p { position: absolute; margin: 16px; padding: 8px 12px; border-radius: 8px; background: rgba(255, 255, 255, .92); text-align: center; font-size: 14px; }
/* 大圖載入中：先顯示縮圖，右下角轉圈 */
.gallery-stage.is-loading img { filter: blur(1.5px); }
.gallery-stage.is-loading::after {
  content: ''; position: absolute; right: 12px; bottom: 12px; width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid rgba(21, 96, 130, .2); border-top-color: var(--cyan); animation: spin .8s linear infinite;
}
.gallery-controls { display: flex; align-items: center; justify-content: center; gap: 24px; margin-top: 12px; }
.gallery-controls button { min-width: 44px; min-height: 44px; }
.gallery-controls output { min-width: 70px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; }
.gallery-dialog .gallery-hint { margin: 10px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
@media (max-height: 520px) {
  /* 手機橫拿：省下說明文字，圖片用掉剩下的高度 */
  .gallery-dialog { padding: 10px 14px; }
  .gallery-dialog h2 { font-size: 14px; }
  .gallery-dialog .gallery-variant { margin-bottom: 6px; }
  .gallery-stage { height: calc(100vh - 170px); height: calc(100dvh - 170px); }
  .gallery-controls { margin-top: 6px; }
  .gallery-dialog .gallery-hint { display: none; }
}

/* ---------- 完成頁：右側滑出的「照片中的羅技產品」清單（加入羅技商城購物車） ---------- */
.cart-tab {
  position: absolute; right: 0; top: 50%; z-index: 3;
  width: 50px; height: 78px; margin-top: -39px; padding: 0 2px 0 10px;
  border: 0; background: none; display: grid; place-items: center;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .3));
  touch-action: none;
}
.cart-tab-shape { width: 36px; height: 50px; }
.cart-tab-shape path { fill: var(--brand); stroke: #fff; stroke-width: 2.5; stroke-linejoin: round; transition: fill .15s; }
@media (hover: hover) { .cart-tab:hover .cart-tab-shape path { fill: var(--brand-dark); } }
.cart-tab:focus-visible { outline: none; }
.cart-tab:focus-visible .cart-tab-shape path { stroke: var(--cyan); stroke-width: 4; }
.cart-tab.nudge .cart-tab-shape { animation: tab-nudge 1.1s ease-in-out .3s 2; }
@keyframes tab-nudge { 0%, 100% { transform: none; } 35% { transform: translateX(-9px); } 65% { transform: none; } }
body.cart-open .cart-tab { visibility: hidden; }

.cart-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(6, 22, 32, .45); animation: fade-in .2s ease-out; }
@keyframes fade-in { from { opacity: 0; } }
.cart-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 81;
  width: min(88vw, 400px);
  display: flex; flex-direction: column;
  background: #fff; box-shadow: -14px 0 34px rgba(0, 0, 0, .24);
  transform: translateX(calc(100% + 40px)); visibility: hidden;
  transition: transform .32s var(--ease), visibility 0s linear .32s;
  touch-action: pan-y;
}
body.cart-open .cart-drawer { transform: none; visibility: visible; transition: transform .32s var(--ease); }
.cart-drawer * { touch-action: pan-y; } /* 橫向滑動留給「往右滑收起」，清單只上下捲 */
.cart-head {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + var(--safe-top)) 10px 10px 18px;
  background: var(--brand); color: #fff;
}
.cart-head h2 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: .04em; }
.cart-close { width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .16); color: #fff; display: grid; place-items: center; }
.cart-close .icon { width: 24px; height: 24px; stroke-width: 2.6; }
.cart-sub { flex: none; margin: 0; padding: 10px 18px 2px; font-size: 13px; color: var(--muted); }
.cart-list { flex: 1; min-height: 0; margin: 0; padding: 2px 14px 8px; list-style: none; overflow-y: auto; overscroll-behavior: contain; }
.cart-item { display: grid; grid-template-columns: auto 64px minmax(0, 1fr); gap: 10px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.cart-item:last-child { border-bottom: 0; }
.cart-check { display: grid; place-items: center; width: 26px; height: 64px; }
.cart-check input { width: 22px; height: 22px; margin: 0; accent-color: var(--brand); }
.cart-thumb-button { position: relative; width: 64px; height: 64px; padding: 0; border: 0; border-radius: 4px; background: #f1f6f9; cursor: zoom-in; }
.cart-thumb-button:disabled { cursor: default; }
.cart-thumb { display: block; width: 100%; height: 100%; object-fit: contain; border: 2px solid var(--brand); border-radius: 4px; background: #fff; }
.cart-thumb-hint { position: absolute; bottom: -2px; right: -2px; padding: 1px 4px; border-radius: 4px; background: var(--brand); color: #fff; font-size: 10px; line-height: 1.5; pointer-events: none; }
.cart-thumb-empty { display: grid; place-items: center; height: 100%; padding: 4px; font-size: 11px; color: var(--muted); }
.cart-spec { font-size: 13px; color: var(--ink-2); }
.cart-info { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.cart-name {
  font-size: 14px; font-weight: 700; line-height: 1.35; color: var(--ink); text-decoration: none;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
a.cart-name:focus-visible { outline-offset: 1px; }
.cart-variant { height: 34px; max-width: 100%; padding: 0 6px; border: 2px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font-size: 14px; }
.cart-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 8px; }
.qty { display: inline-flex; align-items: center; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; }
.qty button { width: 34px; height: 32px; border: 0; background: #fff; color: var(--ink); display: grid; place-items: center; }
.qty button:disabled { opacity: .3; }
.qty button .icon { width: 16px; height: 16px; stroke-width: 2.6; }
.qty output { min-width: 24px; text-align: center; font-size: 15px; font-weight: 700; }
.cart-status { margin: 0; font-size: 12.5px; font-weight: 600; color: var(--danger); }
.cart-status a { color: var(--brand); font-weight: 700; }
.cart-item.is-off .cart-thumb, .cart-item.is-off .cart-name { opacity: .45; }
.cart-empty { padding: 30px 8px; text-align: center; color: var(--muted); }
.cart-foot { flex: none; display: flex; flex-direction: column; gap: 8px; padding: 12px 16px calc(14px + var(--safe-bottom)); border-top: 1px solid var(--line); background: #fff; }
.cart-total { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink-2); }
.cart-coupon { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.coupon-chip { padding: 1px 10px; border: 2px dashed var(--brand); border-radius: 6px; color: var(--brand); font-size: 13px; font-weight: 800; letter-spacing: .08em; }
.cart-go { width: 100%; min-height: 50px; font-size: 16px; text-decoration: none; }
.cart-go[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.cart-note { margin: 0; font-size: 11.5px; line-height: 1.5; color: var(--muted); }
@media (max-width: 380px) {
  .cart-drawer { width: 92vw; }
  .cart-list { padding: 2px 10px 8px; }
  .cart-item { grid-template-columns: auto 52px minmax(0, 1fr); gap: 8px; }
  .cart-check { height: 52px; }
  .cart-thumb-button { width: 52px; height: 52px; }
}
@media (max-height: 520px) {
  .cart-sub { display: none; }
  .cart-head { padding-top: calc(6px + var(--safe-top)); padding-bottom: 6px; }
  .cart-foot { gap: 6px; padding-top: 8px; }
  .cart-go { min-height: 44px; }
}

/* ---------- 寬螢幕 / 橫向手機：右側固定產品欄 ---------- */
@media (min-width: 900px), (orientation: landscape) and (max-height: 520px) {
  .editor {
    grid-template-columns: minmax(0, 1fr) clamp(300px, 30vw, 420px);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "tools sheet" "stage sheet" "actions sheet";
  }
  /* 按了繼續：收掉右側產品欄，完成的圖片置中 */
  body[data-mode="final"] .editor { grid-template-columns: minmax(0, 1fr); grid-template-areas: "tools" "stage" "actions"; }
  .sheet { height: auto; box-shadow: none; border-left: 1px solid var(--line); }
  .sheet-peek, .sheet-nav, .sheet-bar-toggle { display: none; }
  .sheet-panel { display: flex; }
  .sheet-bar { height: 52px; padding: 0 16px; touch-action: auto; }
  .sheet-bar-title { display: block; }
  body[data-mode="edit"] .action-bar { display: flex; }
  .action-bar { height: calc(var(--actions-h) + 8px + var(--safe-bottom)); }
  .final-actions { flex: none; justify-content: center; gap: clamp(28px, 5vw, 64px); }
  .toast { bottom: calc(var(--actions-h) + 24px + var(--safe-bottom)); left: calc(50% - clamp(150px, 15vw, 210px)); }
  body[data-mode="final"] .toast { bottom: calc(var(--actions-h) + 24px + var(--safe-bottom)); left: 50%; }
  body[data-screen="capture"] .toast { left: 50%; }
}
@media (min-width: 900px) {
  :root { --topbar-h: 60px; --tools-h: 52px; }
  .brand img { height: 34px; }
  .capture { padding: 24px 24px 14px; gap: 18px; }
  .stage-shell { padding: 24px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  :root { --topbar-h: 40px; --tools-h: 42px; --actions-h: 66px; }
  .brand img { height: 22px; }
  .round-button { --size: 46px; }
  .round-button > span { display: none; }
  .round-button > .icon { border-width: 2.5px; }
  .capture { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: minmax(0, 1fr) auto; padding: 10px 16px calc(6px + var(--safe-bottom)); gap: 8px 18px; }
  .viewfinder-area { grid-row: 1; grid-column: 1; }
  .capture-controls { grid-row: 1; grid-column: 2; grid-template-columns: auto; grid-template-rows: 1fr auto 1fr; height: 100%; width: auto; gap: 14px; }
  .round-button.shutter { --size: 66px; }
  .fine-print { grid-column: 1 / -1; font-size: 11px; }
  .stage-shell { padding: 8px; }
  .sheet-body { padding: 8px 10px 0; }
  .sheet-tip { display: none; }
  /* 右側欄只有 300px 寬：固定兩欄（角度三欄），一次看得到更多產品 */
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 8px; }
  .variant-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .card-name { font-size: 13.5px; }
}
@media (max-width: 380px) {
  :root { --pill-h: 40px; }
  .round-button { --size: 56px; }
  .round-button.shutter { --size: 76px; }
  .tool-button { width: 37px; }
  body.has-selection .edit-hint { display: none; }
  .nav-pill { padding: 0 12px; font-size: 15px; letter-spacing: .02em; }
  .nav-pill .icon { width: 20px; height: 20px; }
  .sheet-peek { font-size: 14px; letter-spacing: .02em; }
}
@media (max-height: 640px) and (orientation: portrait) {
  :root { --tools-h: 44px; --actions-h: 86px; --peek-h: 52px; --pill-h: 40px; }
  .round-button { --size: 54px; }
  .round-button.shutter { --size: 72px; }
  .capture { gap: 10px; padding-top: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ---------- 開場動畫：Logitech G 直式 Logo 置中，下方標語 ----------
   同一張 splash-logo.png 疊三層，用 clip-path 切成 G 的圓弧、方塊和 logitech 字樣，各自動：
   0.1s 圓弧繞著 G 的圓心轉進來、方塊從右邊滑進來 → 0.8s 扣上時亮一下 → 字樣、兩行標語浮現 → 2.3s 像布幕往上拉開（約 3.1 秒）。
   百分比對應 splash-logo.png（600×772）：圓弧／方塊分界 x 51.15%，G／字樣分界 y 70.21%，G 的圓心 (50.95%, 32.37%)。 */
.splash {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center; overflow: hidden;
  background:
    radial-gradient(60% 45% at 50% 40%, rgba(0, 184, 252, .13), transparent 70%),
    radial-gradient(130% 90% at 50% 40%, #0f3c54 0%, #0a2332 45%, #04090c 100%);
  color: #e8f7fd; -webkit-user-select: none; user-select: none; touch-action: none;
  animation: splash-curtain .79s cubic-bezier(.76, 0, .24, 1) 2.3s forwards; /* 上拉 0.79 秒：tim 要求比原本 0.55 秒慢（速度 0.7 倍） */
}
/* 布幕下緣的青色光線 */
.splash::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; opacity: 0;
  background: linear-gradient(90deg, transparent, var(--cyan) 18%, #9be8ff 50%, var(--cyan) 82%, transparent);
  box-shadow: 0 0 22px 3px rgba(0, 184, 252, .7);
  animation: splash-show .15s linear 2.3s forwards;
}
.splash.is-leaving { animation: splash-fade .3s ease forwards; }
.splash-content { display: grid; justify-items: center; gap: clamp(22px, 4.5vh, 40px); animation: splash-content-out .4s cubic-bezier(.5, 0, .75, 0) 2.2s forwards; }
.splash-logo { position: relative; width: clamp(128px, 34vmin, 240px); aspect-ratio: 600 / 772; animation: splash-lock .45s ease-out .78s; }
.splash-logo img { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; -webkit-user-drag: none; }
.splash-arc { clip-path: inset(0 48.85% 29.79% 0); transform-origin: 50.95% 32.37%; animation: splash-arc .8s cubic-bezier(.16, 1, .3, 1) .12s forwards; }
.splash-bracket { clip-path: inset(0 0 29.79% 51.15%); animation: splash-bracket .7s cubic-bezier(.16, 1, .3, 1) .28s forwards; }
.splash-word { clip-path: inset(70.21% 0 0 0); animation: splash-word .6s cubic-bezier(.33, 1, .68, 1) .72s forwards; }
/* 字樣那層留在版面裡撐出 Logo 的高度，不支援 aspect-ratio 的舊版 Safari 也不會變成 0 高 */
.splash-logo img.splash-word { position: relative; display: block; height: auto; }
.splash-glow {
  position: absolute; left: 50.95%; top: 32.37%; width: 115%; aspect-ratio: 1; border-radius: 50%; opacity: 0;
  background: radial-gradient(circle, rgba(0, 184, 252, .5) 0%, rgba(0, 184, 252, .16) 42%, transparent 70%);
  transform: translate(-50%, -50%) scale(.4);
  animation: splash-glow .9s ease-out .8s forwards;
}
/* 掃過 Logo 的反光：用 Logo 本身當遮罩，只亮在 Logo 上 */
.splash-shine {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(110deg, transparent 40%, rgba(255, 255, 255, .75) 50%, transparent 60%) 100% 0 / 250% 100% no-repeat;
  -webkit-mask: url(/splash-logo.png) center / 100% 100% no-repeat; mask: url(/splash-logo.png) center / 100% 100% no-repeat;
  animation: splash-shine .7s ease-in-out 1.15s forwards;
}
/* 標語排兩行：大字「一拍即合」＋小一號的下一句（分行處的逗號只是隱藏，文字內容仍是完整的一句） */
.splash-slogan { margin: 0; padding: 0 16px; display: grid; justify-items: center; gap: 6px; text-align: center; color: #e8f7fd; }
.splash-slogan > span { display: block; white-space: nowrap; }
.splash-slogan-main {
  font-size: clamp(28px, 3.4vmin + 16px, 44px); font-weight: 800; letter-spacing: .32em; text-indent: .32em; line-height: 1.3;
  color: #fff; text-shadow: 0 0 22px rgba(0, 184, 252, .6);
  opacity: 0; clip-path: inset(0 100% 0 0);
  animation: splash-slogan .6s cubic-bezier(.33, 1, .68, 1) .85s forwards;
}
.splash-slogan-sep { display: none !important; }
.splash-slogan-sub {
  font-size: clamp(15px, 1.4vmin + 10px, 22px); font-weight: 600; letter-spacing: .18em; text-indent: .18em; line-height: 1.4;
  color: #cfe9f5; text-shadow: 0 0 14px rgba(0, 184, 252, .35);
  opacity: 0; transform: translateY(8px);
  animation: splash-sub .55s ease-out 1.05s forwards;
}
.splash-slogan::after {
  content: ''; display: block; width: 0; height: 2px; margin-top: 8px; border-radius: 2px;
  background: var(--cyan); box-shadow: 0 0 10px rgba(0, 184, 252, .8);
  animation: splash-bar .45s ease-out 1.55s forwards;
}
@keyframes splash-arc { from { opacity: 0; transform: rotate(-135deg) scale(.85); } 30% { opacity: 1; } to { opacity: 1; transform: none; } }
@keyframes splash-bracket { from { opacity: 0; transform: translateX(26%); } 40% { opacity: 1; } to { opacity: 1; transform: none; } }
@keyframes splash-word { from { opacity: 0; transform: translateY(5%); filter: blur(4px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes splash-lock { 40% { transform: scale(1.045); } }
@keyframes splash-glow { 35% { opacity: 1; } to { opacity: .35; transform: translate(-50%, -50%) scale(1.15); } }
@keyframes splash-shine { to { background-position: 0 0; } }
@keyframes splash-slogan { from { opacity: 0; clip-path: inset(0 100% 0 0); transform: translateY(6px); } to { opacity: 1; clip-path: inset(0 0 0 0); transform: none; } }
@keyframes splash-sub { to { opacity: 1; transform: none; } }
@keyframes splash-bar { to { width: 56px; } }
@keyframes splash-show { to { opacity: 1; } }
@keyframes splash-content-out { to { opacity: 0; transform: translateY(-3vh) scale(.97); } }
@keyframes splash-curtain { to { transform: translateY(-100%); visibility: hidden; } }
@keyframes splash-fade { to { opacity: 0; visibility: hidden; } }
@media (prefers-reduced-motion: reduce) {
  /* 減少動態效果：不轉、不滑，Logo 與標語直接出現，1.8 秒後淡出（要蓋過上面把動畫縮成 0.01ms 的通用規則） */
  .splash { animation: splash-fade .35s ease 1.8s forwards !important; }
  .splash.is-leaving { animation: splash-fade .2s ease forwards !important; }
  .splash::after, .splash-glow, .splash-shine { display: none; }
  .splash-content, .splash-logo, .splash-logo img, .splash-slogan > span, .splash-slogan::after { animation: none !important; }
  .splash-logo img, .splash-slogan > span { opacity: 1; transform: none; }
  .splash-slogan-main { clip-path: none; }
  .splash-slogan::after { width: 56px; }
}
@media print { .splash { display: none; } }
