:root {
  --bg: #14161a;
  --panel: #1c1f26;
  --panel-2: #23262f;
  --line: #31353f;
  --text: #e7e9ee;
  --muted: #949aa8;
  --accent: #5b9dff;
  --accent-dim: #2f5fa8;
  --ok: #4ec98a;
  --warn: #e8b64c;
  --err: #ef6b6b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* --- chrome --- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { font-weight: 650; letter-spacing: .2px; }

.topbar nav { display: flex; gap: 4px; }

.topbar nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 14px;
}

.topbar nav a:hover { background: var(--panel-2); color: var(--text); }
.topbar nav a.active { background: var(--accent-dim); color: #fff; }

.device {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

main { max-width: 1240px; margin: 0 auto; padding: 22px; }

/* --- layout --- */

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid-wide { grid-column: 1 / -1; }

@media (max-width: 980px) { .grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 620;
}

.panel .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

/* --- forms --- */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

input[type=text], input[type=number], select, textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}

textarea { resize: vertical; min-height: 120px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dim); outline-offset: -1px; border-color: var(--accent); }

input[type=color] {
  width: 44px; height: 34px; padding: 2px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px;
}

input[type=range] { width: 100%; accent-color: var(--accent); }

.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.check input { width: auto; }

button {
  background: var(--accent-dim);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 9px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
}

button:hover:not(:disabled) { background: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
button.ghost:hover:not(:disabled) { background: var(--panel-2); color: var(--text); border-color: var(--line); }

/* --- file browser --- */

.browser { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }

.browser-path {
  padding: 7px 11px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  text-align: left;
}

.browser-list { max-height: 260px; overflow-y: auto; }

.entry {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 11px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.03);
  font-size: 14px;
}

.entry:hover { background: var(--panel-2); }
.entry.selected { background: var(--accent-dim); }
.entry .size { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.entry.selected .size { color: rgba(255,255,255,.75); }
.entry .icon { opacity: .8; }
.empty { padding: 18px 12px; color: var(--muted); font-size: 13px; text-align: center; }

/* --- preview + watermark box --- */

/* The stage must wrap the preview image exactly, because the placement box is
   positioned relative to it. If the stage were wider or taller than the picture — as a
   full-width block would be for portrait footage — the box would no longer line up with
   what ends up in the frame. inline-block shrink-wraps it to the image in both axes. */
.stage-wrap { display: flex; justify-content: center; }
.stage-wrap[hidden] { display: none; }

.stage {
  position: relative;
  display: inline-block;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
  line-height: 0;
  max-width: 100%;
}

.stage img {
  display: block;
  max-width: 100%;
  max-height: 68vh;   /* keeps tall portrait clips on screen */
  width: auto;
  height: auto;
}

.wm-box {
  position: absolute;
  border: 1.5px dashed rgba(91,157,255,.95);
  cursor: move;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  line-height: 1.15;
  touch-action: none;
}

.wm-box .wm-text {
  white-space: pre;
  text-align: center;
  font-weight: 700;
  pointer-events: none;
  /* Background, padding and text stroke are set from picker.js so they mirror what the
     server actually renders. */
}

.wm-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 1.5px solid #fff;
  border-radius: 3px;
  touch-action: none;
}

.wm-handle.nw { left: -6px; top: -6px; cursor: nwse-resize; }
.wm-handle.ne { right: -6px; top: -6px; cursor: nesw-resize; }
.wm-handle.sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.wm-handle.se { right: -6px; bottom: -6px; cursor: nwse-resize; }

/* --- hop positions ---
   One ghost per corner the text moves through, numbered in playback order. Ghosts sit
   behind the placement box so its resize handles stay grabbable. */

.wm-ghost {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed rgba(255, 255, 255, .22);
  overflow: hidden;
  line-height: 1.15;
  pointer-events: none;
}

.wm-ghost .wm-text { white-space: pre; text-align: center; font-weight: 700; }

/* Element opacity multiplies with the text opacity set from picker.js, so the later
   positions read as previews without misrepresenting how strong the text will be. */
.wm-ghost:not(.first) { opacity: .5; }

.wm-ghost .wm-num {
  position: absolute;
  top: 0;
  left: 0;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 0 0 4px 0;
}

