:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5d6b7a;
  --border: #dde3ea;
  --accent: #0f7c8c;
  --accent-text: #ffffff;
  --accent-soft: #e3f3f5;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --surface: #1a2129;
    --text: #e6ebf0;
    --muted: #9aa7b4;
    --border: #2b3540;
    --accent: #3fb6c6;
    --accent-text: #0b1418;
    --accent-soft: #173238;
    --danger: #ff8a7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
[hidden] { display: none !important; }
a { color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; }
.brand-mark { width: 26px; height: 26px; fill: var(--accent); flex: none; }
.user { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: var(--muted); }
.user img { width: 30px; height: 30px; border-radius: 50%; }
@media (max-width: 600px) {
  .topbar { padding: 10px 16px; }
  .brand span { font-size: .95rem; }
  #user-name { display: none; }
}

main { max-width: 1200px; margin: 0 auto; padding: 24px; }
@media (max-width: 600px) { main { padding: 16px; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-size: .9rem; font-weight: 600; text-decoration: none;
  cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--accent-soft); color: var(--accent); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); padding: 6px 12px; }
.btn-ghost:hover { color: var(--text); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- sign-in ---------- */
.signin {
  max-width: 420px; margin: 10vh auto 0; padding: 32px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); text-align: center;
}
.signin h1 { margin: 0 0 8px; font-size: 1.4rem; }
.signin p { color: var(--muted); margin: 0 0 24px; }
#google-button { display: flex; justify-content: center; min-height: 44px; }
.error { color: var(--danger); font-weight: 500; }
.signin .error { margin: 16px 0 0; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; margin-bottom: -1px;
  border: none; border-bottom: 3px solid transparent; background: none;
  color: var(--muted); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab .badge {
  min-width: 24px; padding: 1px 8px; border-radius: 999px;
  background: var(--border); color: var(--muted); font-size: .75rem; text-align: center;
}
.tab[aria-selected="true"] .badge { background: var(--accent-soft); color: var(--accent); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 8px; }
#search {
  flex: 1 1 260px; max-width: 420px;
  padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.count { color: var(--muted); font-size: .85rem; margin: 0 0 16px; }
.empty { color: var(--muted); text-align: center; padding: 48px 0; }

/* ---------- grid ---------- */
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.card {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.thumb {
  position: relative; display: block; aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, var(--accent-soft), var(--border));
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.play {
  position: absolute; inset: 0; margin: auto; width: 56px; height: 56px; border-radius: 50%;
  background: rgba(0, 0, 0, .55); transition: transform .15s, background .15s;
}
.play::after {
  content: ""; position: absolute; left: 22px; top: 17px;
  border-style: solid; border-width: 11px 0 11px 17px;
  border-color: transparent transparent transparent #fff;
}
.thumb:hover .play { transform: scale(1.08); background: var(--accent); }
.duration {
  position: absolute; right: 8px; bottom: 8px; padding: 2px 6px; border-radius: 4px;
  background: rgba(0, 0, 0, .75); color: #fff; font-size: .75rem; font-variant-numeric: tabular-nums;
}
.card-body { padding: 14px 16px 4px; flex: 1; }
.card-body h3 { margin: 0 0 6px; font-size: 1rem; line-height: 1.3; }
.card-body h3 a { text-decoration: none; }
.card-body h3 a:hover { text-decoration: underline; }
.card-body p {
  margin: 0; color: var(--muted); font-size: .9rem;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-actions { display: flex; gap: 8px; padding: 12px 16px 16px; }

/* ---------- player ---------- */
.player {
  width: min(960px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 0; border: none; border-radius: var(--radius);
  background: var(--surface); color: var(--text); overflow: auto;
}
.player::backdrop { background: rgba(5, 10, 15, .75); }
.player-inner { position: relative; }
.player video { display: block; width: 100%; max-height: 70vh; background: #000; }
.close {
  position: absolute; top: 8px; right: 8px; z-index: 1;
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.player-meta { padding: 16px 20px 20px; }
.player-meta h2 { margin: 0 0 6px; font-size: 1.2rem; }
.player-meta p { margin: 0 0 16px; color: var(--muted); }
.player-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.link-field {
  flex: 1 1 240px; min-width: 0; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--muted);
  font: .8rem ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 8px;
  background: var(--text); color: var(--bg); font-size: .9rem; box-shadow: var(--shadow);
  transition: opacity .2s, transform .2s; overflow-wrap: anywhere;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
