/* ============================================================
   Tokens — Bilibili on Meta Display Glasses (additive HUD)
   Black = transparent. Surfaces are dark grays that emit light.
   Identity: Bilibili pink focus glow over the see-through canvas.
   ============================================================ */
:root {
  --bg: #000000;            /* transparent on the additive display */
  --surface: #17181C;       /* cards, chips — reads as opaque */
  --surface-2: #23252B;     /* raised / inside-card */
  --brand: #FB7299;         /* Bilibili pink — primary accent + focus */
  --brand-2: #3FBEF0;       /* Bilibili blue — UP names, links */
  --text: #FFFFFF;
  --text-2: #D2D6DD;
  --text-3: #939AA4;
  --danger: #FF5A7A;

  --t-title: 24px;
  --t-h2: 20px;
  --t-body: 17px;
  --t-meta: 15px;
  --t-cap: 13px;

  --r-lg: 16px;
  --r-md: 12px;
  --r-pill: 999px;
  --btn-h: 88px;
  --gap: 12px;

  --dur: 300ms;
  --dur-focus: 475ms;
  --ease: cubic-bezier(0.6, 0, 0.4, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 600px; height: 600px; overflow: hidden;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app-root { width: 600px; height: 600px; padding: 8px; }
.screen { display: flex; flex-direction: column; height: 100%; gap: 10px; }
.hidden { display: none !important; }

/* ---------------- Header (transparent; chips carry the surface) -------- */
.header {
  flex: 0 0 56px; height: 56px;
  display: flex; align-items: center; gap: 8px; padding: 0 4px;
}
.title {
  flex: 1; min-width: 0;
  font-size: var(--t-title); font-weight: 700; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------------- Chips (header buttons) ------------------------------- */
.badge {
  flex: 0 0 auto;
  font-size: var(--t-meta); font-weight: 600; color: var(--text-2);
  background: var(--surface); padding: 10px 16px; border-radius: var(--r-pill);
  border: 2px solid transparent; cursor: pointer; white-space: nowrap;
  transition: transform var(--dur) var(--ease), border-color var(--dur);
}
#userBadge { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.badge-ico-btn { display: flex; align-items: center; padding: 8px 12px; }
.badge-ico-btn .btn-ico { width: 20px; height: 20px; }

/* ---------------- Focus (the signature: pink) ------------------------- */
.focusable:focus, .focusable:focus-within {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand), 0 0 18px rgba(251, 114, 153, 0.55);
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------------- Scroll containers ----------------------------------- */
.scroll {
  position: relative; flex: 1;
  overflow-y: auto; overflow-x: hidden;
  padding: 4px 4px 20px;
  scrollbar-width: none;        /* Firefox — D-pad scrolls; the bar is just clutter */
  -ms-overflow-style: none;     /* old Edge */
}
.scroll::-webkit-scrollbar { width: 0; height: 0; }  /* Chrome/Safari/Edge */

/* ---------------- Feed grid (2-col cards, like the B站 app) ----------- */
/* flex-wrap (not grid): with a definite 50% card width the padding-ratio thumb
   resolves correctly; grid auto-rows mis-size width-dependent heights. */
#feed { display: flex; flex-wrap: wrap; gap: var(--gap); align-content: flex-start; align-items: flex-start; }
.placeholder {
  flex: 0 0 100%;
  color: var(--text-3); font-size: var(--t-body); padding: 40px 16px; text-align: center;
}

.card {
  background: var(--surface); border-radius: var(--r-lg);
  border: 2px solid transparent; overflow: hidden; cursor: pointer;
  display: block;
  transition: transform var(--dur-focus) var(--ease), border-color var(--dur);
}
#feed .card, #detailRelated .card { width: calc(50% - 6px); }
/* padding-top ratio box (not aspect-ratio: that mis-sizes grid tracks) */
.card-thumb-wrap { position: relative; width: 100%; height: 0; padding-top: 56.25%; background: var(--surface-2); }
.card-thumb {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  object-fit: cover; display: block; transition: filter var(--dur);
}
.card-dur {
  position: absolute; right: 6px; bottom: 6px;
  font-size: var(--t-cap); font-weight: 600; color: #fff;
  background: rgba(0, 0, 0, 0.78); padding: 2px 7px; border-radius: 6px;
}
.card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 5px; }
.card-title {
  font-size: var(--t-body); font-weight: 700; line-height: 1.3; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.6em;
}
.card-meta {
  font-size: var(--t-meta); color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card.focusable:focus { transform: scale(0.97); }
.card.focusable:focus .card-thumb { filter: brightness(1.12); }

/* ---------------- Buttons (one standard) ------------------------------ */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--btn-h); padding: 0 20px;
  font-size: var(--t-body); font-weight: 700; color: var(--text);
  background: var(--surface); border: 2px solid transparent; border-radius: var(--r-lg);
  cursor: pointer; transition: transform var(--dur-focus) var(--ease), border-color var(--dur);
}
.btn.primary { background: var(--brand); color: #fff; }
.btn-ico { width: 22px; height: 22px; fill: currentColor; flex: 0 0 auto; }
.btn.danger { color: var(--danger); }
.btn.focusable:focus { transform: scale(0.93); }
/* pink button needs a light halo — a pink glow on pink is invisible */
.btn.primary.focusable:focus {
  border-color: #fff;
  box-shadow: 0 0 0 2px #fff, 0 0 22px rgba(251, 114, 153, 0.85);
}

/* ---------------- Detail ---------------------------------------------- */
/* Natural 16:9. aspect-ratio reserves the box even before the image loads,
   so there's no reflow/clip (the old bug); placeholder bg shows meanwhile. */
.detail-thumb {
  width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block;
  border-radius: var(--r-lg); background: var(--surface-2);
  margin-top: 4px;
}
.detail-up { font-size: var(--t-meta); color: var(--brand-2); font-weight: 700; margin-top: 12px; }
.detail-stats { display: flex; gap: 20px; margin: 8px 0; }
.stat { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-meta); color: var(--text-2); }
.stat-ico { width: 18px; height: 18px; fill: currentColor; flex: 0 0 auto; }
.detail-desc {
  font-size: var(--t-cap); color: var(--text-3); line-height: 1.55; white-space: pre-wrap;
  margin: 10px 0 4px;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
}
.detail-section { font-size: var(--t-h2); font-weight: 700; color: var(--text); margin: 16px 0 10px; }
.action-row { display: flex; gap: 12px; margin: 12px 0 4px; }
.action-row .btn { flex: 1; }
.icon-btn {
  flex: 0 0 88px; width: 88px; height: 88px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text); background: var(--surface);
  border: 2px solid transparent; border-radius: var(--r-lg); cursor: pointer;
  transition: transform var(--dur-focus) var(--ease), border-color var(--dur),
    background var(--dur), color var(--dur);
}
.icon-btn svg { width: 30px; height: 30px; fill: currentColor; display: block; }
.icon-btn.active { color: var(--brand); background: rgba(251, 114, 153, 0.16); border-color: var(--brand); }
.icon-btn.focusable:focus {
  transform: scale(0.93); border-color: var(--brand);
  box-shadow: 0 0 18px rgba(251, 114, 153, 0.55);
}
#detailRelated { display: flex; flex-wrap: wrap; gap: var(--gap); align-items: flex-start; }

