:root {
  --bg: #0b0f14;
  --bg2: #121821;
  --card: #161d27;
  --card2: #1d2634;
  --line: #263143;
  --fg: #e8eef6;
  --fg2: #93a4b8;
  --fg3: #64748b;
  --accent: #3b9dff;
  --accent2: #1f6fd0;
  --ok: #22c55e;
  --warn: #f59e0b;
  --ng: #ef4444;
  --radius: 12px;
  --tabbar: 62px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg); color: var(--fg);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, -apple-system, sans-serif;
  font-size: 15px; line-height: 1.6;
  overscroll-behavior-y: none;
}
body { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom, 0px)); }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); }

/* ---------- ヘッダー ---------- */
header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: rgba(11,15,20,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 16px; font-weight: 700; letter-spacing: .02em; flex: 1; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--fg3); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px rgba(34,197,94,.7); }
.dot.off { background: var(--ng); }
#connLabel { font-size: 12px; color: var(--fg2); }

main { padding: 14px 14px 24px; max-width: 1200px; margin: 0 auto; }
section.tab { display: none; }
section.tab.active { display: block; }

h2.sec { font-size: 13px; color: var(--fg2); font-weight: 700; letter-spacing: .08em; margin: 20px 0 10px; }
h2.sec:first-child { margin-top: 4px; }

