:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface2: #eceef2;
  --text: #15171c;
  --muted: #6b7180;
  --line: #dfe2e8;
  --accent: #e5484d;
  --accent-text: #ffffff;
  --good: #1f9d55;
  --bad: #d93a3a;
  --tabbar-h: 58px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #181b21;
    --surface2: #232731;
    --text: #eef0f4;
    --muted: #9aa1ae;
    --line: #2b303b;
    --accent: #ff5a5f;
    --good: #3fcf7f;
    --bad: #ff6b6b;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  padding-top: calc(var(--top) + 52px);
  padding-bottom: calc(var(--tabbar-h) + var(--bottom) + 16px);
  overscroll-behavior-y: none;
}
body.player-mini { padding-bottom: calc(var(--tabbar-h) + var(--bottom) + 96px); }
body.has-player:not(.player-mini) { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
a { color: var(--accent); }
img { display: block; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; padding: 32px 0; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.danger { color: var(--bad) !important; }

/* ---------- 上のバーと下のタブ ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  padding: calc(var(--top) + 8px) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 22px; line-height: 36px; font-weight: 800; letter-spacing: .02em; }
main { padding: 8px 16px 0; max-width: 760px; margin: 0 auto; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--bottom));
  padding-bottom: var(--bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 600;
}
.tabbar svg { width: 26px; height: 26px; fill: currentColor; }
.tabbar button[aria-current="page"] { color: var(--accent); }

/* ---------- 共通部品 ---------- */
.block { margin: 18px 0 8px; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.block-head h2 { margin: 0; font-size: 18px; font-weight: 800; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--accent-text); font-weight: 700; text-decoration: none;
}
.btn.ghost { background: var(--surface2); color: var(--text); }
.btn.wide { width: 100%; margin-top: 10px; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 4px; min-height: 40px; text-decoration: none; display: inline-flex; align-items: center; }
.inline-form { display: flex; gap: 8px; }
.inline-form input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px; /* 16px未満だとiOSが勝手に拡大する */
}
.inline-form.sticky { position: sticky; top: calc(var(--top) + 60px); z-index: 10; padding: 8px 0; background: var(--bg); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.two .btn { padding: 0 8px; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 600; text-decoration: none; color: var(--text);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.removable { padding: 0; overflow: hidden; }
.chip.removable button { border: 0; background: none; min-height: 40px; padding: 0 6px 0 14px; font-weight: 600; font-size: 14px; }
.chip.removable .x { padding: 0 12px 0 6px; color: var(--muted); }
.sug-label { font-size: 13px; color: var(--muted); font-weight: 700; margin: 14px 0 8px; }
.err { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); color: var(--text); border-radius: 12px; padding: 12px 14px; margin: 0; font-size: 14px; }
.empty { text-align: center; padding: 32px 12px; color: var(--muted); }
.empty .btn { margin-top: 8px; }
.skeleton { height: 84px; border-radius: 12px; margin-bottom: 10px; background: linear-gradient(90deg, var(--surface2), var(--surface), var(--surface2)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- 動画カード ---------- */
.list { display: flex; flex-direction: column; gap: 12px; }
.card { display: grid; grid-template-columns: 148px 1fr 36px; gap: 10px; align-items: start; }
.thumb {
  position: relative; padding: 0; border: 0; border-radius: 10px; overflow: hidden;
  aspect-ratio: 16 / 9; background: var(--surface2); width: 100%;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.noimg { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 12px; font-weight: 700; }
.tag { position: absolute; right: 5px; bottom: 5px; padding: 1px 6px; border-radius: 5px; background: rgba(0,0,0,.78); color: #fff; font-size: 11px; font-weight: 700; }
.tag.live { background: #e5161d; }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255,255,255,.35); }
.progress i { display: block; height: 100%; background: var(--accent); }
.meta { min-width: 0; }
.title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  border: 0; background: none; padding: 0; text-align: left; font-size: 15px; font-weight: 700; line-height: 1.35;
}
.sub { display: flex; flex-wrap: wrap; gap: 2px 8px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.svc { color: var(--c); font-weight: 800; }
.more { border: 0; background: none; color: var(--muted); width: 36px; height: 40px; display: grid; place-items: center; }
.hscroll { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: 16px; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
.card.compact { flex: 0 0 200px; grid-template-columns: 1fr 28px; scroll-snap-align: start; }
.card.compact .thumb { grid-column: 1 / -1; }
.card.compact .more { width: 28px; }

/* ---------- 検索のタブ ---------- */
.stabs { display: flex; gap: 6px; overflow-x: auto; margin: 4px -16px 0; padding: 4px 16px; scrollbar-width: none; }
.stabs::-webkit-scrollbar { display: none; }
.stabs button {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 700;
}
.stabs button[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.stabs i { font-style: normal; font-size: 11px; opacity: .7; }
.stabs i.bad { color: var(--bad); opacity: 1; }
.spin { width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 配信サービスの作品カード ---------- */
.work { display: grid; grid-template-columns: 92px 1fr; gap: 12px; padding: 12px; margin-bottom: 12px; background: var(--surface); border-radius: var(--radius); }
.poster { width: 92px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 8px; background: var(--surface2); }
.poster.noimg { display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.work h3 { margin: 0 0 4px; font-size: 16px; line-height: 1.35; }
.work h3 .muted { font-size: 12px; font-weight: 600; }
.overview { margin: 0 0 8px; font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.prov-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.prov-label { font-size: 11px; font-weight: 800; color: var(--muted); width: 100%; }
.prov { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 3px 10px 3px 3px; border-radius: 10px; background: var(--surface2); color: var(--text); text-decoration: none; font-size: 12px; font-weight: 700; }
.prov img { width: 30px; height: 30px; border-radius: 7px; }

/* ---------- ライブラリ・設定 ---------- */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; margin: 6px 0 14px; background: var(--surface2); border-radius: 12px; }
.seg button { border: 0; background: none; min-height: 38px; border-radius: 9px; font-size: 13px; font-weight: 700; color: var(--muted); }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.pl-title { margin: 4px 0 12px; font-size: 20px; }
.card-box { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row small { color: var(--muted); font-size: 12px; }
.row.col { flex-direction: column; align-items: flex-start; gap: 2px; }
.btn-row { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; font-weight: 600; color: var(--accent); cursor: pointer; }
input[type="radio"] { width: 22px; height: 22px; accent-color: var(--accent); }
.switch {
  appearance: none; -webkit-appearance: none; flex: 0 0 auto; width: 52px; height: 32px; border-radius: 99px;
  background: var(--surface2); position: relative; transition: background .2s; border: 1px solid var(--line);
}
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch:checked { background: var(--good); border-color: var(--good); }
.switch:checked::after { transform: translateX(20px); }

/* ---------- シート・トースト ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 86vh; overflow-y: auto; background: var(--surface);
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(16px + var(--bottom)); animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h3 { margin: 0 0 12px; font-size: 17px; }
.sheet-list { display: flex; flex-direction: column; }
.sheet-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; padding: 0 4px;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; font-size: 16px; font-weight: 600; color: var(--text); text-decoration: none;
}
.sheet-item.accent { color: var(--accent); }
.sheet-scroll { max-height: 52vh; overflow-y: auto; }
.steps { padding-left: 1.4em; margin: 0 0 12px; }
.steps li { margin-bottom: 8px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 80;
  bottom: calc(var(--tabbar-h) + var(--bottom) + 16px); max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: 12px; background: rgba(20,22,28,.94); color: #fff; font-size: 14px; font-weight: 600; text-align: center;
}
body.player-mini .toast { bottom: calc(var(--tabbar-h) + var(--bottom) + 96px); }

/* ---------- プレイヤー(全画面) ---------- */
.player { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; padding-top: var(--top); }
.p-head { display: flex; align-items: center; justify-content: space-between; height: 48px; padding: 0 6px; }
.icon-btn { width: 46px; height: 46px; display: grid; place-items: center; border: 0; background: none; color: var(--text); border-radius: 50%; }
.p-badge { padding: 3px 10px; border-radius: 99px; color: #fff; font-size: 12px; font-weight: 800; }
.stage { background: #000; width: 100%; max-width: 760px; margin: 0 auto; }
.stage-inner { position: relative; width: 100%; aspect-ratio: 16 / 9; }
.stage-inner > * , .stage-inner iframe, .stage-inner video { position: absolute; inset: 0; width: 100% !important; height: 100% !important; border: 0; }
.stage-inner video { background: #000; }
.vimeo-holder > div { padding: 0 !important; height: 100%; }
.mini-bar { display: none; }
.p-body { flex: 1; overflow-y: auto; padding: 14px 16px calc(24px + var(--bottom)); width: 100%; max-width: 760px; margin: 0 auto; }
.p-title { margin: 0; font-size: 18px; line-height: 1.4; }
.p-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.p-note { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--bad) 12%, var(--surface)); font-size: 14px; }
.p-time { margin: 10px 0 4px; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.ctl-row { display: grid; grid-template-columns: 1fr 1.2fr 1fr 1fr; gap: 8px; margin: 6px 0 14px; }
.ctl { min-height: 54px; border-radius: 14px; border: 0; background: var(--surface2); font-weight: 800; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.ctl.big { background: var(--accent); color: var(--accent-text); }
.ctl-group { margin-bottom: 14px; }
.ctl-label { font-size: 13px; font-weight: 800; color: var(--muted); margin-bottom: 6px; }
.ctl-label span { font-weight: 600; color: var(--accent); margin-left: 6px; }
.ctl-group .chips { flex-wrap: nowrap; gap: 6px; }
.ctl-group .chip { flex: 1 1 0; min-width: 0; padding: 0 4px; justify-content: center; }
.actions { grid-template-columns: repeat(4, 1fr); }
.act { min-height: 62px; border: 0; border-radius: 14px; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 700; color: var(--text); }
.act.on { color: var(--accent); }

/* ---------- プレイヤー(小さくした状態) ---------- */
.player.mini {
  inset: auto 8px calc(var(--tabbar-h) + var(--bottom) + 8px) 8px; height: 76px; padding: 6px; z-index: 40;
  flex-direction: row; align-items: center; gap: 10px; border-radius: 14px;
  background: var(--surface); box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.player.mini .p-head, .player.mini .p-body { display: none; }
.player.mini .stage { width: 112px; flex: 0 0 112px; margin: 0; border-radius: 8px; overflow: hidden; }
.player.mini .mini-bar { display: flex; flex: 1; min-width: 0; align-items: center; }
.mini-title { flex: 1; min-width: 0; border: 0; background: none; text-align: left; font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0; min-height: 46px; }

@media (min-width: 700px) {
  .card { grid-template-columns: 220px 1fr 36px; }
}

/* ---------- マルチ視聴(複数窓) ---------- */
.actions { grid-template-columns: repeat(5, 1fr); gap: 6px; }
.act span { font-size: 10px; }
.mv-open-btn { margin-top: 8px; }
.multi { position: fixed; inset: 0; z-index: 45; background: var(--bg); display: flex; flex-direction: column; padding-top: var(--top); transition: transform .25s ease; }
.multi.away { transform: translateY(calc(100% + 40px)); pointer-events: none; } /* 画面の外へ出すだけで、再生は止めない */
.mv-head-title { font-size: 16px; }
.mv-tools { display: flex; gap: 6px; overflow-x: auto; padding: 4px 12px 10px; scrollbar-width: none; flex: 0 0 auto; }
.mv-tools::-webkit-scrollbar { display: none; }
.mv-tools .chip { flex: 0 0 auto; }
.accent-chip { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.mv-scroll { flex: 1; overflow-y: auto; padding: 0 8px calc(16px + var(--bottom)); }
.mv-grid { display: grid; gap: 8px; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); max-width: 1100px; margin: 0 auto; }
.mv-grid[data-cols="1"] { --cols: 1; }
.mv-grid[data-cols="2"] { --cols: 2; }
.mv-pane { background: var(--surface); border-radius: 12px; overflow: hidden; border: 2px solid transparent; min-width: 0; }
.mv-pane.audible { border-color: var(--accent); }
.mv-pane.focus { grid-column: 1 / -1; }
.mv-stage { position: relative; aspect-ratio: 16 / 9; background: #000; }
.mv-stage > *, .mv-stage iframe, .mv-stage video { position: absolute; inset: 0; width: 100% !important; height: 100% !important; border: 0; }
.mv-bar { display: flex; align-items: center; gap: 4px; padding: 2px 2px 2px 8px; min-height: 44px; }
.mv-svc { flex: 0 0 auto; padding: 1px 6px; border-radius: 99px; color: #fff; font-size: 10px; font-weight: 800; }
.mv-title { flex: 1; min-width: 0; font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mv-btn { flex: 0 0 auto; width: 40px; height: 40px; border: 0; border-radius: 10px; background: none; color: var(--muted); display: grid; place-items: center; }
.mv-btn.on { color: var(--accent); }
.mv-grid[data-cols="2"] .mv-pane:not(.focus) .mv-svc { display: none; }
.mv-grid[data-cols="2"] .mv-pane:not(.focus) .mv-btn { width: 32px; }
.mv-note { margin: 0; padding: 6px 8px; font-size: 12px; background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }
.mv-empty { text-align: center; padding: 40px 16px 16px; }
.mv-empty p { margin: 0 0 8px; }
.mv-help { max-width: 760px; margin: 16px auto 0; padding: 0 8px; line-height: 1.8; }
.mv-help .link { min-height: 0; padding: 0; }
.mv-pill {
  position: fixed; z-index: 35; right: 12px; top: calc(var(--top) + 10px);
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border: 0; border-radius: 99px;
  background: var(--accent); color: var(--accent-text); font-size: 13px; font-weight: 800; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.pick { justify-content: flex-start; gap: 10px; font-size: 14px; }
.pick-svc { flex: 0 0 auto; font-size: 11px; font-weight: 800; }
.pick-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.accent { color: var(--accent); font-weight: 800; }
body.mv-open { overflow: hidden; }
/* 横向きでは2本でも左右に並べる */
@media (orientation: landscape) and (max-height: 500px) {
  .mv-grid[data-layout="auto"] { --cols: 2 !important; }
}

/* ---------- 便利機能(連続再生・くり返し・時間メモ・反転) ---------- */
.actions { grid-template-columns: repeat(3, 1fr); }
.act span { font-size: 11px; }
.p-queue { background: var(--surface); border-radius: 14px; padding: 12px; margin-bottom: 14px; }
.q-head { font-size: 14px; }
.p-queue .two { margin: 8px 0; }
.q-list { display: flex; flex-direction: column; }
.q-item { border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; padding: 8px 2px; min-height: 40px; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-note { margin: 6px 0 0; }
.ctl-group .chips.wrap { flex-wrap: wrap; }
.ctl-group .chips.wrap .chip { flex: 0 0 auto; padding: 0; }
.ctl-group .chip.removable button { padding: 0 6px 0 12px; }
.ctl-group .chip.removable .x { padding: 0 10px 0 4px; }
.small-chip { min-height: 32px !important; padding: 0 10px !important; font-size: 12px !important; margin-left: 6px; flex: 0 0 auto !important; vertical-align: middle; color: var(--accent) !important; }
.sub-btn { cursor: pointer; }
.stage-inner.mirror > *, .stage-inner.mirror iframe, .stage-inner.mirror video { transform: scaleX(-1); }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0 12px; }
.filters select { min-height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 10px; font-size: 14px; }
.filters .chip { min-height: 36px; padding: 0 12px; }
.list-actions { display: flex; gap: 8px; margin: 0 0 12px; }
.list-actions .btn { flex: 1; min-height: 42px; font-size: 14px; }
.stat-big { font-size: 22px; font-weight: 800; }

/* ---------- チャンネル ---------- */
.seg { grid-template-columns: repeat(5, 1fr); }
.seg button { font-size: 12px; }
.ch-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.ch-head h3 { margin: 0; }
.ch-head .svc { font-size: 12px; }
.ch-row { gap: 8px; }
.ch-open { flex: 1; min-width: 0; border: 0; background: none; text-align: left; font-size: 15px; font-weight: 700; color: var(--text); min-height: 48px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0; }
.ch-open .svc { font-size: 11px; margin-right: 4px; }
.p-channel { padding: 4px 0; min-height: 36px; }