/* ---------------- Comments (read-only) -------------------------------- */
#commentsBody { display: flex; flex-direction: column; gap: 10px; }
.comment {
  display: flex; gap: 10px; padding: 12px;
  background: var(--surface); border-radius: var(--r-md);
  border: 2px solid transparent;
  transition: border-color var(--dur);
}
.comment-face {
  flex: 0 0 44px; width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface-2); object-fit: cover;
}
.comment-main { flex: 1; min-width: 0; }
.comment-head { display: flex; align-items: baseline; gap: 8px; }
.comment-name {
  font-size: var(--t-meta); font-weight: 700; color: var(--brand-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.comment-time { flex: 0 0 auto; font-size: var(--t-cap); color: var(--text-3); }
.comment-text {
  font-size: var(--t-body); line-height: 1.45; color: var(--text);
  margin: 5px 0 7px; white-space: pre-wrap; word-break: break-word;
}
.comment-meta { display: flex; align-items: center; gap: 18px; font-size: var(--t-cap); color: var(--text-3); }
.comment-meta .stat { font-size: var(--t-cap); color: var(--text-3); gap: 5px; }
.comment-meta .stat-ico { width: 15px; height: 15px; }

/* ---------------- Player (video fills; floating back; click to toggle) */
.screen.player { position: relative; gap: 0; }
.screen.player .header {
  position: absolute; top: 12px; left: 12px; right: 12px;
  height: auto; flex: none; z-index: 5; pointer-events: none;
}
.screen.player .header .badge,
.screen.player .header .chip-btn { pointer-events: auto; }

/* Player header tools (top-right): danmaku + resolution toggles */
.player-tools { margin-left: auto; display: flex; gap: 8px; pointer-events: none; }
.chip-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 48px; height: 48px; padding: 0 14px;
  font-size: var(--t-meta); font-weight: 700; color: #fff;
  background: rgba(0, 0, 0, 0.5); border: 2px solid transparent; border-radius: var(--r-pill);
  cursor: pointer; white-space: nowrap;
  transition: border-color var(--dur), background var(--dur), color var(--dur);
}
.chip-btn.active { color: var(--brand); border-color: var(--brand); background: rgba(251, 114, 153, 0.2); }
.chip-btn.focusable:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand), 0 0 18px rgba(251, 114, 153, 0.55);
}

