:root {
  --bg: #14161a; --panel: #1d2026; --panel2: #262a32; --line: #343a45;
  --fg: #e8eaee; --mut: #98a0ad; --accent: #4aa3ff; --danger: #ff6b6b;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); overscroll-behavior: none;
  font: 14px/1.45 system-ui, -apple-system, "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
[hidden] { display: none !important; }
#app { height: 100dvh; 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); }

button, select, input[type=text], input[type=number] {
  font: inherit; color: var(--fg); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; min-height: 38px;
}
button { cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
button.on { background: var(--accent); border-color: var(--accent); color: #06121f; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
button.danger { color: var(--danger); }
button.big { font-size: 16px; padding: 12px 24px; }
select { max-width: 100%; }

#topbar { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#topbar h1 { font-size: 16px; margin: 0 6px 0 0; white-space: nowrap; }
#topbar .actions { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
#topbar button { padding: 6px 10px; min-height: 34px; }

#photoStrip { display: flex; gap: 6px; padding: 6px 10px; overflow-x: auto; background: var(--panel); border-bottom: 1px solid var(--line); }
#photoStrip .thumb { position: relative; flex: 0 0 auto; width: 56px; height: 56px; border-radius: 6px; overflow: hidden; border: 2px solid transparent; padding: 0; background: #000; min-height: 0; }
#photoStrip .thumb.on { border-color: var(--accent); }
#photoStrip .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
#photoStrip .thumb .x { position: absolute; top: 0; right: 0; background: rgba(0,0,0,.65); color: #fff; width: 18px; height: 18px; line-height: 16px; text-align: center; font-size: 13px; border-radius: 0 0 0 6px; }

main { flex: 1; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) minmax(0, 46%); }
@media (min-width: 900px) {
  main { grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr) 400px; }
}

#stage { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  background: #0b0c0e; }
#viewport { position: absolute; left: 0; top: 0; transform-origin: 0 0;
  background: repeating-conic-gradient(#1b1d22 0% 25%, #121316 0% 50%) 0 0 / 20px 20px; }
#viewport canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
#cvOrig { visibility: hidden; }
#divider { position: absolute; top: 0; bottom: 0; width: 0; pointer-events: auto; cursor: ew-resize; }
#divider span { position: absolute; left: -14px; top: 0; bottom: 0; width: 28px; }
#divider::after { content: ""; position: absolute; left: -1px; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 4px #000; }
#empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; gap: 8px; }
#empty h2 { margin: 0; font-size: 20px; }
#empty p { margin: 4px 0; color: var(--mut); }
#stage.drag { outline: 3px dashed var(--accent); outline-offset: -6px; }

#toolbar { touch-action: pan-x; position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 6px; padding: 6px; overflow-x: auto; background: rgba(20,22,26,.82); backdrop-filter: blur(6px); }
#toolbar button { flex: 0 0 auto; padding: 6px 10px; min-height: 36px; white-space: nowrap; }

#panel { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-top: 1px solid var(--line); }
@media (min-width: 900px) { #panel { border-top: 0; border-left: 1px solid var(--line); } }
#tabs { display: flex; border-bottom: 1px solid var(--line); }
#tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; border-bottom: 3px solid transparent; }
#tabs button.on { border-bottom-color: var(--accent); color: var(--accent); background: transparent; }
#subtabs { display: flex; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--panel2); }
#subtabs[hidden] { display: none; }
#subtabs button { flex: 1; padding: 5px 8px; min-height: 32px; }
#subtabs button.on { background: var(--accent); border-color: var(--accent); color: #06121f; }
.tab { display: none; overflow-y: auto; padding: 8px; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
.tab.on { display: block; }
#minimap { flex: 0 0 auto; display: flex; justify-content: center; padding: 6px; background: var(--panel2); border-top: 1px solid var(--line); }
#minimap[hidden] { display: none; }
#miniBox { position: relative; overflow: hidden; border-radius: 4px; background: #0b0c0e; box-shadow: 0 0 0 1px var(--line); }
#miniBox canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
#miniHi { animation: miniBlink 1s ease-in-out infinite; }
@keyframes miniBlink { 0%, 100% { opacity: .1; } 50% { opacity: 1; } }
#miniView { position: absolute; pointer-events: none; box-shadow: 0 0 0 1px #fff, 0 0 0 2px rgba(0,0,0,.6); }
.card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; }
.card h3 { margin: 0 0 8px; font-size: 14px; color: var(--accent); }
.card.fold > h3 { display: flex; justify-content: space-between; align-items: center; cursor: pointer; user-select: none; -webkit-user-select: none; }
.card.fold > h3::after { content: '\25BE'; color: var(--mut); }
.card.fold.collapsed > h3 { margin-bottom: 0; }
.card.fold.collapsed > h3::after { content: '\25B8'; }
.card.fold.collapsed > :not(h3) { display: none; }
.hint { color: var(--mut); font-size: 12px; margin: 6px 0 0; }

.row { display: grid; grid-template-columns: 84px 1fr 52px; align-items: center; gap: 8px; margin: 6px 0; }
.row > span { color: var(--mut); font-size: 13px; }
.row output { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.row.chkrow { grid-template-columns: 1fr auto; }
.row input[type=text], .row select { grid-column: 2 / 4; width: 100%; }
.row input[type=range] { width: 100%; min-width: 0; height: 28px; accent-color: var(--accent); }
.row input[type=checkbox] { width: 22px; height: 22px; }
.row2 { display: flex; gap: 8px; margin-top: 8px; }
.row2 select { flex: 1; min-width: 0; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.btnrow button { flex: 1 1 auto; }
.card > button.primary { width: 100%; margin-top: 6px; }

#regionList { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.toolgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.toolgrid button { padding: 6px 2px; min-height: 36px; font-size: 13px; white-space: nowrap; }
.toolhint { margin: 8px 0; padding: 6px 8px; background: var(--panel); border-radius: 6px; }
.eye { width: 32px; height: 32px; min-height: 0; padding: 0; border: 0; background: transparent; color: var(--fg); display: grid; place-items: center; }
.eye svg { width: 20px; height: 20px; }
#regionList li.hid .eye { color: var(--mut); }
#regionList li.hid i, #regionList li.hid input, #regionList li.hid small { opacity: .4; }
#regionList li { display: grid; grid-template-columns: 16px 32px 22px 1fr auto; align-items: center; gap: 6px; padding: 4px 8px 4px 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; position: relative; }
#regionList li.empty { display: block; cursor: default; color: var(--mut); font-size: 12px; padding: 8px; border-style: dashed; }
#regionList li.glob { border-style: dashed; }
#regionList li.glob input { pointer-events: none; }
.modenote { margin: 0 0 8px; }
#regionList .grip { color: var(--mut); text-align: center; cursor: grab; touch-action: none; font-size: 14px; line-height: 1; letter-spacing: -2px; padding: 8px 0; }
#regionList li.moving { opacity: .45; }
#regionList li.sub { border-left: 3px solid var(--accent); }
#regionList li.lv2 { margin-left: 14px; }
#regionList li.lv3 { margin-left: 28px; }
#regionList li.drop-before::before, #regionList li.drop-after::after { content: ''; position: absolute; left: 0; right: 0; height: 3px; background: var(--accent); border-radius: 2px; pointer-events: none; }
#regionList li.drop-before::before { top: -5px; }
#regionList li.drop-after::after { bottom: -5px; }
#regionList li.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
#regionList li { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
#regionList.multi li:not(.sel) { opacity: .45; filter: grayscale(1); }
#regionList li.sel { border-color: #3ddc84; box-shadow: inset 0 0 0 2px #3ddc84; background: rgba(61,220,132,.12); }
#regionList input[readonly] { cursor: pointer; pointer-events: none; }
#regionList i { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(255,255,255,.4); }
#regionList input { background: transparent; border: 0; padding: 4px; min-height: 30px; min-width: 0; color: var(--fg); -webkit-text-fill-color: var(--fg); opacity: 1; -webkit-user-select: text; user-select: text; }
#regionList input:not([readonly]) { background: var(--panel2); border: 1px solid var(--accent); border-radius: 6px; cursor: text; }
#regionList small { color: var(--mut); white-space: nowrap; }

.effect { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-bottom: 8px; background: var(--panel); }
.effect.off { opacity: .6; }
#effectList { margin-top: 10px; }
.eff-head { display: flex; align-items: center; gap: 8px; }
.eff-head input[type=checkbox] { width: 22px; height: 22px; flex: 0 0 auto; }
.eff-head .eff-name { flex: 1; min-width: 0; padding: 4px 8px; min-height: 32px; }
.row.smax input[type=number] { width: 100%; padding: 4px 8px; min-height: 30px; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 99px; background: var(--line); color: var(--mut); }
.eff-btns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.eff-btns button { padding: 4px 8px; min-height: 30px; font-size: 12px; }
.sub { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); }
.sub h4 { margin: 6px 0 2px; font-size: 12px; color: var(--mut); }
.ease-prev { height: 44px; margin: 4px 0 2px; padding: 2px; background: #0b0c0e; border: 1px solid var(--line); border-radius: 6px; }
.ease-prev svg { display: block; width: 100%; height: 100%; }
.ease-lab { display: flex; justify-content: space-between; gap: 6px; font-size: 11px; color: var(--mut); margin-bottom: 4px; }
.ease-lab span:nth-child(2) { flex: 1; text-align: center; }
.row.rs { grid-template-columns: 24px 66px 1fr 56px; gap: 4px; }
.rst { width: 24px; height: 24px; min-height: 0; padding: 0; border: 0; background: transparent; color: var(--accent); font-size: 17px; line-height: 1; display: grid; place-items: center; border-radius: 6px; }
.rst:hover { background: var(--line); }
.rst.off { visibility: hidden; }
.hsl-grid { display: grid; grid-template-columns: 24px 34px repeat(3, 1fr); gap: 4px 6px; align-items: center; font-size: 12px; }
.hsl-grid input[type=range] { width: 100%; min-width: 0; accent-color: var(--accent); }
.hsl-grid .hd { color: var(--mut); text-align: center; }
details summary { cursor: pointer; color: var(--mut); padding: 4px 0; }

#busy { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; gap: 12px; z-index: 50; color: #fff; font-size: 16px; }
.spinner { width: 26px; height: 26px; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(40,44,52,.96); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: 90vw; text-align: center; }

/* 重辨識結果：舞台底部分割工具列（覆蓋在上方，不改變舞台尺寸） */
#dock, #simDock, #cropDock { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; max-height: 46%; display: flex; flex-direction: column; background: rgba(29,32,38,.95); backdrop-filter: blur(6px); border-top: 1px solid var(--line); touch-action: pan-x pan-y; cursor: default; }
#dock input, #simDock input, #cropDock input { user-select: text; -webkit-user-select: text; }
.sim-row input.crop-num { flex: 0 0 64px; min-width: 0; width: 64px; text-align: center; }
.sim-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.sim-row > span { flex: 0 0 auto; min-width: 3em; color: var(--mut); font-size: 13px; }
.sim-row input[type=range] { flex: 1 1 140px; min-width: 100px; }
.sim-row output { flex: 0 0 auto; min-width: 3em; text-align: right; }
.sim-row button { padding: 4px 10px; min-height: 34px; font-size: 13px; white-space: nowrap; }
.sim-row input[type=text] { flex: 1 1 140px; min-width: 100px; min-height: 34px; padding: 4px 8px; }
.sim-chk { display: inline-flex; align-items: center; gap: 4px; min-height: 34px; padding: 0 6px; cursor: pointer; }
.sim-chk input { width: 18px; height: 18px; }
.dock-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.dock-head strong { color: var(--accent); font-size: 14px; white-space: nowrap; }
.dock-head .dock-sp { flex: 1; }
.dock-head button { padding: 4px 10px; min-height: 32px; font-size: 13px; white-space: nowrap; }
.dock-body { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 0; -webkit-overflow-scrolling: touch; }
.dock-body .hint { margin: 0; }
#dlgPool { display: flex; flex-wrap: nowrap; gap: 6px; align-items: center; overflow-x: auto; min-height: 44px; padding: 6px; border: 1px dashed var(--line); border-radius: 8px; flex: 0 0 auto; }
#dlgPool .hint { white-space: nowrap; }
.chip { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 6px; display: grid; place-items: center; font-size: 14px; font-weight: 700; color: #000; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.chip.none { background: var(--panel2); border: 1px dashed var(--mut); color: var(--fg); }
.chip.dragging { opacity: .3; }
.chip.ghost { position: fixed; z-index: 200; pointer-events: none; transform: translate(-50%, -50%) scale(1.15); box-shadow: 0 4px 14px rgba(0,0,0,.6); }
#dlgTable { display: flex; gap: 8px; overflow-x: auto; align-items: stretch; padding-bottom: 4px; flex: 0 0 auto; }
.tcol { flex: 0 0 150px; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); overflow: hidden; }
.tcol .th { display: flex; border-bottom: 1px solid var(--line); }
.tcol .th input { flex: 1; min-width: 0; border: 0; border-radius: 0; background: transparent; padding: 6px 8px; min-height: 36px; }
.tcol .th .tdel { border: 0; border-radius: 0; background: transparent; min-height: 36px; padding: 0 10px; color: var(--mut); font-size: 18px; }
.tcol .td { flex: 1; min-height: 64px; padding: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; }
.dropping { outline: 2px solid var(--accent); outline-offset: -2px; background: rgba(74,163,255,.14); }
.tadd { flex: 0 0 44px; border: 1px dashed var(--line); background: transparent; border-radius: 8px; font-size: 22px; color: var(--mut); }
#btnTplAdmin { margin-left: auto; white-space: nowrap; }
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { width: min(440px, 100%); max-height: min(84dvh, 680px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.modal-card h3 { margin: 0 0 8px; color: var(--accent); }
#shareList { border: 1px solid var(--line); border-radius: 8px; max-height: 220px; overflow: auto; margin: 8px 0; }
.share-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.share-item:last-child { border-bottom: 0; }
.share-item input { width: 18px; height: 18px; }
.share-item .mut { color: var(--mut); margin-left: auto; font-size: 12px; }
#shareCodeOut { margin: 4px 0 8px; font: 22px/1.2 ui-monospace, Consolas, monospace; letter-spacing: .14em; }
