:root{
  --bg:#0f0f0f; --surface:#181818; --surface-2:#212121; --card:#272727;
  --text:#f1f1f1; --muted:#a9a9a9; --dim:#717171; --accent:#ff0000; --accent-2:#f0f0f0;
  --chip:#272727; --chip-hover:#3f3f3f; --chip-on:#f1f1f1; --chip-on-tx:#0f0f0f;
  --radius:12px; --shadow:0 4px 16px rgba(0,0,0,.5);
  --bar-h:56px;
}
*{box-sizing:border-box}
html{scroll-behavior:smooth}
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:"Roboto","Noto Sans TC","PingFang TC","Microsoft JhengHei",system-ui,Arial,sans-serif;
  -webkit-font-smoothing:antialiased;
}
a{color:inherit;text-decoration:none}
button{font-family:inherit}

/* ---------- App bar ---------- */
.appbar{
  position:sticky; top:0; z-index:50; height:var(--bar-h);
  display:grid; grid-template-columns:1fr auto 1fr; align-items:center;
  padding:0 12px; gap:12px;
  background:rgba(15,15,15,.95); backdrop-filter:blur(8px);
  border-bottom:1px solid #272727;
}
.appbar-left{display:flex;align-items:center;gap:6px;justify-self:start}
.appbar-center{justify-self:center;max-width:640px;width:100%}
.appbar-right{display:flex;align-items:center;gap:6px;justify-self:end}

.icon-btn{
  width:40px;height:40px;border-radius:50%;border:0;background:transparent;color:var(--text);
  display:grid;place-items:center;cursor:pointer;transition:background .15s;
}
.icon-btn:hover{background:var(--surface-2)}
.brand{display:flex;align-items:center;gap:6px;cursor:pointer;padding:0 6px}
.brand-badge{
  width:32px;height:22px;border-radius:6px;background:var(--accent);
  display:grid;place-items:center;box-shadow:0 1px 3px rgba(0,0,0,.6);
}
.brand-text{font-weight:700;font-size:18px;letter-spacing:-.5px}