/* Danmaku — scrolling comments confined to the upper quarter of the frame */
.danmaku-layer {
  position: absolute; top: 0; left: 0; right: 0; height: 25%;
  overflow: hidden; pointer-events: none; z-index: 3;
}
.dm {
  position: absolute; left: 0; white-space: nowrap; will-change: transform;
  font-size: 20px; font-weight: 700; color: #fff; line-height: 1.1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.85);
}

.video-wrap {
  position: relative; flex: 1; width: 100%; height: 100%;
  background: var(--bg); border-radius: var(--r-lg); overflow: hidden;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  border: 2px solid transparent;
}
.video-wrap.focusable:focus { box-shadow: inset 0 0 0 2px rgba(251, 114, 153, 0.7); }
#player { width: 100%; height: 100%; object-fit: contain; background: #000; }

.play-indicator {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity var(--dur);
}
.play-indicator svg {
  width: 96px; height: 96px; fill: #fff; display: block;
  filter: drop-shadow(0 2px 14px rgba(0, 0, 0, 0.8));
}
.play-indicator.show { opacity: 0.95; }

.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: var(--t-body); color: var(--text-2); text-align: center; padding: 16px;
  pointer-events: none; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7);
}

/* Scrubber — auto-hides during playback, revealed on D-pad / pause */
.player-bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  padding: 22px 18px 16px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.74), rgba(0, 0, 0, 0));
  opacity: 0; transition: opacity var(--dur); pointer-events: none;
}
.player-bar.show { opacity: 1; }
.pbar-track {
  position: relative; height: 6px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.28);
}
.pbar-buffered, .pbar-played {
  position: absolute; left: 0; top: 0; height: 100%; width: 0; border-radius: 3px;
}
.pbar-buffered { background: rgba(255, 255, 255, 0.45); }
.pbar-played { background: var(--brand); }
.pbar-knob {
  position: absolute; top: 50%; left: 0; width: 16px; height: 16px; margin-left: -8px;
  border-radius: 50%; background: #fff; transform: translateY(-50%);
  box-shadow: 0 0 0 2px var(--brand), 0 1px 4px rgba(0, 0, 0, 0.5);
}
.pbar-times {
  display: flex; justify-content: space-between; margin-top: 9px;
  font-size: var(--t-cap); font-weight: 600; color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

/* ---------------- Toast ----------------------------------------------- */
.toast {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  max-width: 536px; z-index: 30;
  font-size: var(--t-meta); font-weight: 600; color: #fff;
  background: var(--surface-2); border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 12px 20px; border-radius: 18px; text-align: center; line-height: 1.4;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
}

/* ---------------- Account --------------------------------------------- */
.account-body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center; padding: 16px;
}
.account-face {
  width: 120px; height: 120px; border-radius: 50%;
  background: var(--surface-2); object-fit: cover; display: none;
  border: 3px solid var(--brand);
}
.account-name { font-size: 26px; font-weight: 700; }
.account-meta { font-size: var(--t-body); color: var(--text-3); }
.account-body .btn { width: 100%; max-width: 320px; margin-top: 16px; }

/* ---------------- Login ----------------------------------------------- */
.login-body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; text-align: center; padding: 16px;
}
.login-step { font-size: var(--t-body); color: var(--text-2); }
.login-url {
  font-size: var(--t-h2); font-weight: 700; color: var(--brand);
  background: var(--surface); border-radius: var(--r-md); padding: 16px 20px; word-break: break-all;
}
.login-status { font-size: var(--t-body); font-weight: 700; }
.login-status.pending { color: #F0883A; }
.login-status.ok { color: var(--brand); }
.login-status.err { color: var(--danger); }

/* ---------------- Debug log (hidden; toggle with `~`) ----------------- */
.log {
  flex: 0 0 64px; overflow-y: auto; font-size: var(--t-cap); line-height: 1.5;
  color: var(--text-3); background: var(--surface); border-radius: var(--r-md);
  padding: 6px 10px; white-space: pre-wrap; word-break: break-all; display: none;
}
body.debug .log { display: block; }
