:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #17202c;
  --muted: #66727f;
  --line: #dde4ec;
  --accent: #19b8d8;
  --accent-ink: #ffffff;
  --accent-soft: #e2f6fb;
  --stage: #e9eef4;
  --danger: #d6455d;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131a;
    --panel: #161d27;
    --ink: #e6edf5;
    --muted: #8d9aa8;
    --line: #26303d;
    --accent: #3fd4ef;
    --accent-ink: #062029;
    --accent-soft: #11313b;
    --stage: #0a0f15;
    --danger: #ff6b84;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* top bar */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.bar h1 { margin: 0; font-size: 18px; letter-spacing: .02em; }
.bar h1 span { color: var(--accent); font-weight: 600; margin-left: 4px; }
.bar-actions { display: flex; gap: 8px; }

.primary, .ghost {
  border-radius: 999px; padding: 7px 16px; border: 1px solid transparent; white-space: nowrap;
}
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.primary:disabled { opacity: .55; cursor: progress; }
.ghost { background: transparent; border-color: var(--line); }
.ghost:hover { border-color: var(--accent); }
.ghost.small { padding: 4px 12px; font-size: 13px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; }

main { flex: 1; min-height: 0; display: flex; }

/* upload */
.drop {
  flex: 1; display: grid; place-items: center; padding: 24px 16px;
}
.drop-inner {
  width: min(560px, 100%); text-align: center; padding: 48px 24px;
  border: 2px dashed var(--line); border-radius: 20px; background: var(--panel);
  transition: border-color .15s, background .15s;
}
.drop.over .drop-inner { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon svg { width: 72px; height: 72px; fill: var(--accent); filter: drop-shadow(0 0 10px var(--accent)); }
.drop-title { font-size: 17px; margin: 12px 0 6px; }
.drop .muted { margin: 4px 0; font-size: 13px; }
.drop p { text-wrap: pretty; word-break: keep-all; }  /* break Chinese at punctuation, not mid-phrase */

/* editor */
.editor { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.stage { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--stage); }
.frame { position: relative; flex: 1; min-height: 0; overflow: hidden; }
/* Images are sized by fitImages() in app.js and centred here. */
.frame img {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  border-radius: 6px; user-select: none; -webkit-user-select: none;
  box-shadow: 0 4px 24px rgba(0, 0, 0, .18);
}
#result { cursor: grab; touch-action: none; }
#result.dragging { cursor: grabbing; }
.busy {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 18px 24px; border-radius: var(--radius); background: color-mix(in srgb, var(--panel) 88%, transparent);
  box-shadow: 0 4px 24px rgba(0, 0, 0, .2);
}
.busy p { margin: 0; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.frame.pending #result { filter: blur(6px) saturate(.7); }
.stage-foot {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 16px 12px;
}
#timing { margin-left: auto; }
#occlusionStatus { color: var(--accent); }

/* manual shoulder marks */
#result.marking { cursor: crosshair; }
.marks { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.mark-dot {
  position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .45);
}
.mark-bar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 2;
  display: flex; align-items: center; gap: 10px; max-width: calc(100% - 24px);
  padding: 6px 8px 6px 16px; border-radius: 999px; font-size: 14px;
  background: color-mix(in srgb, var(--panel) 92%, transparent); box-shadow: 0 4px 18px rgba(0, 0, 0, .2);
}

/* panel */
.panel {
  min-height: 0; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line);
  padding: 8px 18px 20px;
}
.group { padding: 12px 0; border-bottom: 1px solid var(--line); }
.group h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 8px; letter-spacing: .04em; }
.ctl { margin: 8px 0 12px; }
.ctl-head { display: flex; align-items: center; gap: 8px; min-height: 26px; }
.ctl-head > :first-child { margin-right: auto; font-size: 14px; }
.ctl-val { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.ctl-val.changed { color: var(--accent); font-weight: 600; }
.reset {
  flex: none; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line);
  background: none; color: var(--accent); font-size: 15px; line-height: 1; padding: 0;
}
.reset:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.reset:disabled { color: var(--muted); opacity: .35; cursor: default; }
.opt { margin: 8px 0 12px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.switch-row .switch { margin: 0; }
.ctl-hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 4px 0 0; }
.range { position: relative; }
/* Takes the touches on touch screens, see touchSlider() in app.js. */
.range-touch { display: none; position: absolute; inset: 0; touch-action: pan-y pinch-zoom; }

.switch { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 14px; cursor: pointer; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; margin: 4px 0 0; }
.seg button { border: 0; background: none; padding: 4px 16px; border-radius: 999px; font-size: 14px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

details { margin-top: 4px; }
summary { cursor: pointer; font-size: 14px; color: var(--muted); padding: 4px 0; }
.panel-foot { padding-top: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  max-width: calc(100% - 32px); padding: 10px 18px; border-radius: 10px;
  background: var(--ink); color: var(--bg); box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}
.toast.error { background: var(--danger); color: #fff; }

/* touch screens: sliders move only on a sideways drag; larger targets */
@media (pointer: coarse) {
  .range-touch { display: block; }
  input[type=range] { height: 32px; }
  .reset { width: 34px; height: 34px; }
  .seg button { padding: 7px 18px; }
  #compareBtn { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
}

/* phones: preview on top, controls below */
@media (max-width: 820px) {
  .bar { padding: 8px 16px; }
  .bar h1 { font-size: 16px; }
  .primary, .ghost { padding: 6px 12px; }
  main { display: block; }
  .editor { display: block; }
  .stage { position: sticky; top: 0; z-index: 3; }
  .frame { flex: none; height: 52vh; }
  .stage-foot { padding: 6px 16px 8px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); padding: 4px 16px 32px; overflow: visible; }
  #hint { display: none; }
}