/* ---------- 汎用パーツ ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--fg2); font-size: 13px; }
.tiny { font-size: 12px; color: var(--fg3); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--card2); border: 1px solid var(--line); color: var(--fg);
  border-radius: 9px; padding: 9px 13px; font-size: 14px; font-weight: 600;
  transition: background .12s, border-color .12s; white-space: nowrap;
}
.btn:hover { background: #26324a; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121f; }
.btn.primary:hover { background: #59aeff; }
.btn.danger { color: #ffb4b4; border-color: #4a2530; background: #2a1820; }
.btn.danger:hover { background: #3a1f28; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 8px 10px; min-width: 40px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

input[type=text], input[type=password], input[type=number], input[type=time], input[type=date], input[type=search], select, textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 84px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12.5px; color: var(--fg2); margin-bottom: 5px; }

.badge {
  display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; border: 1px solid var(--line); color: var(--fg2); background: var(--bg2);
}
.badge.auto { color: #7dd3fc; border-color: #1e4a63; background: #0d2432; }
.badge.manual { color: #fbbf24; border-color: #59431a; background: #2b220e; }
.badge.live { color: #86efac; border-color: #1e5233; background: #0e2a1a; }
.badge.yt { color: #ff8b8b; border-color: #5a2626; background: #2b1414; }
.badge.file { color: #a5b4fc; border-color: #33366b; background: #16182e; }
.badge.off { color: #94a3b8; }

.switch { position: relative; width: 44px; height: 25px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; background: #2b374a; border-radius: 999px;
  transition: background .16s; pointer-events: none;
}
.switch span::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px;
  background: #94a3b8; border-radius: 50%; transition: transform .16s, background .16s;
}
.switch input:checked + span { background: #1b4e7d; }
.switch input:checked + span::after { transform: translateX(19px); background: var(--accent); }

/* ---------- 画面カード ---------- */
.screen-card .head { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.screen-card .head .name { font-weight: 700; font-size: 16px; }
.now {
  display: flex; gap: 11px; align-items: center;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; margin-bottom: 11px;
}
.now img { width: 84px; height: 47px; object-fit: cover; border-radius: 6px; background: #000; flex: none; }
.now .ph { width: 84px; height: 47px; border-radius: 6px; background: #0a0e14; border: 1px dashed var(--line); flex: none; }
.now .info { min-width: 0; flex: 1; }
.now .t1 { font-weight: 600; font-size: 14px; }
.now .t2 { font-size: 12.5px; color: var(--fg2); }
.controls { display: flex; gap: 7px; flex-wrap: wrap; }
.url-line {
  display: flex; gap: 7px; align-items: center; margin-top: 11px;
  background: #0a0e14; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
}
.url-line .u { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #7dd3fc; }

/* ---------- 動画グリッド ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 11px; }
.vcard {
  background: var(--card); border: 1px solid var(--line); border-radius: 11px;
  overflow: hidden; display: flex; flex-direction: column;
}
.vcard.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.vthumb { position: relative; aspect-ratio: 16/9; background: #05080c; }
.vthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vthumb .noimg { display: flex; width: 100%; height: 100%; align-items: center; justify-content: center; color: var(--fg3); font-size: 26px; }
.vthumb .dur {
  position: absolute; right: 5px; bottom: 5px; background: rgba(0,0,0,.8);
  border-radius: 4px; padding: 1px 5px; font-size: 11px; color: #fff;
}
.vbody { padding: 8px 9px 9px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.vtitle { font-size: 13px; font-weight: 600; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.vactions { display: flex; gap: 5px; margin-top: auto; }
.vactions .btn { flex: 1; padding: 6px 4px; font-size: 12px; }

/* ---------- 一覧行 ---------- */
.item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 9px;
}
.item .grow { flex: 1; min-width: 0; }
.item .t1 { font-weight: 600; font-size: 14.5px; }
.item .t2 { font-size: 12.5px; color: var(--fg2); }
.item.disabled { opacity: .5; }

.pl-item {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 9px; padding: 7px 9px; margin-bottom: 7px;
}
.pl-item img { width: 62px; height: 35px; object-fit: cover; border-radius: 5px; background: #000; flex: none; }
.pl-item .n { flex: 1; min-width: 0; font-size: 13.5px; }

/* ---------- タブバー ---------- */
nav.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; background: rgba(13,18,25,.97); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
nav.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 2px 8px; color: var(--fg3); font-size: 11px; font-weight: 600;
}
nav.tabbar button .ic { font-size: 19px; line-height: 1; }
nav.tabbar button.active { color: var(--accent); }

/* ---------- モーダル ---------- */
#modalWrap {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: flex-end; justify-content: center; background: rgba(0,0,0,.65);
}
#modalWrap.on { display: flex; }
.modal {
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 16px 16px 0 0; width: 100%; max-width: 620px;
  max-height: 92vh; display: flex; flex-direction: column;
  animation: up .18s ease;
}
@keyframes up { from { transform: translateY(24px); opacity: .4 } }
.modal .mh {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal .mh h3 { font-size: 15.5px; flex: 1; }
.modal .mb { padding: 16px; overflow-y: auto; flex: 1; }
.modal .mf { padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); display: flex; gap: 9px; }
.modal .mf .btn { flex: 1; }

@media (min-width: 640px) {
  #modalWrap { align-items: center; }
  .modal { border-radius: 16px; }
}

/* ---------- トースト ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar) + 18px); z-index: 80;
  background: #22303f; border: 1px solid var(--line); color: var(--fg);
  padding: 11px 18px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: 90vw; text-align: center;
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(-6px); }
#toast.err { background: #3b1e22; border-color: #6b2b31; color: #ffd0d0; }

/* ---------- ログイン ---------- */
#login {
  position: fixed; inset: 0; z-index: 90; display: none;
  align-items: center; justify-content: center; background: var(--bg); padding: 24px;
}
#login.on { display: flex; }
#login .box { width: 100%; max-width: 340px; text-align: center; }
#login h2 { margin-bottom: 6px; }
#login p { color: var(--fg2); font-size: 13px; margin-bottom: 18px; }
#login input { text-align: center; font-size: 16px; }
#login label.f { margin-bottom: 10px; }

.empty { text-align: center; color: var(--fg3); padding: 34px 12px; font-size: 13.5px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--bg2); color: var(--fg2);
  border-radius: 999px; padding: 5px 12px; font-size: 12.5px; font-weight: 600;
}
.chip.on { border-color: var(--accent); color: var(--accent); background: #0d2438; }
.hr { height: 1px; background: var(--line); margin: 16px 0; }
progress { width: 100%; height: 6px; }
