:root {
  --bg: #faf7f2; --card: #ffffff; --ink: #2b2723; --sub: #6f675e; --line: #e6dfd5;
  --accent: #b5482f; --accent-ink: #ffffff; --soft: #f3ebe0; --done: #3f7d58; --hold: #a9720f; --skip: #7c7570;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a18; --card: #272421; --ink: #f1ece5; --sub: #aaa197; --line: #3b3631;
    --accent: #e0775c; --accent-ink: #1c1a18; --soft: #332e29; --done: #79c096; --hold: #e0ac4e; --skip: #a39b94;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); line-height: 1.55;
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.top {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { color: var(--accent); font-weight: 700; font-size: 20px; text-decoration: none; }
.tagline { color: var(--sub); font-size: 13px; }
.tools { margin-left: auto; display: flex; gap: 12px; }
.link { background: none; border: 0; padding: 4px 0; color: var(--sub); font-size: 13px; text-decoration: underline; }
main { max-width: 1120px; margin: 0 auto; padding: 16px; }

.add { display: flex; gap: 8px; margin-bottom: 8px; }
.add input {
  flex: 1; min-width: 0; padding: 10px 12px; background: var(--card);
  border: 1px solid var(--line); border-radius: 8px;
}
.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 700; white-space: nowrap; }
.primary:disabled { opacity: .6; cursor: default; }
.msg { min-height: 22px; color: var(--sub); font-size: 13px; margin: 0 0 12px; }
.msg.error { color: var(--accent); }
.empty { color: var(--sub); padding: 32px 0; text-align: center; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card-head { display: flex; gap: 10px; align-items: center; color: inherit; text-decoration: none; min-width: 0; }
.card-head img { width: 44px; height: 44px; border-radius: 50%; flex: none; background: var(--soft); }
.card-title { font-weight: 700; overflow-wrap: anywhere; }
.bar { height: 8px; background: var(--soft); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--done); }
.nums { font-size: 13px; color: var(--sub); }
.nums b { color: var(--ink); font-variant-numeric: tabular-nums; }
.card .primary { text-align: center; text-decoration: none; padding: 8px 12px; }

.watch { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; align-items: start; }
.player-box { aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; position: relative; }
.player-box iframe, .player-box > div { width: 100%; height: 100%; display: block; border: 0; }
.now-title { font-size: 17px; font-weight: 700; margin: 10px 0 2px; overflow-wrap: anywhere; }
.now-meta { color: var(--sub); font-size: 13px; margin: 0 0 8px; }
.notice { background: var(--soft); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin: 0 0 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions button, .actions a {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; font-size: 14px; color: inherit; text-decoration: none;
}
.actions .main { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.actions button[hidden] { display: none; }
.actions button:disabled { opacity: .4; cursor: default; }
.sub-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 10px; font-size: 13px; color: var(--sub); }
.sub-actions label { display: inline-flex; align-items: center; gap: 4px; }
.chan-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 12px; }
.chan-head h1 { font-size: 18px; margin: 0; overflow-wrap: anywhere; }
.chan-head .bar { flex: 1 1 120px; }

.side { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.filters { padding: 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tabs button { border: 1px solid var(--line); background: none; border-radius: 16px; padding: 3px 10px; font-size: 13px; }
.tabs button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.selects { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.selects select { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }
.selects label { display: inline-flex; align-items: center; gap: 4px; }
.list { list-style: none; margin: 0; padding: 0; max-height: calc(100vh - 210px); overflow-y: auto; }
.row { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:hover { background: var(--soft); }
.row.current { background: var(--soft); box-shadow: inset 3px 0 0 var(--accent); }
.thumb { position: relative; display: block; aspect-ratio: 16 / 9; background: var(--soft); border-radius: 6px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb span { position: absolute; right: 3px; bottom: 3px; background: rgba(0,0,0,.8); color: #fff; font-size: 11px; padding: 0 4px; border-radius: 3px; }
.thumb .resume { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); padding: 0; border-radius: 0; right: auto; }
.row-title { font-size: 13px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; background: none; border: 0; padding: 0; text-align: left; width: 100%; }
.row-meta { font-size: 12px; color: var(--sub); display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: center; }
.state-watched { color: var(--done); font-weight: 700; }
.state-later { color: var(--accent); font-weight: 700; }
.state-hold { color: var(--hold); font-weight: 700; }
.state-skip { color: var(--skip); font-weight: 700; }
.back { background: none; border: 0; padding: 0; color: var(--sub); font-size: 12px; text-decoration: underline; }
.more { padding: 10px; text-align: center; color: var(--sub); font-size: 13px; }

.section { font-size: 15px; margin: 20px 0 8px; }
.section-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.empty.small { padding: 8px 0; font-size: 13px; text-align: left; }
.head-tools { display: inline-flex; gap: 12px; }
.list-note { margin: 0; font-size: 13px; color: var(--sub); }
.row-tools { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.row-tools button { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px; font-size: 12px; color: var(--sub); }
.row-tools button:disabled { opacity: .35; cursor: default; }
.dialog { width: min(420px, calc(100vw - 32px)); background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dialog h2 { font-size: 16px; margin: 0 0 8px; }
.dialog input { width: 100%; min-width: 0; padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.dialog .add { margin: 8px 0 0; }
.dialog .add input { flex: 1; width: auto; }
.dialog-video { font-size: 13px; color: var(--sub); margin: 0 0 10px; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.dialog-actions button:not(.primary) { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.picks { display: flex; flex-direction: column; gap: 4px; max-height: 40vh; overflow-y: auto; }
.pick { display: flex; justify-content: space-between; gap: 8px; text-align: left; background: var(--soft); border: 0; border-radius: 6px; padding: 8px 10px; }
.pick span { overflow-wrap: anywhere; }
.pick small { color: var(--sub); white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 10;
  width: max-content; max-width: calc(100vw - 32px);
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--ink); color: var(--bg); border-radius: 8px; font-size: 14px;
}
.toast[hidden] { display: none; }
.toast button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; white-space: nowrap; padding: 0; }

@media (max-width: 860px) {
  .watch { grid-template-columns: minmax(0, 1fr); }
  .list { max-height: none; overflow: visible; }
  .now-title { font-size: 15px; }
  .actions button, .actions a { padding: 7px 10px; font-size: 13px; }
}

/* 大きく表示（パソコンの幅だけ） */
.wide-toggle { display: none; }
a.pick { color: inherit; text-decoration: none; }
@media (min-width: 861px) {
  /* 「もう見た」は塗りつぶし、こちらは枠だけにして、ほかより目立つが主役にはしない */
  .sub-actions .wide-toggle {
    display: inline-flex; justify-content: center; min-width: 124px; padding: 8px 18px;
    background: var(--card); color: var(--accent); border: 2px solid var(--accent); border-radius: 8px;
    font-size: 15px; font-weight: 700; text-decoration: none;
  }
  .sub-actions .wide-toggle:hover { background: var(--soft); }
  /* 動画の幅：ふだんの約1.5倍。画面の幅と高さに収まらないときは、収まる大きさまで */
  .watch.wide {
    --wide-w: min(calc((min(1088px, 100vw - 32px) - 416px) * 1.5), calc(100vw - 32px), calc((100vh - 16px) * 16 / 9));
    grid-template-columns: minmax(0, 1fr);
  }
  .watch.wide .player-col, .watch.wide .side { width: min(100%, var(--wide-w)); justify-self: center; }
  .watch.wide .player-box { scroll-margin-top: 8px; }
  .watch.wide .list { max-height: none; overflow: visible; }
}
/* 動画の横に一覧が入る幅なら、一覧は横に残す */
@media (min-width: 1376px) {
  main:has(.watch.wide) { max-width: 1456px; }
  .watch.wide { grid-template-columns: var(--wide-w) minmax(320px, 400px); justify-content: center; }
  .watch.wide .player-col, .watch.wide .side { width: auto; justify-self: stretch; }
  .watch.wide .list { max-height: calc(100vh - 210px); overflow-y: auto; }
}

/* トップへ戻る道と、トップだけの道具 */
.tools[hidden] { display: none; }
.back-top {
  display: inline-block; margin-bottom: 10px; padding: 6px 12px; max-width: 100%;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; font-weight: 700; text-decoration: none;
}
.back-top:hover { background: var(--soft); }

/* 公開版 */
.player-box { width: 100%; min-width: 200px; min-height: 200px; }
.terms-note { margin: 0 0 8px; font-size: 12px; color: var(--sub); }
.terms-note a, .site-footer a, .legal a { color: inherit; }
.home-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.tool-button { display: inline-block; background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; font-size: 14px; text-decoration: none; }
.tool-button:hover { background: var(--soft); }
.danger { background: none; color: var(--accent); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 14px; font-size: 14px; }
.page-title { font-size: 20px; margin: 8px 0; }
.lead { font-size: 16px; font-weight: 700; }
.plain { padding-left: 20px; color: var(--sub); font-size: 14px; }
.agree { display: flex; gap: 8px; align-items: center; margin: 12px 0; }
.google-box { min-height: 44px; margin-bottom: 8px; }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.site-footer { max-width: 1120px; margin: 24px auto 0; padding: 16px; display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--sub); font-size: 12px; border-top: 1px solid var(--line); }
.legal { max-width: 760px; margin: 0 auto; padding: 16px; }
.legal h1 { font-size: 22px; }
.legal h2 { font-size: 16px; margin-top: 24px; }
.legal .todo { background: var(--soft); padding: 2px 6px; border-radius: 4px; }

/* YouTube の決まりに合わせた表示 */
.row { grid-template-columns: 128px minmax(0, 1fr); }   /* 再生を始めるサムネイルは 120×70 以上 */
.source-note { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; margin: 0 0 10px; color: var(--sub); font-size: 12px; }
.source-from { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.yt-source { color: inherit; font-weight: 700; }
.yt-source.has-logo { position: relative; display: inline-block; width: 226px; height: 35px; overflow: hidden; }
.yt-source.has-logo picture { display: block; }
.yt-source.has-logo .yt-logo { position: absolute; left: -42px; top: -37px; width: 308px; height: 110px; max-width: none; }
.toast.inline { position: static; transform: none; width: auto; max-width: none; margin: 8px 0; justify-content: space-between; }
.dialog.inline { position: static; display: block; width: 100%; margin: 8px 0; }

/* 子ども向けの動画は埋め込まない */
.player-box.kids > :not(.kids-panel) { display: none !important; }
.kids-panel[hidden] { display: none; }
.kids-panel {
  width: 100%; height: 100%; min-height: 200px; padding: 16px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; text-align: center;
  background: var(--card); color: var(--ink); font-size: 14px;
}
.kids-panel p { margin: 0; }
.kids-panel .primary { text-decoration: none; }
