:root {
  --bg: #161b20; --panel: #1e252c; --line: #2e3842; --text: #e6edf2; --muted: #93a1ad;
  --accent: #3fb6e8; --accent-t: #062230; --ok: #7dffb0; --warn: #ffd36a; --danger: #e05a4f;
  --sheet: 46vh;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px system-ui, -apple-system, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif; overflow: hidden;
  overscroll-behavior: none; touch-action: manipulation; }
button { font: inherit; color: inherit; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#view { position: relative; flex: 1 1 auto; min-height: 0; touch-action: none; }
#view canvas { display: block; width: 100%; height: 100%; }
#topbar { position: absolute; left: 0; right: 0; top: 0; padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  display: flex; gap: 6px; align-items: flex-start; pointer-events: none;
  background: linear-gradient(rgba(14, 18, 22, .78), rgba(14, 18, 22, 0)); }
#caseTitle { flex: 1; font-weight: 700; font-size: 15px; line-height: 1.3; text-shadow: 0 1px 2px #000; }
#camBtns { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; pointer-events: auto; max-width: 62%; }
#camBtns button { background: rgba(30, 37, 44, .85); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; font-size: 13px; }
#exposeBtn { position: absolute; right: 10px; bottom: 10px; z-index: 2; border: 0; border-radius: 40px; padding: 14px 22px;
  background: var(--danger); color: #fff; font-weight: 800; font-size: 18px; box-shadow: 0 3px 12px rgba(0, 0, 0, .5); }
#exposeBtn:disabled { background: #555; color: #bbb; }
#lastShot { position: absolute; left: 10px; bottom: 12px; z-index: 2; border: 1px solid var(--accent); border-radius: 20px; padding: 8px 12px;
  background: rgba(14, 18, 22, .8); color: #7fd8ff; font-size: 13px; }

#sheet { flex: 0 0 var(--sheet); display: flex; flex-direction: column; background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); min-height: 0; transition: flex-basis .2s; }
#grab { height: 18px; display: flex; align-items: center; justify-content: center; touch-action: none; }
#grab span { width: 44px; height: 5px; border-radius: 3px; background: #4b5762; }
#tabs { display: flex; overflow-x: auto; gap: 2px; padding: 0 6px 6px; border-bottom: 1px solid var(--line); scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
#tabs button { flex: 0 0 auto; border: 0; background: transparent; padding: 7px 11px; border-radius: 16px; color: var(--muted); font-size: 15px; }
#tabs button.on { background: var(--accent); color: var(--accent-t); font-weight: 700; }
#panel { flex: 1; overflow-y: auto; padding: 8px 10px 14px; -webkit-overflow-scrolling: touch; }

@media (orientation: landscape) {
  #app { flex-direction: row; }
  #sheet { flex: 0 0 42vw; border-top: 0; border-left: 1px solid var(--line); }
  #grab { display: none; }
}

/* panel widgets */
.title { font-weight: 700; font-size: 16px; margin: 6px 0 6px; }
.text { color: var(--text); margin: 4px 0; line-height: 1.45; }
.muted { color: var(--muted); font-size: 13px; }
.gap { height: 8px; }
.btns { display: flex; gap: 6px; margin: 5px 0; }
.btns button { flex: 1; min-height: 42px; border: 1px solid var(--line); background: #27313a; border-radius: 10px; padding: 6px 4px; font-size: 14px; line-height: 1.2; }
.btns button.on { background: #1f5f7a; border-color: var(--accent); color: #fff; font-weight: 700; }
.btns button:active { filter: brightness(1.3); }
.row { margin: 7px 0 9px; }
.row .lab { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 3px; }
.row .lab b { color: var(--ok); font-weight: 700; }
.row .ctl { display: flex; gap: 6px; align-items: center; }
.row .ctl button { flex: 0 0 44px; height: 40px; border: 1px solid var(--line); background: #27313a; border-radius: 10px; font-size: 22px; line-height: 1; }
.row .ctl input[type=range] { flex: 1; height: 40px; accent-color: var(--accent); }
.row select { width: 100%; height: 42px; background: #27313a; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; font: inherit; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 6px 0; }
.pad button { min-height: 46px; border: 1px solid var(--line); background: #27313a; border-radius: 10px; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chips button { border: 1px solid var(--line); background: #27313a; border-radius: 16px; padding: 7px 10px; font-size: 14px; }
.chips button.on { background: #1f5f7a; border-color: var(--accent); color: #fff; }
.info { color: var(--ok); font-size: 14px; margin: 4px 0; }

/* result screen */
#result { position: fixed; inset: 0; z-index: 10; background: #0b0e11; display: flex; flex-direction: column; }
#result[hidden] { display: none; }
#resHead { display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 8px) 10px 8px; border-bottom: 1px solid var(--line); }
#resHead button { border: 1px solid var(--accent); background: transparent; color: #7fd8ff; border-radius: 18px; padding: 7px 12px; font-size: 14px; }
#resInfo { color: var(--muted); font-size: 13px; }
#resBody { flex: 1; overflow-y: auto; padding: 8px 10px calc(env(safe-area-inset-bottom) + 16px); }
#imgWrap { position: relative; background: #000; border-radius: 8px; overflow: hidden; touch-action: manipulation; }
#xray { display: block; width: 100%; height: auto; max-height: 62vh; object-fit: contain; margin: 0 auto; }
#imgHint { position: absolute; left: 8px; right: 8px; top: 8px; background: rgba(255, 211, 106, .92); color: #231a00; border-radius: 8px;
  padding: 6px 8px; font-size: 13px; text-align: center; pointer-events: none; }
.score-total { font-size: 26px; font-weight: 800; margin: 10px 0 4px; }
.items { width: 100%; border-collapse: collapse; font-size: 14px; margin: 6px 0; }
.items td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.items td:last-child { text-align: right; white-space: nowrap; }
.bar { height: 6px; background: #2b343c; border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar i { display: block; height: 100%; background: var(--ok); }
.hints li { margin: 4px 0; line-height: 1.45; }
@media (orientation: landscape) {
  #resBody { display: grid; grid-template-columns: 58% 1fr; gap: 12px; align-items: start; }
  #xray { max-height: 78vh; }
  #resTools { grid-column: 1; }
  #resScore { grid-column: 2; grid-row: 1 / span 3; }
}

#loading { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: var(--bg); padding: 24px; text-align: center; }
#loading.hidden { display: none; }
#loading h1 { font-size: 24px; margin: 0; }
#status { color: #7fd8ff; }
#bar { width: 70%; max-width: 320px; height: 8px; background: #2b343c; border-radius: 4px; overflow: hidden; }
#bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.small { color: var(--muted); font-size: 13px; }
.credit { position: fixed; right: 6px; bottom: 2px; font-size: 9px; color: #55626d; pointer-events: none; z-index: 1; }
