/* RO 助手控制台。深色為主：這個頁面會長時間開著看畫面。
   版面由窄到寬：手機直立一欄（畫面 → 控制 → 分頁），平板兩欄，桌面三欄。 */

:root {
  --bg: #14171c;
  --panel: #1b1f26;
  --panel-2: #222833;
  --field: #11141a;
  --line: #2e3541;
  --text: #dfe4ea;
  --muted: #8d97a6;
  --accent: #4f9dfd;
  --accent-bg: #1a2638;
  --ok: #45c17c;
  --warn: #e2b33c;
  --danger: #e2564a;
  --watch: #ff9f40;
  --radius: 8px;
}

* { box-sizing: border-box; }

/* The page toggles screens with the hidden attribute (login, app, dev login, tabs).
   A class that sets display - .login is flex, .dev-login is grid - beats the
   browser's own [hidden] rule, and the login card stayed on top after signing in. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #0b1016; font-weight: 600; }
button.warn { border-color: var(--warn); color: var(--warn); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.small { padding: 2px 8px; font-size: 12px; }
button.big { padding: 12px 18px; font-size: 16px; }
button.wide { width: 100%; }
button.icon { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; flex: none; }

input[type=email], input[type=text], input[type=number], textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 9px;
  width: 100%;
}
textarea { font: 12px/1.5 ui-monospace, Consolas, monospace; min-height: 80px; resize: vertical; }
select.compact { width: auto; max-width: 100%; margin-bottom: 8px; padding: 4px 8px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); }
.spacer { flex: 1; }

/* ── 登入 ─────────────────────────────────────────── */
.login {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 30%, #1d2430, #0d1013);
  z-index: 50;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px;
  width: min(420px, 92vw);
  text-align: center;
}
.login-card h1 { margin: 0 0 8px; }
.dev-login { margin-top: 20px; display: grid; gap: 8px; text-align: left; }
.dev-login label { color: var(--muted); font-size: 12px; }

