:root {
  color-scheme: light dark;
  --bg: #f4f3f0; --surface: #ffffff; --surface-2: #f8f7f5; --border: rgba(20, 20, 18, .11); --border-strong: rgba(20, 20, 18, .22);
  --text: #1c1b19; --muted: #67655f; --faint: #8f8c85;
  --accent: #5b45e0; --accent-bg: #eeebfd; --accent-text: #3d2bb0; --on-accent: #ffffff;
  --ok: #1f7a3f; --ok-bg: #e5f3e9; --warn: #93560b; --warn-bg: #fbf0dc; --bad: #b42323; --bad-bg: #fbe6e6;
  --radius: 8px; --card: 12px; --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614; --surface: #1f1f1c; --surface-2: #262623; --border: rgba(255, 255, 250, .1); --border-strong: rgba(255, 255, 250, .2);
    --text: #ecebe6; --muted: #a8a59d; --faint: #7d7a73;
    --accent: #8f7cff; --accent-bg: #2a2550; --accent-text: #c9beff; --on-accent: #15122b;
    --ok: #6cc98a; --ok-bg: #1b3324; --warn: #e6b062; --warn-bg: #3a2c15; --bad: #f08a8a; --bad-bg: #3d1d1d;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hint { color: var(--muted); font-size: 12.5px; }
.bad { color: var(--bad); }
.spacer { flex: 1; }
.empty { color: var(--faint); padding: 12px 0; }
.ic { display: inline-flex; width: 16px; height: 16px; flex: none; }
.ic svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

button, .button {
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 6px 11px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; text-decoration: none; min-height: 32px;
}
button:hover:not(:disabled), .button:hover { background: var(--surface-2); }
button:active:not(:disabled) { transform: scale(.98); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, .button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
button.small { padding: 3px 9px; min-height: 28px; font-size: 12.5px; }
button.link { border: 0; background: none; color: var(--muted); padding: 2px 6px; min-height: 0; text-decoration: underline; }
button.icon-btn { padding: 2px; min-height: 26px; width: 26px; border-color: var(--border); }
.warn-btn { width: 100%; color: var(--warn); border-color: var(--warn); background: var(--warn-bg); }
input[type=number], input[type=password], select {
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 5px 8px; min-height: 32px;
}
input[type=number] { width: 72px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; flex: none; }
input[type=number]:invalid { border-color: var(--bad); }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand img { width: 24px; height: 24px; }
.device-pick select { max-width: 220px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.chip .ic { width: 13px; height: 13px; }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.chip.accent { background: var(--accent-bg); color: var(--accent-text); border-color: transparent; }
.chip.muted { color: var(--faint); }
.reset { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }

.notice { margin: 12px 20px 0; padding: 9px 14px; border-radius: var(--radius); background: var(--accent-bg); color: var(--accent-text); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.notice.error { background: var(--bad-bg); color: var(--bad); }
/* Other devices card */
.home-body { display: grid; gap: 8px; }
.home-links { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.home-links li { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
code.addr, .access-code { font-family: var(--mono); user-select: all; overflow-wrap: anywhere; }
code.addr { font-size: 12.5px; }
code.sign-link { flex-basis: 100%; padding: 4px 6px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.home-sub { font-weight: 600; font-size: 12.5px; margin-top: 4px; }
.home-code { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.access-code { font-size: 15px; font-weight: 600; letter-spacing: .04em; }
.own-code { display: flex; gap: 6px; }
.own-input { flex: 1; min-width: 0; font: inherit; font-family: var(--mono); font-size: 13px; text-transform: uppercase; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 4px 8px; min-height: 28px; }
.home-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.warn-text { color: var(--warn); }
/* Sign-in page for other devices (login.html) */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 400px; display: grid; gap: 12px; }
.login form { display: grid; gap: 8px; }
.login label { font-weight: 600; }
.login input { font: inherit; font-family: var(--mono); font-size: 16px; letter-spacing: .04em; text-transform: uppercase; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 8px 10px; min-height: 40px; }
.login button { min-height: 40px; }
.login-error { color: var(--bad); }
.login-error:empty { display: none; }
.confirm-bar { margin-top: 10px; padding: 9px 12px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.confirm-text { flex: 1; min-width: 180px; font-weight: 600; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice > span { flex: 1; min-width: 200px; }

/* layout */
.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; padding: 16px 20px 40px; max-width: 1500px; margin: 0 auto; align-items: start; }
/* Sticky, but scrolls on its own once its cards are taller than the window (padding keeps focus rings visible). */
.side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow-y: auto; overscroll-behavior: contain; padding: 3px; margin: -3px; }
.content { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--card); padding: 14px 16px; min-width: 0; }

/* phone panel */
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.btn-grid button { justify-content: flex-start; }
.pin-form { margin-top: 12px; }
.pin-form label { font-size: 12px; color: var(--muted); }
.pin-row { display: flex; gap: 6px; margin: 4px 0; }
.pin-row input { flex: 1; min-width: 0; }
.result { margin-top: 8px; font-size: 12.5px; color: var(--muted); min-height: 1em; }
.result.bad { color: var(--bad); }
.app-rows { display: flex; flex-direction: column; gap: 8px; }
.app-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.app-name { display: flex; flex-direction: column; line-height: 1.25; }
.app-state { color: var(--accent-text); }
.app-btns { display: flex; gap: 4px; }
.shot-card img { width: 100%; border-radius: 8px; border: 1px solid var(--border); display: block; }

/* run bar */
.run-card { display: flex; flex-direction: column; gap: 10px; }
.run-row { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-height: 32px; }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button[aria-checked=true] { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.presets { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
#run { min-width: 170px; }

/* session */
.session-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.session-head h2 { font-size: 18px; margin: 2px 0 2px; }
.overline { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.dot.run { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); animation: pulse 1.6s infinite; }
.dot.wait { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px transparent; } }
@media (prefers-reduced-motion: reduce) { .dot.run { animation: none; } }
.session-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.elapsed { font-family: var(--mono); font-size: 20px; font-variant-numeric: tabular-nums; }
.session-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.wait-banner { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.wait-text { font-weight: 600; flex: 1; min-width: 200px; }
.jobs, .run-jobs { list-style: none; margin: 12px 0 0; padding: 0; }
.jobs:empty { display: none; }
.job { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.job > .ic { margin-top: 2px; color: var(--faint); }
.job.running > .ic { color: var(--ok); }
.job.finished > .ic { color: var(--ok); }
.job.attention > .ic { color: var(--warn); }
.job.failed > .ic { color: var(--bad); }
.job.running { background: linear-gradient(90deg, var(--ok-bg), transparent 60%); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.job-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.job-text .hint { overflow-wrap: anywhere; }
.job-name { font-weight: 500; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.job.skipped .job-name, .job.stopped .job-name { color: var(--muted); }
.job-side { display: flex; align-items: center; gap: 8px; flex: none; }
.job-edit { display: inline-flex; gap: 3px; }

/* task groups */
.groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.group-note { margin: -4px 0 8px; }
.items { display: flex; flex-direction: column; }
.item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 9px 0; border-top: 1px solid var(--border); }
.item-main { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.item-main input { margin-top: 3px; }
.item-text { display: flex; flex-direction: column; min-width: 0; }
.item-name { font-weight: 500; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.target { font-size: 11px; font-weight: 500; padding: 0 6px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.item-side { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.item-state { font-size: 12px; font-weight: 600; color: var(--muted); }
.item-state.running { color: var(--ok); }
.item-state.finished { color: var(--ok); }
.item-state.attention { color: var(--warn); }
.item-state.failed { color: var(--bad); }
.sched { font-size: 12px; color: var(--accent-text); }
.sched.ok { color: var(--ok); font-weight: 600; }
.sched.soon { color: var(--warn); font-weight: 600; }
.wait-count { font-variant-numeric: tabular-nums; font-weight: 600; }
.pre { grid-column: 1 / -1; display: flex; gap: 6px; align-items: flex-start; font-size: 12px; color: var(--warn); margin-left: 26px; }
.pre .ic { width: 14px; height: 14px; margin-top: 2px; }
.opts { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 0 26px; }
.opt { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.opt[hidden] { display: none; }
.opt input.wide { width: 116px; font-variant-numeric: tabular-nums; }
.group-experimental { border-style: dashed; }

/* now running */
.now { margin-top: 12px; padding: 12px 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.now-step { font-size: 16px; font-weight: 600; }
.bar { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .6s ease; }
.bar.thin { height: 5px; }
@media (prefers-reduced-motion: reduce) { .bar i { transition: none; } }
.now-tasks { display: flex; flex-wrap: wrap; gap: 6px; }
.ad-box { padding: 10px 12px; border-radius: var(--radius); background: var(--accent-bg); color: var(--accent-text); display: flex; flex-direction: column; gap: 6px; }
.ad-box .hint { color: inherit; opacity: .9; }
.ad-box.closing { background: var(--warn-bg); color: var(--warn); }
.ad-box.closing .bar i { background: var(--warn); }
.ad-top { display: flex; align-items: center; gap: 8px; }
.ad-secs { margin-left: auto; font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.today { font-size: 11.5px; font-weight: 600; color: var(--accent-text); }
.today.all { color: var(--ok); }

/* readable feed */
.tabs button { min-height: 28px; padding: 2px 10px; font-size: 12.5px; }
.tabs button[aria-selected=true] { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.feed { height: 420px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; background: var(--surface); }
.fhead { position: sticky; top: -6px; background: var(--surface); font-size: 12px; font-weight: 700; color: var(--muted); padding: 8px 0 4px; border-bottom: 1px solid var(--border); margin-bottom: 2px; z-index: 1; }
.fl { display: grid; grid-template-columns: 76px 18px minmax(0, 1fr); gap: 6px; align-items: start; padding: 3px 0; font-size: 13.5px; }
.fl .time { color: var(--faint); font: 12px/1.6 var(--mono); }
.fl .ic { margin-top: 2px; color: var(--faint); }
.fl .msg { overflow-wrap: anywhere; }
.fl.k-step .msg { font-weight: 600; }
.fl.k-reward .ic, .fl.k-done .ic { color: var(--ok); }
.fl.k-reward .msg { color: var(--ok); font-weight: 600; }
.fl.k-ad .ic, .fl.k-ad-end .ic { color: var(--accent); }
.fl.k-queue .msg, .fl.k-phone .msg { color: var(--muted); }
.fl.warn .ic, .fl.warn .msg { color: var(--warn); }
.fl.error .ic, .fl.error .msg { color: var(--bad); }
.feed.ads-only .fl:not(.k-ad):not(.k-ad-end):not(.k-reward) { display: none; }

/* log */
.log-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.log-head h2 { margin: 0; display: flex; align-items: center; gap: 8px; }
.live { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--faint); }
.live.on { background: var(--ok-bg); color: var(--ok); }
.log { height: 380px; overflow: auto; font: 12px/1.55 var(--mono); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; }
.line { display: grid; grid-template-columns: 76px 110px minmax(0, 1fr); gap: 8px; }
.line .time { color: var(--faint); }
.line .src { color: var(--accent-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line .msg { white-space: pre-wrap; overflow-wrap: anywhere; }
.line.warn .msg { color: var(--warn); }
.line.error .msg { color: var(--bad); }

/* history */
.history { display: flex; flex-direction: column; }
.run { border-top: 1px solid var(--border); padding: 8px 0; }
.run summary { display: flex; align-items: center; gap: 10px; cursor: pointer; flex-wrap: wrap; }
.run .run-jobs { margin: 6px 0 0 4px; }
.run .run-jobs .job { padding: 4px 0; border: 0; font-size: 13px; }
.pill { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.finished { background: var(--ok-bg); color: var(--ok); }
.pill.attention, .pill.stopped { background: var(--warn-bg); color: var(--warn); }
.pill.failed { background: var(--bad-bg); color: var(--bad); }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 32px; }
  .side { position: static; }
  .topbar { padding: 10px 16px; position: static; }
  .chips { order: 3; flex: 1 1 100%; }
  .reset { order: 4; }
  .notice { margin: 12px 16px 0; }
  .groups { grid-template-columns: minmax(0, 1fr); }
  .line { grid-template-columns: 64px minmax(0, 1fr); }
  .fl { grid-template-columns: 62px 16px minmax(0, 1fr); font-size: 13px; }
  .line .src { display: none; }
}
