:root {
  --bg: #0f0f10;
  --surface: #17171a;
  --surface-2: #1f1f24;
  --border: #2a2a30;
  --text: #f2f2f4;
  --muted: #9a9aa4;
  --accent: #ff4d4d;
  --accent-soft: rgba(255, 77, 77, 0.14);
  --radius: 14px;
  --maxw: 1240px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f6f7;
    --surface: #ffffff;
    --surface-2: #f0f0f2;
    --border: #e2e2e6;
    --text: #16161a;
    --muted: #6b6b74;
    --accent: #e23a3a;
    --accent-soft: rgba(226, 58, 58, 0.1);
  }
}

* { box-sizing: border-box; }
/* hidden属性を、display指定を持つ要素(.drawer, .link-btn等)より確実に優先させる */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: calc(12px + env(safe-area-inset-top)) 22px 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; flex-shrink: 0; }
.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 13px;
}
.brand-name { font-weight: 700; font-size: 19px; letter-spacing: -0.02em; }
.search { flex: 1; display: flex; justify-content: center; }
.search input {
  width: 100%; max-width: 560px;
  padding: 10px 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 15px; outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 17px; cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--surface-2); }
.ghost-btn {
  padding: 9px 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
}
.ghost-btn:hover { background: var(--surface-2); }

/* ---- Layout ---- */
main { max-width: var(--maxw); margin: 0 auto; padding: 24px 22px 80px; }
.status { color: var(--muted); font-size: 14px; padding: 8px 2px 18px; }

/* ---- Grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 22px 18px;
}
.card { cursor: pointer; }
.card .thumb {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  border-radius: var(--radius); overflow: hidden; background: var(--surface-2);
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform 0.25s ease; }
.card:hover .thumb img { transform: scale(1.03); }
.card .thumb .dur {
  position: absolute; right: 8px; bottom: 8px;
  background: rgba(0,0,0,0.82); color: #fff; font-size: 12px; font-weight: 600;
  padding: 1px 5px; border-radius: 5px; letter-spacing: 0.02em;
}
.card .info { display: flex; gap: 11px; padding: 11px 2px 0; }
.card .avatar {
  width: 34px; height: 34px; border-radius: 999px; flex-shrink: 0;
  background: var(--surface-2); object-fit: cover;
}
.card .avatar.placeholder { display: grid; place-items: center; color: var(--muted); font-weight: 700; font-size: 14px; }
.card .title {
  font-size: 15px; font-weight: 600; line-height: 1.35; margin: 0 0 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .sub { color: var(--muted); font-size: 13px; line-height: 1.5; }
.card .sub .dot { margin: 0 5px; }

/* ---- Empty state ---- */
.empty {
  text-align: center; padding: 80px 20px; color: var(--muted);
}
.empty h2 { color: var(--text); font-size: 22px; margin: 0 0 10px; }
.empty p { margin: 0 0 22px; font-size: 15px; }
.empty button { font-size: 15px; padding: 12px 22px; }
.empty .accent-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 999px; cursor: pointer; font-weight: 700;
}

/* ---- Player ---- */
.back-btn {
  background: none; border: none; color: var(--text); font-size: 15px; font-weight: 600;
  cursor: pointer; padding: 4px 0; margin-bottom: 14px;
}
.player-wrap { max-width: 980px; margin: 0 auto; }
.player-frame {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  border-radius: var(--radius); overflow: hidden; background: #000;
}
.player-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-title { max-width: 980px; margin: 20px auto 6px; font-size: 21px; line-height: 1.4; }
.player-meta { max-width: 980px; margin: 0 auto; color: var(--muted); font-size: 14px; }

/* ---- Drawer ---- */
.drawer {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.5); display: flex; justify-content: flex-end;
}
.drawer-panel {
  width: min(440px, 100%); height: 100%; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--border);
  padding: 20px 22px 40px; animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { transform: translateX(30px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.drawer-head h2 { font-size: 19px; margin: 0; }

.add-box { display: flex; gap: 8px; }
.add-box input {
  flex: 1; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; outline: none;
}
.add-box input:focus { border-color: var(--accent); }
.add-box button {
  padding: 0 18px; border-radius: 10px; border: none; background: var(--accent);
  color: #fff; font-weight: 700; cursor: pointer;
}
.add-msg { font-size: 13px; color: var(--muted); min-height: 18px; margin: 8px 2px 0; }
.add-msg.error { color: var(--accent); }
.add-msg.ok { color: #35c07a; }

.sync-box {
  margin: 22px 0; padding: 16px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.sync-head { display: flex; align-items: center; justify-content: space-between; }
.sync-desc { color: var(--muted); font-size: 13px; margin: 8px 0 12px; line-height: 1.5; }
.sync-actions { display: flex; gap: 8px; }
.badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--border); color: var(--muted); font-weight: 600; }
.badge.on { background: var(--accent-soft); color: var(--accent); }
.link-btn {
  display: inline-block; padding: 9px 16px; border-radius: 999px;
  background: var(--accent); color: #fff; text-decoration: none; font-weight: 700; font-size: 14px;
}

.ch-list-head { margin: 8px 2px 12px; color: var(--muted); font-size: 13px; font-weight: 600; }
.channel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.channel-list li {
  display: flex; align-items: center; gap: 11px; padding: 9px 8px; border-radius: 10px;
}
.channel-list li:hover { background: var(--surface-2); }
.channel-list .ch-av { width: 32px; height: 32px; border-radius: 999px; background: var(--surface-2); object-fit: cover; flex-shrink: 0; }
.channel-list .ch-av.placeholder { display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.channel-list .ch-name { flex: 1; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-list .ch-tag { font-size: 10px; color: var(--muted); border: 1px solid var(--border); padding: 2px 6px; border-radius: 6px; }
.channel-list .rm { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 4px; }
.channel-list .rm:hover { color: var(--accent); }

.spinner { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 999px; animation: spin 0.7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.site-footer {
  max-width: var(--maxw); margin: 0 auto; padding: 28px 22px 40px;
  display: flex; gap: 18px; align-items: center;
  color: var(--muted); font-size: 13px; border-top: 1px solid var(--border);
}
.site-footer span { font-weight: 600; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); }

@media (max-width: 620px) {
  .brand-name { display: none; }
  .ghost-btn { padding: 9px 12px; }
  main { padding: 18px 14px 60px; }
  .grid { grid-template-columns: 1fr; }
}