/* ── 版面 ─────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; letter-spacing: .5px; }
.message {
  padding: 3px 14px; min-height: 1.9em; font-size: 13px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 380px;
  grid-template-areas: "control stage side";
  gap: 12px;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.stage { grid-area: stage; }
.panel.control { grid-area: control; }
.panel.side { grid-area: side; }

/* Desktop: the page fits the window and each panel scrolls on its own. */
@media (min-width: 1200px) {
  #app { height: 100vh; height: 100dvh; }
  .layout { flex: 1; min-height: 0; }
  .panel { overflow-y: auto; }
  .panel.side { display: flex; flex-direction: column; overflow: hidden; }
  .panel.side .tab-body { flex: 1; min-height: 0; overflow-y: auto; }
}
@media (max-width: 1199px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "stage stage" "control side";
  }
}
/* Phone upright: one column, the game screen first. */
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "control" "side"; gap: 8px; padding: 8px; }
  .topbar { padding-left: 10px; padding-right: 10px; gap: 8px; }
  .topbar .email { display: none; }
  .message { padding: 3px 10px; }
  .stage-foot { gap: 8px; }
  .legend { font-size: 11px; }
  /* 16px keeps iOS from zooming into a field on focus. */
  input[type=email], input[type=text], input[type=number], textarea, select { font-size: 16px; }
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tab { flex: 0 0 auto; padding: 8px 12px; }
  .trace-list { max-height: 70vh; overflow-y: auto; }
}
@media (pointer: coarse) {
  button { min-height: 44px; }
  button.small { min-height: 34px; padding: 4px 10px; }
  button.icon { width: 40px; height: 40px; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 0;
}
.panel section { margin-bottom: 20px; }
.panel section:last-child { margin-bottom: 0; }
.panel h2 {
  font-size: 13px; letter-spacing: .08em;
  color: var(--muted); margin: 0 0 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.panel h2 .hint { font-size: 11px; letter-spacing: 0; font-weight: 400; }

.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.button-grid .wide { grid-column: 1 / -1; }

/* ── 徽章 ─────────────────────────────────────────── */
.badge {
  padding: 2px 9px; border-radius: 999px; font-size: 12px; white-space: nowrap;
  border: 1px solid var(--line); background: var(--panel-2);
}
.badge.idle { color: var(--muted); }
.badge.running { color: var(--ok); border-color: var(--ok); }
.badge.paused { color: var(--warn); border-color: var(--warn); }
.badge.stopping, .badge.off { color: var(--danger); border-color: var(--danger); }
.badge.blocked { color: #fff; background: var(--danger); border-color: var(--danger); font-weight: 600; }

/* 任務因失敗而暫停：紅色橫幅寫出原因 */
.blocked {
  margin: 0 16px 10px; padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid var(--danger); border-left: 5px solid var(--danger);
  background: var(--panel-2);
}
.blocked strong { color: var(--danger); font-size: 15px; }
.blocked p { margin: 6px 0 0; }
.blocked .blocked-reason { color: var(--danger); font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.badge.dim { color: var(--muted); }

.tag {
  font-size: 11px; padding: 1px 6px; border-radius: 4px; white-space: nowrap;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.tag.guess { color: var(--warn); border-color: var(--warn); }
.tag.bad { color: var(--danger); border-color: var(--danger); }

/* ── 模擬器 ───────────────────────────────────────── */
.emulator-info { margin-top: 6px; }
.emulator-info .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.emulator-info p { margin: 4px 0 0; }

/* ── 任務 ─────────────────────────────────────────── */
.task-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.task {
  width: 100%; display: flex; align-items: center; gap: 10px;
  text-align: left; padding: 9px 12px;
}
.task .order {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  border: 2px solid var(--line);
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums;
}
.task[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-bg); }
.task[aria-pressed="true"] .order { background: var(--accent); border-color: var(--accent); color: #0b1016; }
.task .note { margin-left: auto; font-size: 11px; color: var(--muted); }
.task.running { border-color: var(--ok); }
.task.running .note { color: var(--ok); }
.queue-state { margin: 0 0 8px; font-size: 13px; color: var(--ok); }

/* ── 畫面 ─────────────────────────────────────────── */
.stage { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.frame-wrap {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  max-width: 100%;
}
#frame, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#frame { object-fit: contain; }
.frame-empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--muted); padding: 12px; text-align: center;
}
.stage-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.legend { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 5px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw.match { background: #3ddc84; }
.sw.miss { background: #ff5a4e; }
.sw.watch { background: #ff9f40; }
.sw.tap { background: transparent; border: 2px solid #ff5a4e; border-radius: 50%; }
.sw.swipe { background: #ffd24a; }

/* ── 分頁 ─────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tab { flex: 1; padding: 6px 4px; font-size: 13px; background: transparent; white-space: nowrap; }
.tab.active { background: var(--panel-2); border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.trace-list, .incident-list, .recipe-list, .user-list { list-style: none; margin: 0; padding: 0; }

/* ── 感知日誌 ─────────────────────────────────────── */
.trace-list li {
  border-left: 3px solid var(--ok);
  background: var(--panel-2);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 5px 9px; margin-bottom: 5px;
  font-size: 13px;
}
.trace-list li.fail { border-left-color: var(--danger); }
.trace-list li.watch { border-left-color: var(--watch); opacity: .8; }
.trace-list li.incident { border-left: 5px solid var(--danger); background: var(--panel); }
.trace-list .head { display: flex; gap: 8px; align-items: baseline; }
.trace-list .verdict { font-weight: 700; flex: none; }
.trace-list .pass .verdict { color: var(--ok); }
.trace-list .fail .verdict { color: var(--danger); }
.trace-list .watch .verdict { color: var(--watch); }
.trace-list .incident .verdict, .trace-list .incident .title { color: var(--danger); font-weight: 700; }
.trace-list .title { min-width: 0; }
.trace-list .method { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.trace-list .facts { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

/* ── 異常、配方、白名單 ───────────────────────────── */
.incident-list li {
  border: 1px solid var(--line); border-left: 3px solid var(--warn);
  border-radius: var(--radius); padding: 8px; margin-bottom: 8px;
}
.incident-list li.resolved { opacity: .5; border-left-color: var(--ok); }
.incident-list .desc { margin: 0; }
.incident-list .actions { display: flex; gap: 6px; margin-top: 6px; }
.incident-list .shot img { display: block; max-width: 100%; margin-top: 6px; border-radius: 4px; }

.recipe-list li {
  border: 1px solid var(--line); border-left: 3px solid var(--warn);
  border-radius: var(--radius); padding: 8px; margin-bottom: 8px;
}
.recipe-list li.approved { border-left-color: var(--ok); opacity: .7; }
.recipe-list li.rejected { border-left-color: var(--danger); opacity: .5; }
.recipe-list .row { display: flex; flex-wrap: wrap; gap: 6px; }
.recipe-list .kind { font-weight: 600; }
.recipe-list .yaml {
  margin: 6px 0 0; padding: 6px 8px; max-height: 240px; overflow: auto;
  background: var(--panel-2); border-radius: 4px;
  font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-all;
}
.recipe-list .actions { display: flex; gap: 6px; margin-top: 6px; }

.user-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}
.user-list .email { flex: 1; overflow-wrap: anywhere; }
.add-user { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.add-user input { flex: 1 1 200px; }

/* ── 設定 ─────────────────────────────────────────── */
.config-group {
  margin-bottom: 12px; padding: 10px;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.config-group h3 { font-size: 14px; margin: 0 0 8px; }
.config-row { margin-bottom: 12px; }
.config-row:last-child { margin-bottom: 0; }
.config-row > label, .config-row > .label { display: block; font-size: 13px; margin-bottom: 4px; }
.config-row .help { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.config-row.toggle > label { display: flex; align-items: center; gap: 8px; }

details.advanced { margin: 4px 0 12px; }
details.advanced > summary,
details.fold > summary {
  cursor: pointer; padding: 8px 10px; list-style-position: inside;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
}
details.advanced[open] > summary { margin-bottom: 8px; }
details.fold > summary { font-size: 13px; }
details.fold[open] > summary { margin-bottom: 6px; }

/* Floats over the fields while the settings scroll, so it is drawn as a bar of its own. */
.save-bar {
  position: sticky; bottom: 0; z-index: 1;
  margin: 0 -12px -12px; padding: 8px 12px 10px;
  background: var(--panel); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 12px rgba(0, 0, 0, .35);
}
.save-bar p { margin: 4px 0 0; min-height: 1.4em; }

/* List editor: one row per entry, reorder with the arrows. */
.list-items, .mvp-list { list-style: none; margin: 0; padding: 0; }
.list-items li, .mvp-list li {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 0; border-bottom: 1px solid var(--line);
}
.list-items .rank, .mvp-list .rank {
  width: 22px; flex: none; text-align: right;
  color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums;
}
.list-items input[type=text] { padding: 4px 8px; }
.list-add { display: flex; gap: 6px; margin-top: 6px; }
.list-add input { flex: 1; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.segmented button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-bg); font-weight: 600; }
.mvp-tools { display: flex; gap: 6px; margin: 6px 0; }
.mvp-list label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.mvp-list li.skipped .name { color: var(--muted); text-decoration: line-through; }

/* Run plan: one card per entry - which dungeon, how hard, how many times. */
.plan-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.plan-row {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 8px; background: var(--panel-2);
}
.plan-top, .plan-bottom { display: flex; align-items: center; gap: 6px; }
.plan-bottom { margin-top: 6px; }
.plan-top select { flex: 1; min-width: 0; }
.plan-row select.plan-level { width: auto; }
.plan-row .rank {
  width: 22px; flex: none; text-align: right;
  color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums;
}
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper .count { min-width: 3.2em; text-align: center; font-variant-numeric: tabular-nums; }
.plan-total { margin: 6px 0; }
.plan-actions { display: flex; flex-wrap: wrap; gap: 6px; }