.search{display:flex;align-items:center;height:40px}
.search-field{position:relative;flex:1;display:flex;min-width:0}
.search input{
  flex:1;height:40px;background:var(--surface-2);border:1px solid var(--surface-2);
  border-radius:20px;color:var(--text);padding:0 16px;font-size:15px;outline:none;transition:border-color .15s;
}
.search input:focus{border-color:#888}

/* ---------- Category chips ---------- */
.chips{
  position:sticky;top:var(--bar-h);z-index:40;display:flex;gap:10px;
  padding:10px 24px;overflow-x:auto;background:rgba(15,15,15,.9);backdrop-filter:blur(8px);
  scrollbar-width:none;
}
.chips::-webkit-scrollbar{display:none}
.chip{
  flex:0 0 auto;height:32px;padding:0 14px;border-radius:8px;border:0;cursor:pointer;
  background:var(--chip);color:var(--text);font-size:14px;white-space:nowrap;transition:background .15s;
}
.chip:hover{background:var(--chip-hover)}
.chip.on{background:var(--chip-on);color:var(--chip-on-tx);font-weight:600}

/* ---------- Content ---------- */
.content{padding:8px 24px 40px;max-width:1800px;margin:0 auto}

/* Player */
.player-wrap{margin-top:12px}
.player-layout{display:grid;gap:24px}
@media (min-width:1080px){.player-layout{grid-template-columns:minmax(0,1fr) 360px}}
.player-frame{position:relative;aspect-ratio:16/9;background:#000;border-radius:var(--radius);overflow:hidden;box-shadow:var(--shadow)}
.player-frame iframe{position:absolute;inset:0;width:100%;height:100%;border:0}
/* The YT API replaces our #ytPlayer div with its own wrapper <div> (which
   holds the actual player <iframe>). Size EVERY div/iframe layer of the
   frame: a statically-positioned wrapper with a 100%x100% iframe collapses
   to 0x0 -> audio yes, no picture. */
.player-frame>div{position:absolute;inset:0;width:100%;height:100%}
.player-frame iframe{position:absolute;inset:0;width:100%;height:100%;border:0}
.player-frame video.local-video{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;background:#000;display:block}
.player-loading{position:absolute;inset:0;display:grid;place-items:center;background:rgba(0,0,0,.85);z-index:2}
/* The display:grid above beats the UA [hidden]{display:none} rule, so the
   overlay must be explicitly hidden here or it stays pinned over the video
   (spinner always visible, picture dimmed under the 85%-black layer). */
.player-loading[hidden]{display:none}
.player-loading .spin{width:40px;height:40px;border-radius:50%;border:3px solid #2a2a2a;border-top-color:var(--accent);animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
.player-title{font-size:22px;font-weight:700;margin:14px 0 8px;line-height:1.25}
.player-meta{display:flex;align-items:center;gap:8px;color:var(--dim);flex-wrap:wrap;font-size:13px}
.player-channel{font-weight:600;color:var(--muted);font-size:13px}
.player-cat{color:var(--dim);font-size:13px}

.upnext{margin-top:22px}
.upnext-h{font-size:15px;font-weight:700;margin:0 0 12px;color:var(--text)}
.upnext-list{display:grid;gap:10px;grid-template-columns:repeat(auto-fill,minmax(280px,1fr))}

/* Browse + grid */
.browse{margin-top:8px}
.browse-head{display:flex;align-items:baseline;gap:10px;margin:18px 0 14px}
.browse-head h2{font-size:15px;font-weight:600;margin:0;color:var(--muted)}
.count{color:var(--dim);font-size:12px}
.grid{display:grid;gap:20px 16px;grid-template-columns:repeat(auto-fill,minmax(240px,1fr))}

/* Cards */
.card{background:var(--surface);border-radius:var(--radius);overflow:hidden;cursor:pointer;transition:transform .15s,box-shadow .15s}
.card:hover{transform:translateY(-3px);box-shadow:var(--shadow)}
.card:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.thumb{position:relative;aspect-ratio:16/9;background:#000;overflow:hidden}
/* shimmer while the thumbnail is still loading */
.thumb::before{
  content:"";position:absolute;inset:0;
  background:linear-gradient(100deg,#1a1a1a 30%,#272727 50%,#1a1a1a 70%);
  background-size:200% 100%;animation:shimmer 1.1s linear infinite;
}
@keyframes shimmer{to{background-position:-200% 0}}
.thumb img{width:100%;height:100%;object-fit:cover;display:block;opacity:0;transition:opacity .25s}
.thumb img.loaded{opacity:1}
.thumb:has(img.loaded)::before{display:none}
.thumb .dur{
  position:absolute;bottom:8px;right:8px;background:rgba(0,0,0,.75);color:#fff;font-size:11px;
  padding:2px 6px;border-radius:4px;letter-spacing:.3px;z-index:1;
}
/* featured star (icon only, top-right of the thumb) */
.thumb-star{
  position:absolute;top:8px;right:8px;z-index:2;width:30px;height:30px;border-radius:50%;
  border:0;background:rgba(0,0,0,.55);color:rgba(255,255,255,.85);
  font-size:14px;line-height:1;display:grid;place-items:center;cursor:pointer;padding:0;
}
.thumb-star:hover{background:rgba(0,0,0,.85)}
.thumb-star.is-on{color:#ffd23f}
/* Now-playing indicator: shows which card is the current video */
.card .np{
  position:absolute;left:8px;bottom:8px;z-index:2;display:none;align-items:center;gap:6px;
  background:var(--accent);color:#fff;font-size:11px;font-weight:700;letter-spacing:.3px;
  padding:4px 9px;border-radius:6px;box-shadow:0 2px 8px rgba(0,0,0,.5);
}
.card.is-playing .np{display:flex}
.card.is-playing .dur{opacity:0}              /* keep corner uncluttered */
.card.is-playing .thumb{box-shadow:inset 0 0 0 2px var(--accent)}
.card-body{display:block;padding:10px 12px 12px}
.card-text{min-width:0}
.card-title{font-size:14.5px;font-weight:500;line-height:1.3;margin:0 0 4px;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.card-sub{font-size:12px;color:var(--dim);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.card-sub .dot{margin:0 5px;color:var(--dim)}

/* Up-next small cards */
.unext{display:flex;gap:10px;background:var(--surface);border-radius:10px;overflow:hidden;cursor:pointer;transition:background .15s}
.unext:hover{background:var(--surface-2)}
.unext .thumb{aspect-ratio:16/9;flex:0 0 160px;border-radius:0}
.unext .body{padding:8px 8px 8px 0;min-width:0}
.unext .t{font-size:14px;font-weight:500;line-height:1.3;margin:0 0 4px;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.unext .c{font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

.empty{color:var(--dim);text-align:center;padding:60px 0;font-size:15px}

.foot{display:flex;flex-direction:column;gap:4px;align-items:center;padding:24px;color:var(--dim);font-size:13px;border-top:1px solid #1f1f1f;margin-top:20px}
.foot-sub{font-size:11px}

.loading{color:var(--dim);text-align:center;padding:80px 0}

@media (max-width:640px){
  .appbar{grid-template-columns:auto minmax(0,1fr) auto;gap:8px}
  .brand-text{display:none}
  .appbar-center{max-width:none;min-width:0;width:100%}
  .search input{padding:0 12px;font-size:14px}
  .content{padding:8px 14px calc(32px + env(safe-area-inset-bottom,0px))}
  .chips{padding:8px 14px}
  .grid{gap:14px 10px}
  .card-title{font-size:13px}
  .player-title{font-size:18px}
  .upnext-list{grid-template-columns:1fr}
}

/* Accessibility: honor reduced-motion preference */
@media (prefers-reduced-motion: reduce){
  html{scroll-behavior:auto}
  .card,.chip{transition:none}
  .player-loading .spin,.thumb::before{animation:none}
  .thumb::before{display:none}
}

/* Floating Hermes chat button (-> /chat) */
.hermes-fab{position:fixed;right:18px;bottom:calc(18px + env(safe-area-inset-bottom));z-index:60;
  display:flex;align-items:center;gap:6px;background:linear-gradient(135deg,#f85149,#d24440);
  color:#fff;text-decoration:none;padding:11px 18px;border-radius:99px;font-size:19px;
  box-shadow:0 6px 20px rgba(0,0,0,.45);transition:transform .15s ease,box-shadow .15s ease}
.hermes-fab:hover{transform:translateY(-2px) scale(1.04);box-shadow:0 10px 26px rgba(248,81,73,.4)}
.hermes-fab-label{font-size:13px;font-weight:600;letter-spacing:.3px}
@media (max-width:640px){
  .hermes-fab{right:12px;padding:10px 14px}
  .hermes-fab-label{display:none}
}

/* search FAB (neutral look vs the red chat FAB) + its popover */
.fab-neutral{background:var(--surface);border:1px solid var(--surface-2);color:var(--text)}
body:not(.hide-bars) #searchFab{display:none}
/* three-FAB stack when bars are hidden: settings 18px, chat 70px, search 140px */
body.hide-bars #searchFab{bottom:calc(140px + env(safe-area-inset-bottom))}
body:not(.hide-bars) #searchPop{display:none}
.search-pop{position:fixed;top:14px;left:50%;transform:translateX(-50%);z-index:95;
  display:flex;align-items:center;gap:8px;width:min(560px,94vw);padding:10px 12px;
  background:var(--surface);border:1px solid var(--surface-2);border-radius:12px;
  box-shadow:0 12px 40px rgba(0,0,0,.5)}
.search-pop[hidden]{display:none}
.search-pop input{flex:1;min-width:0;height:40px;padding:0 12px;border-radius:9px;
  border:1px solid var(--surface-2);background:var(--bg);color:var(--text);font-size:14px;outline:none}
.search-pop input:focus{border-color:var(--accent)}
.search-pop button{width:36px;height:36px;flex:0 0 auto;border:0;border-radius:50%;
  background:var(--surface-2);color:var(--text);cursor:pointer;font-size:14px}

/* Floating Hermes chat widget (non-modal — the app keeps working underneath) */
.chat-widget{position:fixed;right:18px;bottom:calc(76px + env(safe-area-inset-bottom));z-index:80;
  width:min(380px,calc(100vw - 24px));height:min(520px,calc(100vh - 150px));
  display:flex;flex-direction:column;background:var(--surface);border:1px solid var(--surface-2);
  border-radius:14px;box-shadow:0 14px 44px rgba(0,0,0,.5);overflow:hidden}
.chat-widget[hidden]{display:none}
.cw-head{display:flex;align-items:center;justify-content:space-between;padding:10px 14px;
  border-bottom:1px solid var(--surface-2)}
.cw-title{font-weight:700;font-size:15px}
.cw-x{width:32px;height:32px;border-radius:50%;border:0;background:var(--surface-2);
  color:var(--text);cursor:pointer;font-size:14px}
.cw-x:hover{background:var(--chip-hover)}
.cw-chips{display:flex;gap:6px;padding:10px 12px;overflow-x:auto;border-bottom:1px solid var(--surface-2);
  scrollbar-width:none}
.cw-chips::-webkit-scrollbar{display:none}
.cw-chip{flex:0 0 auto;display:inline-flex;align-items:center;gap:5px;height:32px;padding:0 12px;
  border-radius:99px;border:1px solid var(--surface-2);background:transparent;color:var(--text);
  font-size:13px;cursor:pointer;white-space:nowrap}
.cw-chip:hover{background:var(--chip-hover)}
.cw-chip.chat-chip{border-color:var(--accent);color:var(--accent)}
.cw-log{flex:1;overflow-y:auto;padding:12px;display:flex;flex-direction:column;gap:8px}
.cw-msg{max-width:90%;padding:8px 12px;border-radius:10px;white-space:pre-wrap;word-wrap:break-word;font-size:14px}
.cw-msg.user{align-self:flex-end;background:var(--accent);color:#fff}
.cw-msg.bot{align-self:flex-start;background:var(--surface-2)}
.cw-msg.sys{align-self:center;color:var(--muted);font-size:12px;background:transparent}
.cw-msg.err{align-self:flex-start;border:1px solid #ff4d4d;color:#ff9c9c}
.cw-msg.pending{color:var(--muted);font-style:italic}
.cw-inrow{display:flex;gap:8px;padding:10px 12px;border-top:1px solid var(--surface-2)}
.cw-inrow input{flex:1;height:40px;padding:0 12px;border-radius:9px;border:1px solid var(--surface-2);
  background:var(--bg);color:var(--text);font-size:14px;outline:none}
.cw-inrow input:focus{border-color:var(--accent)}
.cw-inrow button{width:44px;height:40px;border:0;border-radius:9px;background:var(--accent);
  color:#fff;font-size:16px;cursor:pointer}
.cw-inrow button:disabled{opacity:.5;cursor:default}
/* when both FABs are stacked (bars hidden), lift the widget clear of them */
body.hide-bars .chat-widget{bottom:calc(148px + env(safe-area-inset-bottom))}
@media (max-width:640px){
  .chat-widget{right:12px;left:12px;width:auto;height:min(56vh,440px);bottom:calc(64px + env(safe-area-inset-bottom))}
  body.hide-bars .chat-widget{bottom:calc(136px + env(safe-area-inset-bottom))}
}

/* ---------- cross-platform search: add-to-list + remote section + embed/external player ---------- */
.add-btn{margin-top:6px;width:100%;height:30px;border-radius:8px;border:1px solid var(--surface-2);
  background:var(--surface-2);color:var(--text);font-size:12px;cursor:pointer;white-space:nowrap}
.add-btn:hover:not(:disabled){border-color:var(--accent);color:var(--accent)}
.add-btn:disabled{opacity:.6;cursor:default}
.remote-sec{margin-top:18px;padding-top:14px;border-top:1px dashed var(--surface-2)}
.remote-h{font-size:13px;color:var(--muted);margin-bottom:10px;letter-spacing:.3px}
.remote-more{display:block;width:100%;margin-top:14px;height:40px;border-radius:10px;
  border:1px solid var(--surface-2);background:transparent;color:var(--text);
  font-size:14px;cursor:pointer}
.remote-more:hover{border-color:var(--accent);color:var(--accent)}
.embed-video{position:absolute;inset:0;width:100%;height:100%;border:0;background:#000}
.ext-overlay{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;
  justify-content:center;gap:10px;background:#0d0d10;padding:20px;text-align:center}
.ext-title{font-size:16px;font-weight:600;color:var(--text);max-width:520px}
.ext-sub{font-size:13px;color:var(--muted)}
.ext-open{display:inline-block;margin-top:6px;padding:10px 22px;border-radius:99px;
  background:var(--accent);color:#fff;text-decoration:none;font-size:14px}
.ext-open:hover{filter:brightness(1.15)}

/* ---------- home-featured (精選): star lives on the card thumbnail (.thumb-star) ---------- */
.sd-add-sm{height:32px;padding:0 14px;border-radius:8px;border:1px solid var(--surface-2);
  background:var(--surface-2);color:var(--text);font-size:13px;cursor:pointer}
.sd-add-sm:hover{border-color:var(--accent);color:var(--accent)}
.feat-hint{font-size:12px;color:var(--muted);margin:0 0 10px}

/* ---------- device-aware UX pass ---------- */
/* touch: kill the blue flash + the 300ms double-tap-zoom delay on interactive elements */
button,.card,.chip,.unext,.brand,.ext-open,.remote-more{
  -webkit-tap-highlight-color:transparent;touch-action:manipulation;
}

/* coarse pointers: comfortable 44px-class tap targets */
@media (pointer:coarse){
  .chip{height:40px;padding:0 16px}
  .icon-btn{width:44px;height:44px}
  .search input,.search-pop input{height:44px}
  .add-btn{height:34px;font-size:13px}
  .thumb-star{width:38px;height:38px;font-size:16px}
  .sd-close{width:44px;height:44px}
  .cw-x{width:40px;height:40px}
}

/* category chips: fade the row at the edges when it overflows (class is
   toggled by JS only when scrollWidth > clientWidth) */
.chips--scroll{
  -webkit-mask-image:linear-gradient(90deg,transparent 0,#000 14px,#000 calc(100% - 14px),transparent 100%);
  mask-image:linear-gradient(90deg,transparent 0,#000 14px,#000 calc(100% - 14px),transparent 100%);
}
.chip:focus-visible,.add-btn:focus-visible,.remote-more:focus-visible,.icon-btn:focus-visible,.thumb-star:focus-visible{
  outline:2px solid var(--accent);outline-offset:2px}

/* bottom safe area (notch / home indicator) */
.foot{padding-bottom:calc(24px + env(safe-area-inset-bottom,0px))}
.content{padding-bottom:calc(40px + env(safe-area-inset-bottom,0px))}

/* very short landscape phones: don't let the 16:9 player eat the whole screen */
@media (max-height:430px) and (orientation:landscape){
  .player-frame{aspect-ratio:auto;height:min(50vh,300px)}
  .player-title{font-size:16px;margin:8px 0 4px}
  .upnext{margin-top:12px}
}

/* ultrawide / 4K: a little more room for the grid */
@media (min-width:2200px){ .content{max-width:2100px} }

/* dynamic viewport height where full-height matters (mobile browser chrome) */
.chat-widget{height:min(520px,calc(100vh - 150px));height:min(520px,calc(100dvh - 150px))}
@media (max-width:640px){
  .chat-widget{height:min(56vh,440px);height:min(56dvh,440px)}
}
