:root {
  --bg: #0c1017;
  --frame: #131923;
  --card: #192230;
  --border: #263346;
  --text: #e6edf3;
  --muted: #8b9bb4;
  --accent: #f0b44c;
  --accent-dim: rgba(240, 180, 76, 0.15);
  --onair: #ef4444;
  --onair-dim: rgba(239, 68, 68, 0.16);
  --safe: #22c55e;
  --safe-dim: rgba(34, 197, 94, 0.14);
  --info: #38bdf8;
  --info-dim: rgba(56, 189, 248, 0.14);
  --dock-h: 118px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  font-size: 14px; line-height: 1.55;
}

button {
  font-family: inherit; cursor: pointer;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 10px; font-size: 12.5px; transition: all .12s ease;
}
button:hover:not(:disabled) { border-color: #4b6180; background: #222e40; }
button:disabled { opacity: 0.42; cursor: not-allowed; }
button.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 800; }
button.primary:hover:not(:disabled) { background: #f6c367; }
button.danger { background: var(--onair); color: #fff; border-color: var(--onair); font-weight: 800; }
button.danger:hover:not(:disabled) { background: #dc2626; }
button.safe { background: var(--safe); color: #052e16; border-color: var(--safe); font-weight: 800; }
button.info { background: var(--info-dim); color: #bae6fd; border-color: rgba(56,189,248,0.45); font-weight: 700; }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { color: var(--text); background: var(--card); }

/* ===== SHELL: LEFT SITEMAP + RIGHT CONTENT + BOTTOM DOCK ===== */
.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) var(--dock-h);
  height: 100vh; width: 100vw;
}

/* LEFT FRAME: SITEMAP + CLOCK */
.left-frame {
  grid-column: 1; grid-row: 1;
  background: var(--frame);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.left-head {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.brand-title { font-size: 13.5px; font-weight: 800; color: var(--accent); }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.proj-open-row { margin-top: 8px; display: flex; gap: 6px; align-items: center; }
.proj-open-row button { flex: 1; font-size: 12px; padding: 6px 8px; }

.sitemap {
  flex: 1; overflow-y: auto; padding: 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.nav-item {
  width: 100%; text-align: left; padding: 7px 9px; border-radius: 7px;
  background: transparent; border: 1px solid transparent;
  display: flex; flex-direction: column; gap: 2px;
}
.nav-item:hover { background: var(--card); border-color: var(--border); }
.nav-item.active {
  background: var(--accent-dim); border-color: var(--accent);
}
.nav-row-top { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; font-weight: 700; }
.nav-item.active .nav-row-top { color: var(--accent); }
.nav-branch { font-size: 10.5px; color: var(--muted); }
.nav-done { color: var(--safe); font-weight: 800; }

.left-foot {
  border-top: 1px solid var(--border); padding: 9px 10px; background: rgba(0,0,0,0.2);
}
.clock-line { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.clock-val { font-size: 21px; font-weight: 900; color: var(--info); font-variant-numeric: tabular-nums; }
.clock-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.clock-btns button { padding: 3px 4px; font-size: 11px; }

/* RIGHT MAIN FRAME: CLASSIC HYPERLINK / DRILL-DOWN PAGE */
.main-frame {
  grid-column: 2; grid-row: 1;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg);
}
.crumb-bar {
  padding: 8px 16px; background: var(--frame);
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 12.5px; flex-wrap: wrap; }
.crumb-link { color: var(--info); cursor: pointer; text-decoration: underline; background: none; border: none; padding: 0; font-size: 12.5px; }
.crumb-sep { color: var(--muted); }
.main-scroll {
  flex: 1; overflow-y: auto; padding: 14px 18px 24px;
  display: flex; flex-direction: column; gap: 12px;
}

/* SKELETON HEADER (ALWAYS VISIBLE INSIDE SCENE) */
.spoiler-bar {
  background: var(--onair-dim); border: 1px solid rgba(239,68,68,0.45);
  border-radius: 7px; padding: 7px 11px; font-size: 12.5px; color: #fecaca;
  display: flex; align-items: flex-start; gap: 8px;
}
.io-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.io-box { background: var(--frame); border: 1px solid var(--border); border-radius: 7px; padding: 8px 11px; font-size: 12.5px; }
.io-lbl { font-size: 10.5px; font-weight: 800; color: var(--muted); margin-bottom: 2px; }

/* LAYER 3 DRILL-DOWN TABS (IN-PLACE SWITCH WITHOUT LOSING SKELETON) */
.drill-tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
  border-bottom: 1px solid var(--border); padding-bottom: 8px;
}
.drill-tab {
  padding: 6px 12px; font-size: 13px; font-weight: 700; border-radius: 7px;
  background: var(--frame); border: 1px solid var(--border); color: var(--muted);
}
.drill-tab.active {
  background: var(--accent-dim); border-color: var(--accent); color: var(--accent);
}

.card {
  background: var(--frame); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px;
}
.card-title {
  font-size: 12px; font-weight: 800; color: var(--muted);
  margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.badge {
  display: inline-flex; align-items: center; font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
}
.badge-danger { background: var(--onair-dim); color: #fca5a5; border: 1px solid rgba(239,68,68,0.4); }
.badge-accent { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(240,180,76,0.35); }
.badge-safe { background: var(--safe-dim); color: #86efac; border: 1px solid rgba(34,197,94,0.35); }
.badge-info { background: var(--info-dim); color: #7dd3fc; border: 1px solid rgba(56,189,248,0.35); }
.badge-muted { background: #1e293b; color: var(--muted); border: 1px solid var(--border); }

/* TOP FLOWCHART OVERVIEW PAGE */
.flow-map { display: flex; flex-direction: column; gap: 8px; }
.flow-card {
  background: var(--frame); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  cursor: pointer; transition: border-color .12s ease;
}
.flow-card:hover { border-color: var(--accent); }
.flow-card.done { border-left: 4px solid var(--safe); }

/* SCRIPT & Q&A BLOCKS */
.script-block {
  background: var(--card); border-left: 3px solid var(--accent);
  border-radius: 6px; padding: 10px 12px; margin-bottom: 8px;
}
.script-speaker { font-size: 12px; font-weight: 800; color: var(--accent); margin-bottom: 5px; }
.script-line { margin: 4px 0; font-size: 13.5px; color: #f1f5f9; }
.qa-search {
  width: 100%; padding: 7px 10px; border-radius: 7px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  font-size: 13px; margin-bottom: 10px;
}
.qa-item {
  border-bottom: 1px solid var(--border); padding: 8px 0;
}
.qa-item:last-child { border-bottom: none; }
.qa-q { font-weight: 800; color: #bae6fd; font-size: 13px; margin-bottom: 3px; }
.qa-a { font-size: 13px; color: var(--text); }

/* LIVE TOOLS (D100 / WOLF / LAKE / WHALE / REWARDS) */
.seg-tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg-tabs button { border: none; border-radius: 0; border-right: 1px solid var(--border); padding: 5px 9px; font-size: 12px; }
.seg-tabs button:last-child { border-right: none; }
.seg-tabs button.active { background: var(--accent); color: #111; font-weight: 800; }

.d100-input {
  width: 82px; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 15px; font-weight: 800; text-align: center;
}
.d100-result { background: var(--card); border: 1px solid var(--accent); border-radius: 8px; padding: 10px 12px; margin-top: 8px; }
.d100-list { max-height: 220px; overflow-y: auto; margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }
.d100-row { display: flex; gap: 8px; align-items: baseline; padding: 4px 8px; border-radius: 5px; font-size: 12px; cursor: pointer; }
.d100-row:hover { background: var(--card); }
.d100-row.hit { background: var(--accent-dim); border: 1px solid var(--accent); }

.hp-bar-outer { height: 24px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; position: relative; margin: 8px 0; }
.hp-bar-inner { height: 100%; background: linear-gradient(90deg, #ef4444, #f59e0b); transition: width .18s ease; }
.hp-bar-mid { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,0.55); }
.hp-bar-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; text-shadow: 0 1px 2px #000; }
.alert-box { margin-top: 8px; padding: 9px 11px; border-radius: 7px; font-size: 12.5px; border: 1px solid var(--accent); background: var(--accent-dim); color: #fde68a; }
.alert-box.flee { border-color: var(--safe); background: var(--safe-dim); color: #bbf7d0; }

.timer-box { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
.timer-num { font-size: 36px; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--accent); line-height: 1; }
.timer-num.done { color: var(--safe); }
.scr-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 8px; }
.scr-card { text-align: left; padding: 8px 10px; border-radius: 7px; background: var(--card); border: 1px solid var(--border); }
.scr-card.selected { border-color: var(--info); background: var(--info-dim); }
.table-mini { width: 100%; border-collapse: collapse; font-size: 12px; }
.table-mini th, .table-mini td { border-bottom: 1px solid var(--border); padding: 4px 6px; text-align: left; }
.table-mini th { color: var(--muted); font-size: 11px; }

.check-item { display: flex; align-items: flex-start; gap: 8px; padding: 5px 8px; border-radius: 6px; background: var(--card); margin-bottom: 5px; cursor: pointer; font-size: 13px; }
.check-item.checked { opacity: 0.6; text-decoration: line-through; }
.reward-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }

/* ===== BOTTOM DOCK: PROJECTOR SWITCHER + AUTO-SYNCED BGM ===== */
.bottom-dock {
  grid-column: 1 / -1; grid-row: 2;
  background: #0f141d; border-top: 2px solid var(--border);
  padding: 8px 12px;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 235px;
  gap: 12px; align-items: center;
}

.dock-onair {
  display: flex; gap: 9px; align-items: center; height: 100%;
}
.onair-mini {
  width: 142px; height: 80px; background: #000;
  border: 2px solid var(--onair); border-radius: 6px;
  position: relative; overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.onair-mini.blackout { border-color: #475569; }
.onair-mini img { width: 100%; height: 100%; object-fit: cover; }
.onair-mini-tag {
  position: absolute; top: 3px; left: 3px;
  background: var(--onair); color: #fff; font-size: 9px; font-weight: 800;
  padding: 1px 4px; border-radius: 3px;
}
.onair-mini.blackout .onair-mini-tag { background: #334155; color: #cbd5e1; }
.onair-mini-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.75); font-size: 10px; padding: 2px 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dock-onair-btns { display: flex; flex-direction: column; gap: 5px; flex: 1; }
.dock-onair-btns button { width: 100%; padding: 6px 8px; font-size: 12px; }

.dock-strip-wrap {
  display: flex; flex-direction: column; gap: 5px; overflow: hidden; height: 100%; justify-content: center;
}
.dock-strip-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; color: var(--muted);
}
.dock-strip {
  display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; align-items: center;
}
.strip-card {
  display: flex; align-items: center; gap: 7px;
  background: var(--card); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px 4px 4px; flex-shrink: 0; text-align: left; max-width: 195px;
}
.strip-card.live { border-color: var(--onair); box-shadow: 0 0 0 1px var(--onair) inset; }
.strip-thumb {
  width: 68px; height: 38px; border-radius: 4px; background: #070a0f;
  overflow: hidden; flex-shrink: 0; position: relative;
  display: flex; align-items: center; justify-content: center; font-size: 10px; color: var(--muted);
}
.strip-thumb img { width: 100%; height: 100%; object-fit: cover; }
.strip-key {
  position: absolute; top: 2px; left: 2px;
  background: rgba(0,0,0,0.8); color: var(--accent); font-size: 9px; font-weight: 800; padding: 0 4px; border-radius: 3px;
}
.strip-title { font-size: 11.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.strip-sub { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }

.op-remote {
  display: inline-flex; gap: 4px; align-items: center;
  background: rgba(240,180,76,0.12); border: 1px solid rgba(240,180,76,0.4);
  border-radius: 6px; padding: 2px 6px;
}
.op-remote button { padding: 2px 6px; font-size: 11px; }

/* RIGHT BGM AUTO-SYNC BOX */
.dock-bgm {
  border-left: 1px solid var(--border); padding-left: 10px;
  display: flex; flex-direction: column; gap: 5px; justify-content: center;
}
.bgm-title { font-size: 11px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--info); }
.bgm-row { display: flex; align-items: center; gap: 5px; }
.bgm-row input[type="range"] { flex: 1; accent-color: var(--info); }
.bgm-row button { padding: 3px 7px; font-size: 11px; }
.bgm-row button.on { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 800; }

.toast {
  position: fixed; top: 12px; right: 16px; z-index: 99;
  background: #1e293b; color: #f8fafc; border: 1px solid var(--accent);
  padding: 7px 13px; border-radius: 8px; font-size: 12px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.toast.show { opacity: 1; }
