:root {
  --bg: #0b0d0c;
  --panel: #151917;
  --panel2: #1d2320;
  --line: #2a312d;
  --fg: #e8ece9;
  --dim: #8d978f;
  --accent: #53fc18;
  --live: #ff3b3b;
  --r: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: currentColor; display: block; }

/* ---------- home ---------- */
#home {
  max-width: 1280px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
}
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 4px 0 10px; }
.logo { margin: 0; font-size: 20px; letter-spacing: .02em; font-weight: 700; }
.logo b { color: var(--accent); }
.go { flex: 1 1 280px; display: flex; gap: 8px; }
.go input {
  flex: 1; min-width: 0; height: 40px; padding: 0 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  font-size: 16px; /* iOS のズーム防止 */
}
.go input:focus { outline: none; border-color: var(--accent); }
.go button {
  height: 40px; padding: 0 18px; border: 0; border-radius: var(--r);
  background: var(--accent); color: #041000; font-weight: 700;
}
.sec { margin-top: 14px; }
.sechead { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.sechead h2 { margin: 0; font-size: 15px; }
.count { color: var(--dim); font-size: 13px; }
.sechead .iconbtn { margin-left: auto; }
.sub { margin: 18px 0 8px; font-size: 13px; color: var(--dim); font-weight: 600; }
.note { color: var(--dim); }

.iconbtn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  padding: 0; border: 0; border-radius: 50%; background: transparent;
}
.iconbtn:hover { background: rgba(255,255,255,.08); }
.iconbtn.spinning svg { animation: rot 0.8s linear infinite; }

.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  flex: none; height: 30px; padding: 0 12px; border-radius: 15px;
  border: 1px solid var(--line); background: var(--panel); color: var(--dim);
}
.filters button[aria-selected="true"] { background: var(--fg); color: #000; border-color: var(--fg); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 12px; }
.card { display: block; color: inherit; text-decoration: none; min-width: 0; }
.thumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--r); overflow: hidden;
  background: var(--panel2);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge {
  position: absolute; left: 6px; top: 6px; padding: 1px 6px; border-radius: 4px;
  background: var(--live); color: #fff; font-size: 11px; font-weight: 700;
}
.vc {
  position: absolute; left: 6px; bottom: 6px; padding: 1px 6px; border-radius: 4px;
  background: rgba(0,0,0,.72); font-size: 12px;
}
.card .nm { margin-top: 6px; font-weight: 700; display: flex; gap: 6px; align-items: baseline; }
.card .nm small { color: var(--dim); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .tt {
  color: var(--fg); opacity: .85; font-size: 13px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .cat { color: var(--dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card:hover .thumb { outline: 2px solid var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 16px; background: var(--panel); border: 1px solid var(--line);
  color: var(--fg); text-decoration: none; font-size: 13px; max-width: 100%;
}
.chip:hover { border-color: var(--dim); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #444; flex: none; }
.chip.on .dot { background: var(--live); }
.chip.on { border-color: #5a2a2a; }
.chip .x { margin: 0 -6px 0 2px; padding: 0 4px; border: 0; background: none; color: var(--dim); font-size: 16px; line-height: 1; }
.chip .x:hover { color: var(--fg); }
.chip .vcs { color: var(--dim); font-size: 12px; }

.skel { aspect-ratio: 16/9; border-radius: var(--r); background: linear-gradient(90deg, var(--panel) 0, var(--panel2) 50%, var(--panel) 100%); background-size: 200% 100%; animation: sh 1.2s infinite; }
@keyframes sh { to { background-position: -200% 0; } }

/* ---------- player ---------- */
#player {
  position: fixed; inset: 0; background: #000; overflow: hidden;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }

.bar {
  position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 4px;
  padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right));
  transition: opacity .2s; z-index: 2;
}
.bar-top {
  top: 0; padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 28px;
  background: linear-gradient(rgba(0,0,0,.75), transparent);
}
.bar-bottom {
  bottom: 0; padding-bottom: max(6px, env(safe-area-inset-bottom)); padding-top: 28px;
  background: linear-gradient(transparent, rgba(0,0,0,.8));
}
#player.idle .bar, #player.idle .stats { opacity: 0; pointer-events: none; }
#player.idle { cursor: none; }
.meta { min-width: 0; flex: 1; }
.who { display: flex; gap: 10px; align-items: baseline; font-weight: 700; min-width: 0; }
.who > span:first-child { flex: none; white-space: nowrap; }
.viewers { color: var(--dim); font-weight: 400; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ptitle { font-size: 12px; color: #cfd6d1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
.vol { width: 90px; accent-color: var(--accent); }
@media (hover: none) { .vol { display: none; } }

.livebtn, .txtbtn {
  height: 28px; padding: 0 10px; border-radius: 6px; border: 0;
  background: rgba(255,255,255,.12); font-size: 12px; font-weight: 700; white-space: nowrap;
}
.livebtn::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #888; margin-right: 6px; vertical-align: 1px; }
.livebtn.at::before { background: var(--live); }
.txtbtn[aria-pressed="true"] { background: var(--accent); color: #041000; }
.quality {
  height: 28px; padding: 0 6px; border-radius: 6px; border: 0;
  background: rgba(255,255,255,.12); font-size: 12px; max-width: 130px;
}
.quality option { background: #111; }

.spin {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border: 4px solid rgba(255,255,255,.2); border-top-color: var(--accent); border-radius: 50%;
  animation: rot .8s linear infinite; z-index: 1; pointer-events: none;
}
@keyframes rot { to { transform: rotate(360deg); } }
.msg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(90%, 420px); text-align: center; z-index: 1;
}
.msg .m1 { font-size: 18px; font-weight: 700; margin: 0 0 4px; }
.msg .m2 { color: var(--dim); margin: 0 0 14px; white-space: pre-line; }
.msg button { height: 36px; padding: 0 18px; border-radius: 8px; border: 0; background: var(--accent); color: #041000; font-weight: 700; }
.unmute {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%); z-index: 3;
  display: flex; gap: 8px; align-items: center; height: 40px; padding: 0 16px;
  border: 0; border-radius: 20px; background: rgba(0,0,0,.8); font-weight: 700;
}
.stats {
  position: absolute; left: max(10px, env(safe-area-inset-left)); top: 70px; z-index: 2; margin: 0;
  padding: 8px 10px; border-radius: 8px; background: rgba(0,0,0,.75);
  font: 11px/1.5 ui-monospace, Menlo, Consolas, monospace; pointer-events: none; transition: opacity .2s;
}

@media (max-width: 520px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 12px 8px; }
  .card .tt { font-size: 12px; }
  .card .nm small { display: none; }
  .bar { gap: 2px; }
  .bar-bottom { overflow-x: auto; scrollbar-width: none; }
  .bar-bottom::-webkit-scrollbar { display: none; }
  .bar-bottom .iconbtn { width: 34px; height: 34px; flex: none; }
  .vol, #pipBtn { display: none !important; }
  .livebtn, .txtbtn { padding: 0 8px; font-size: 11px; flex: none; }
  .quality { max-width: 86px; flex: none; }
}