/* While hopping, the box is purely a handle — the ghosts show the real positions. */
.wm-box.hopping { border-style: dotted; border-color: rgba(91, 157, 255, .55); }

/* --- segmented radio group --- */

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }

.seg label {
  flex: 1;
  margin: 0;
  padding: 9px 8px;
  text-align: center;
  font-size: 13.5px;
  color: var(--muted);
  background: var(--panel-2);
  border-right: 1px solid var(--line);
  cursor: pointer;
}

.seg label:last-child { border-right: none; }
.seg label:hover { color: var(--text); }

/* Hidden from view but not from the keyboard: `display: none` would drop the radios out
   of the tab order and out of the arrow-key group, which is how a radio group is meant
   to be operated. */
.seg input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.seg label:has(input:checked) { background: var(--accent-dim); color: #fff; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }

/* --- corner controls --- */

.corner-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  max-width: 320px;
}

.corner-grid button { padding: 6px 8px; font-size: 12.5px; }

/* `display: flex` below would otherwise beat the UA rule for the hidden attribute,
   leaving the placeholder in the layout and doubling the height of the stage. */
.stage-empty[hidden] { display: none; }

.stage-empty {
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  background: var(--panel-2);
  text-align: center;
  padding: 20px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 10px;
  font-variant-numeric: tabular-nums;
}

.meta b { color: var(--text); font-weight: 550; }

/* --- tables --- */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 550; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
td.num { font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); word-break: break-all; }

/* --- status --- */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.badge.pending { background: #33373f; color: var(--muted); }
.badge.running { background: var(--accent-dim); color: #fff; }
.badge.done    { background: rgba(78,201,138,.18); color: var(--ok); }
.badge.failed  { background: rgba(239,107,107,.18); color: var(--err); }

.bar { height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; min-width: 120px; }
.bar > span { display: block; height: 100%; background: var(--accent); transition: width .3s; }

.error-text { color: var(--err); font-size: 12.5px; white-space: pre-wrap; font-family: ui-monospace, Menlo, monospace; }

/* --- detection result --- */

.result { border-left: 3px solid var(--line); padding-left: 16px; }
.result.hit  { border-left-color: var(--ok); }
.result.miss { border-left-color: var(--warn); }

.result h3 { margin: 0 0 6px; font-size: 20px; }
.result .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }

.stat-row { display: flex; flex-wrap: wrap; gap: 22px; margin: 14px 0; }
.stat .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.stat .v { font-size: 19px; font-variant-numeric: tabular-nums; font-weight: 600; }

/* --- notice box --- */

.notice {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  padding: 13px 16px;
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
}

.notice b { color: var(--text); }
.notice ul { margin: 8px 0; padding-left: 20px; }
.notice li { margin: 3px 0; }

/* --- help tooltips --- */

.help-tip {
  position: fixed;
  z-index: 200;
  max-width: 330px;
  background: #2b2f38;
  color: var(--text);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 13px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .5);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .13s, transform .13s;
}

.help-tip.visible { opacity: 1; transform: translateY(0); }
.help-tip b { color: #fff; }
.help-tip code { color: var(--accent); font-size: 12px; }

/* A dotted underline marks a label whose control carries an explanation. */
label[data-has-help] {
  border-bottom: 1px dotted var(--line);
  display: inline-block;
  padding-bottom: 2px;
  margin-bottom: 6px;
  cursor: help;
}

/* --- login --- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 22px;
}

.login-card { width: 100%; max-width: 380px; margin: 0; }
.login-card .hint { margin-bottom: 18px; }

.login-error {
  background: rgba(239, 107, 107, .12);
  border-left: 3px solid var(--err);
  border-radius: 6px;
  padding: 9px 12px;
  margin-bottom: 14px;
  font-size: 13.5px;
}

.logout { margin-left: 14px; }
.logout button { padding: 5px 11px; font-size: 12.5px; }

/* --- toast --- */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--err);
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 14px;
  max-width: 620px;
  white-space: pre-wrap;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}

.toast.ok { border-left-color: var(--ok); }

.spinner {
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -2px;
  margin-right: 7px;
}

@keyframes spin { to { transform: rotate(360deg); } }
