/* Parens: the look.  Two themes as custom properties on .app. */

:root { color-scheme: dark light; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: #0f0f13; color: #f1f1f1; font: 14px/1.45 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
img { display: block; }

.app {
  --bg: #0f0f13; --surface: #1c1c22; --surface-2: #272730; --line: #2f2f39;
  --text: #f1f1f1; --muted: #a5a5b0; --accent: #c792ea; --accent-strong: #9b6bd6; --link: #82aaff;
  --chip: #26262e; --chip-on: #f1f1f1; --chip-on-text: #0f0f13; --skeleton: #24242c;
  min-height: 100vh; background: var(--bg); color: var(--text);
}
.app.theme-light {
  --bg: #ffffff; --surface: #f2f2f6; --surface-2: #e6e6ec; --line: #dedee6;
  --text: #0f0f13; --muted: #5f5f6b; --accent: #7b4bb8; --accent-strong: #6a3aa6; --link: #2a5bd7;
  --chip: #ececf1; --chip-on: #0f0f13; --chip-on-text: #ffffff; --skeleton: #e9e9ef;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---- the first screen, before Emacs runs ---- */
.boot { min-height: 100vh; display: grid; place-content: center; text-align: center; color: #a5a5b0; gap: 4px; }
.boot-logo { font-size: 28px; font-weight: 700; color: #f1f1f1; margin: 0; }
.boot-logo span { color: #c792ea; }

/* ---- icons: masks, because elisp-react cannot make SVG elements ---- */
.icon { display: inline-block; width: 24px; height: 24px; flex: none; background-color: currentColor;
        -webkit-mask: var(--i) center / contain no-repeat; mask: var(--i) center / contain no-repeat; }
.icon-menu { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z'/%3E%3C/svg%3E"); }
.icon-home { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3 2 12h3v8h6v-6h2v6h6v-8h3z'/%3E%3C/svg%3E"); }
.icon-history { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M13 3a9 9 0 0 0-9 9H1l4 4 4-4H6a7 7 0 1 1 2.05 4.95l-1.42 1.42A9 9 0 1 0 13 3zm-1 5v5l4.25 2.52.77-1.28-3.52-2.09V8z'/%3E%3C/svg%3E"); }
.icon-later { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm0 2a8 8 0 1 1 0 16 8 8 0 0 1 0-16zm-1 3v6l5.2 3.1 1-1.6-4.2-2.5V7z'/%3E%3C/svg%3E"); }
.icon-check { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 16.2 4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z'/%3E%3C/svg%3E"); }
.icon-search { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 3a7 7 0 0 1 5.6 11.2l5.6 5.6-1.4 1.4-5.6-5.6A7 7 0 1 1 10 3zm0 2a5 5 0 1 0 0 10 5 5 0 0 0 0-10z'/%3E%3C/svg%3E"); }
.icon-settings { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 6h9v2H3zm13 0h5v2h-5zm-2-2h2v6h-2zM3 16h4v2H3zm8 0h10v2H11zm-2-2h2v6H9z'/%3E%3C/svg%3E"); }
.icon-keyboard { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 6h20v12H2zm2 2v8h16V8zm1 1h2v2H5zm3 0h2v2H8zm3 0h2v2h-2zm3 0h2v2h-2zm3 0h2v2h-2zM7 13h10v2H7z'/%3E%3C/svg%3E"); }
.icon-like { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 10h4v11H2zm6 11h9.4a2 2 0 0 0 2-1.6l1.5-7.4A2 2 0 0 0 19 9.6h-5.6l.9-4.2A1.5 1.5 0 0 0 12.9 4L8 9.6z'/%3E%3C/svg%3E"); }
.icon-share { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M14 4l7 7-7 7v-4.1c-5 0-8.5 1.6-11 5.1 1-5 4-10 11-11z'/%3E%3C/svg%3E"); }
.icon-external { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M14 3h7v7h-2V6.4l-8.3 8.3-1.4-1.4L17.6 5H14zM5 5h6v2H7v10h10v-4h2v6H5z'/%3E%3C/svg%3E"); }
.icon-close { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.4 5 12 10.6 17.6 5 19 6.4 13.4 12 19 17.6 17.6 19 12 13.4 6.4 19 5 17.6 10.6 12 5 6.4z'/%3E%3C/svg%3E"); }

/* ---- top bar ---- */
.topbar { position: sticky; top: 0; z-index: 20; height: 56px; display: flex; align-items: center; gap: 16px;
          padding: 0 16px; background: var(--bg); }
.topbar-start, .topbar-end { display: flex; align-items: center; gap: 8px; flex: none; }
.logo { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 19px; letter-spacing: -0.3px; }
.logo-mark { color: var(--accent); font-size: 17px; }
.search { flex: 1; min-width: 0; max-width: 640px; margin: 0 auto; display: flex; }
.search input { flex: 1; min-width: 0; width: 0; height: 40px; padding: 0 16px; border: 1px solid var(--line); border-right: 0;
                border-radius: 20px 0 0 20px; background: var(--bg); color: var(--text); font: inherit; font-size: 16px; }
.search input:focus { outline: none; border-color: var(--accent); }
.search-button { width: 64px; flex: none; height: 40px; border: 1px solid var(--line); border-radius: 0 20px 20px 0;
                 background: var(--surface); display: grid; place-items: center; cursor: pointer; }
.icon-button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent;
               display: grid; place-items: center; cursor: pointer; }
.icon-button:hover { background: var(--surface-2); }
.mode-badge { height: 30px; padding: 0 12px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface);
              color: var(--muted); font-size: 12px; cursor: pointer; white-space: nowrap; }
.mode-badge.mode-api { color: var(--accent); border-color: var(--accent); }
.mode-badge.mode-server { color: var(--link); border-color: var(--link); }

/* ---- sidebar and content ---- */
.layout { display: flex; align-items: flex-start; }
.sidebar { position: sticky; top: 56px; width: 236px; flex: none; height: calc(100vh - 56px); overflow-y: auto;
           padding: 8px 12px 24px; }
.sidebar hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.sidebar-heading { font-size: 15px; font-weight: 600; margin: 4px 12px 6px; }
.nav-item { display: flex; align-items: center; gap: 20px; height: 40px; padding: 0 12px; border-radius: 10px; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.selected { background: var(--surface-2); font-weight: 600; }
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer { padding: 0 12px; color: var(--muted); font-size: 12px; }
.sidebar-footer a { color: var(--muted); text-decoration: underline; }
.content { flex: 1; min-width: 0; padding: 8px 24px 48px; }
.app.sidebar-toggled .sidebar { display: none; }
/* On a watch page, and on narrow windows, the sidebar is a drawer over the page. */
.app.page-watch .sidebar { display: none; }
.app.page-watch.sidebar-toggled .sidebar { display: block; position: fixed; left: 0; top: 56px; z-index: 30;
                                           background: var(--bg); box-shadow: 0 0 24px rgba(0, 0, 0, .4); }
@media (max-width: 1000px) {
  .sidebar { display: none; }
  .app.sidebar-toggled .sidebar { display: block; position: fixed; left: 0; top: 56px; z-index: 30;
                                  background: var(--bg); box-shadow: 0 0 24px rgba(0, 0, 0, .4); }
}
@media (max-width: 640px) {
  .logo-text, .mode-badge { display: none; }
  .content { padding: 8px 12px 40px; }
}

/* ---- chips ---- */
.chips { position: sticky; top: 56px; z-index: 10; display: flex; gap: 12px; overflow-x: auto; padding: 12px 0;
         background: var(--bg); scrollbar-width: none; }
.chip { flex: none; height: 32px; padding: 0 12px; border: 0; border-radius: 8px; background: var(--chip); cursor: pointer;
        font-weight: 500; }
.chip:hover { background: var(--surface-2); }
.chip.selected { background: var(--chip-on); color: var(--chip-on-text); }

/* ---- the grid of cards ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 40px 16px; padding-top: 12px; }
.card { min-width: 0; }
.thumb { position: relative; display: block; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: var(--skeleton); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-thumb:hover .thumb { border-radius: 0; transition: border-radius .2s; }
.badge { position: absolute; right: 6px; bottom: 6px; padding: 1px 5px; border-radius: 4px; background: rgba(0, 0, 0, .8);
         color: #fff; font-size: 12px; font-weight: 600; }
.badge.live { background: #cc3a3a; }
.card-body { display: flex; gap: 12px; margin-top: 12px; position: relative; }
.card-text { flex: 1; min-width: 0; padding-right: 24px; }
.card-title { margin: 0 0 4px; font-size: 16px; font-weight: 600; line-height: 22px;
              display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-channel, .card-meta { display: block; color: var(--muted); font-size: 14px; line-height: 20px; }
.card-channel:hover { color: var(--text); }
.card-later { position: absolute; right: -8px; top: -6px; width: 36px; height: 36px; opacity: 0; }
.card:hover .card-later, .card-later:focus, .card-later.saved { opacity: 1; }
@media (hover: none) { .card-later { opacity: 1; } }
.card-later.saved { color: var(--accent); }
.avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; object-fit: cover; background: var(--skeleton); }
.avatar.letter { display: grid; place-items: center; color: #fff; font-weight: 600; }
.avatar.small { width: 24px; height: 24px; font-size: 12px; }
.avatar.large { width: 80px; height: 80px; font-size: 32px; }
.nav-item .avatar.small { margin: 0; }

/* ---- loading ---- */
.skeleton .thumb, .skeleton-line { background: var(--skeleton); }
.skeleton-line { display: block; height: 16px; border-radius: 4px; margin: 12px 0 8px; width: 90%; }
.skeleton-line.short { width: 55%; }
.skeleton-line.wide { width: 70%; height: 24px; }
.card-title .skeleton-line { margin: 2px 0; height: 18px; }
.skeleton .thumb, .skeleton-line { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.note { color: var(--muted); }
.mode-note { margin: 12px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--surface); }
.failed { padding: 24px 0; }
.button { height: 36px; padding: 0 16px; border: 0; border-radius: 18px; background: var(--surface-2); cursor: pointer; font-weight: 500; }
.button:hover { background: var(--line); }
.button:disabled { opacity: .5; cursor: default; }
.text-button { padding: 0; border: 0; background: none; color: var(--link); cursor: pointer; font-weight: 600; }
.more-row { display: flex; justify-content: center; padding: 32px 0; }
.sentinel { width: 1px; height: 1px; }

/* ---- watch page ---- */
.watch { display: flex; gap: 24px; align-items: flex-start; padding-top: 16px; max-width: 1760px; }
.watch-main { flex: 1; min-width: 0; }
.watch-side { width: 402px; flex: none; }
.player { position: relative; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; }
.player-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-error { margin: 8px 0 0; }
.watch-title { margin: 12px 0 8px; font-size: 20px; line-height: 28px; font-weight: 700; }
.owner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.owner .avatar { width: 40px; height: 40px; }
.owner-text { min-width: 0; margin-right: 12px; }
.owner-name { font-weight: 600; font-size: 16px; }
.actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border: 0; border-radius: 18px;
        background: var(--surface-2); cursor: pointer; font-weight: 500; white-space: nowrap; }
.pill:hover { background: var(--line); }
.pill.selected { color: var(--accent); }
.pill .icon { width: 20px; height: 20px; }
.description { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--surface); }
.description-facts { font-weight: 600; margin-bottom: 4px; }
.description-text { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4;
                    -webkit-box-orient: vertical; overflow: hidden; }
.description.open .description-text { display: block; }
.description a, .comment-text a { color: var(--link); }
.timestamp { padding: 0; border: 0; background: none; color: var(--link); cursor: pointer; font: inherit; }
.section-title { font-size: 16px; font-weight: 700; margin: 0; }
.comments { margin-top: 24px; }
.comments .section-title { margin-bottom: 16px; font-size: 20px; }
.comment-list { list-style: none; margin: 0; padding: 0; }
.comment { display: flex; gap: 16px; margin-bottom: 20px; }
.comment .avatar.small { width: 40px; height: 40px; font-size: 16px; }
.comment-body { min-width: 0; }
.comment-head { display: flex; gap: 8px; font-size: 13px; }
.comment-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 2px 0 6px; }
.comment-foot { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.comment-foot .icon { width: 16px; height: 16px; }
.up-next { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); }
@media (max-width: 1100px) {
  .watch { flex-direction: column; }
  .watch-side { width: 100%; }
}

/* ---- lists: results, related, library ---- */
.page-title { font-size: 20px; margin: 16px 0 8px; }
.wide-list { display: flex; flex-direction: column; gap: 16px; padding-top: 8px; }
.wide-card { display: flex; gap: 16px; position: relative; max-width: 1100px; }
.wide-thumb { width: 360px; flex: none; }
.wide-text { min-width: 0; flex: 1; padding-right: 32px; }
.wide-text .card-title { font-size: 18px; line-height: 26px; }
.wide-description { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.wide-remove { position: absolute; right: 0; top: 0; }
.wide-list.compact { gap: 8px; }
.wide-card.compact .wide-thumb { width: 168px; }
.wide-card.compact .thumb { border-radius: 8px; }
.wide-card.compact .card-title { font-size: 14px; line-height: 20px; }
.wide-card.compact .card-channel, .wide-card.compact .card-meta { font-size: 12px; line-height: 18px; }
.wide-card.compact .wide-text { padding-right: 0; }
@media (max-width: 640px) {
  .wide-card:not(.compact) { flex-direction: column; }
  .wide-card:not(.compact) .wide-thumb { width: 100%; }
}
.library-head { display: flex; align-items: center; justify-content: space-between; max-width: 1100px; }

/* ---- channel page ---- */
.channel-head { display: flex; align-items: center; gap: 24px; padding: 24px 0 16px; }
.channel-head .page-title { margin: 0 0 4px; font-size: 28px; }

/* ---- dialogs and messages ---- */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .55); }
.dialog { position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 24px));
          max-height: calc(100vh - 48px); overflow-y: auto; padding: 20px 24px; border-radius: 14px; background: var(--surface);
          box-shadow: 0 16px 48px rgba(0, 0, 0, .5); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.setting { margin-top: 20px; }
.setting h3 { margin: 0 0 8px; font-size: 15px; }
.setting .chips { position: static; padding: 0; background: none; }
.key-form { display: flex; gap: 8px; }
.key-form input { flex: 1; min-width: 0; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
                  background: var(--bg); color: var(--text); font: inherit; }
.mode-line { margin: 0 0 8px; }
.shortcuts { border-collapse: collapse; margin-top: 12px; }
.shortcuts td { padding: 6px 16px 6px 0; }
kbd { display: inline-block; min-width: 24px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 6px;
      background: var(--bg); font: 600 13px/1.4 ui-monospace, monospace; text-align: center; }
.toast { position: fixed; left: 24px; bottom: 24px; z-index: 50; padding: 12px 20px; border-radius: 8px;
         background: var(--text); color: var(--bg); font-weight: 500; }
/* Kept in the accessibility tree (a hidden live region would not be read out). */
.toast:not(.shown) { opacity: 0; padding: 0; pointer-events: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.content:focus { outline: none; }
