/* x.hemishthanki.com — X media downloader.
   Google Sans + a geneticker-style shell (sticky sidebar on desktop, a horizontally
   scrolling tab strip on mobile), X-blue accent, light + dark. */

/* ------------------------------------------------------------ tokens ------- */
:root {
  --bg: #f7f9fa;
  --panel: #ffffff;
  --panel2: #eef3f4;
  --ink: #0f1419;
  --ink2: #536471;
  --line: #e1e8ed;
  --line-strong: #cfd9de;
  --accent: #0f1419;            /* X is monochrome: black button in light mode… */
  --on-accent: #ffffff;
  --accent-hover: #272c30;
  --accent-ink: #0f1419;
  --accent-tint: rgba(15,20,25,.08);
  --accent-tint-strong: rgba(15,20,25,.14);
  --danger: #d9364c;
  --ok: #2aa565;

  --font-display: 'Google Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-body: 'Google Sans Text', 'Google Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-mono: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius: 16px;
  --radius-sm: 12px;
  --radius-btn: 10px;
  --shell-max: 1320px;
  --side-w: 268px;
  --topbar-h: 60px;
  --e1: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
  --e2: 0 6px 20px rgba(16,24,40,.10);
  --dur: .16s;
}
:root[data-mode="dark"] {
  --bg: #000000;
  --panel: #16181c;
  --panel2: #1f2226;
  --ink: #e7e9ea;
  --ink2: #8b98a5;
  --line: #2f3336;
  --line-strong: #3d4145;
  --accent: #eff3f4;            /* …and white button in dark mode, like x.com's Post button */
  --on-accent: #0f1419;
  --accent-hover: #d7dbdc;
  --accent-ink: #eff3f4;
  --accent-tint: rgba(255,255,255,.10);
  --accent-tint-strong: rgba(255,255,255,.16);
  --danger: #f2607a;
  --ok: #4fd28a;
  --e1: 0 1px 2px rgba(0,0,0,.5);
  --e2: 0 10px 30px rgba(0,0,0,.6);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --bg: #000000; --panel: #16181c; --panel2: #1f2226;
    --ink: #e7e9ea; --ink2: #8b98a5; --line: #2f3336; --line-strong: #3d4145;
    --accent: #eff3f4; --on-accent: #0f1419; --accent-hover: #d7dbdc;
    --accent-ink: #eff3f4; --accent-tint: rgba(255,255,255,.10); --accent-tint-strong: rgba(255,255,255,.16);
    --danger: #f2607a; --ok: #4fd28a; --e1: 0 1px 2px rgba(0,0,0,.5); --e2: 0 10px 30px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; margin: 0; }
h1 { letter-spacing: -.6px; }
h2 { letter-spacing: -.4px; }
code { font-family: var(--font-mono); font-size: .9em; background: var(--panel2); padding: 1px 5px; border-radius: 6px; }
.view[hidden], [hidden] { display: none !important; }

/* Material Symbols: hide until the icon font is confirmed loaded, so a blocked
   Google Fonts request never flashes raw ligature words. */
.material-symbols-rounded {
  font-family: 'Material Symbols Rounded';
  font-weight: normal; font-style: normal; font-size: 22px; line-height: 1;
  letter-spacing: normal; text-transform: none; display: inline-block; white-space: nowrap;
  direction: ltr; -webkit-font-feature-settings: 'liga'; font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased; user-select: none; visibility: hidden;
}
body.fonts-ready .material-symbols-rounded { visibility: visible; }

/* ---------------------------------------------------------- buttons -------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--radius-btn); border: 1px solid transparent;
  font-family: var(--font-display); font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background var(--dur), border-color var(--dur), color var(--dur), opacity var(--dur);
  white-space: nowrap;
}
.btn .material-symbols-rounded { font-size: 20px; }
.btn-filled { background: var(--accent); color: var(--on-accent); }
.btn-filled:hover:not(:disabled) { background: var(--accent-hover); }
.btn-tonal { background: var(--panel2); color: var(--ink); border-color: var(--line); }
.btn-tonal:hover:not(:disabled) { border-color: var(--line-strong); }
.btn-text { background: none; color: var(--accent-ink); }
.btn-text:hover:not(:disabled) { background: var(--accent-tint); }
.btn-danger { background: var(--panel2); color: var(--danger); border-color: var(--line); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 20px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-icon {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border-radius: 999px; border: none; background: transparent; color: var(--ink2); cursor: pointer;
  transition: background var(--dur), color var(--dur);
}
.btn-icon:hover { background: var(--panel2); color: var(--ink); }
.btn-icon .material-symbols-rounded { font-size: 22px; }

/* ----------------------------------------------------------- fields -------- */
.field { display: block; }
.field + .field { margin-top: 14px; }
.field-label {
  display: block; font-family: var(--font-display); font-weight: 600; font-size: 12.5px;
  color: var(--ink2); margin: 0 0 6px 2px; letter-spacing: .1px;
}
.field-box {
  display: flex; align-items: center; gap: 8px; padding: 0 8px 0 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-btn);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.field-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.field-icon { color: var(--ink2); font-size: 20px; }
.field-box input {
  flex: 1; min-width: 0; border: none; outline: none; background: none; color: var(--ink);
  font-family: var(--font-body); font-size: 15px; padding: 12px 0;
}
.field-box input::placeholder { color: var(--ink2); opacity: .8; }
.field-trailing { width: 34px; height: 34px; }
.field-trailing .material-symbols-rounded { font-size: 20px; }

/* ------------------------------------------------------------ login -------- */
.login-view { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--e2); padding: 30px 26px;
}
.brand-lockup { text-align: center; margin-bottom: 22px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 13px;
  background: #000000; color: #ffffff;   /* the X app-icon: black tile, white glyph, both themes */
}
.brand-title { font-size: 22px; margin: 14px 0 4px; }
.brand-sub { color: var(--ink2); font-size: 14px; margin: 0; }
.login-error {
  background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger);
  border-radius: var(--radius-btn); padding: 10px 12px; font-size: 13.5px; margin: 14px 0 0;
}
.login-card .btn-block { margin-top: 16px; }

/* ----------------------------------------------------------- topbar -------- */
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 14px;
  min-height: var(--topbar-h); padding: 11px 22px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: var(--ink); min-width: 0; }
.topbar .brand-mark { width: 32px; height: 32px; border-radius: 9px; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: -.3px; }
.brand-tag {
  font-family: var(--font-mono); font-weight: 500; font-size: 10.5px; letter-spacing: 1px;
  text-transform: uppercase; color: var(--ink2); white-space: nowrap;
  padding-left: 12px; margin-left: 2px; border-left: 1px solid var(--line);
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }

/* ------------------------------------------------------------ shell -------- */
.shell {
  display: flex; align-items: flex-start; gap: 26px; max-width: var(--shell-max);
  margin: 0 auto; padding: 26px 22px 90px;
}
.shell > .main { flex: 1; min-width: 0; }
#main:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------- sidebar --------- */
.sidebar {
  position: sticky; top: calc(var(--topbar-h) + 26px); flex: none; width: var(--side-w);
  display: flex; flex-direction: column; gap: 6px;
}
.side-profile {
  display: flex; align-items: center; gap: 11px; padding: 13px 14px; margin-bottom: 6px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--e1);
}
.side-profile .av {
  width: 40px; height: 40px; border-radius: 11px; flex: none; display: grid; place-items: center;
  background: #000000; color: #ffffff;
}
.side-profile .sp-text { display: flex; flex-direction: column; min-width: 0; }
.sp-name { font-family: var(--font-display); font-weight: 600; font-size: 13.5px; color: var(--ink); }
.sp-mode { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink2); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-eyebrow {
  font-family: var(--font-display); font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--ink2); padding: 6px 8px 8px; margin: 0;
}
.side-group { display: block; }
.side-nav, .nav-foot { display: flex; flex-direction: column; gap: 3px; }
.nav-foot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }

.side-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; width: 100%;
  border-radius: var(--radius-sm); border: none; background: none; text-align: left; cursor: pointer;
  color: var(--ink2); font-family: var(--font-display); font-weight: 600; font-size: 14px;
  transition: background var(--dur), color var(--dur);
}
.side-item .material-symbols-rounded { font-size: 21px; flex: none; }
.side-item .side-label { flex: 1; min-width: 0; }
.side-item:hover { background: var(--panel2); color: var(--ink); }
.side-item.is-on { background: var(--accent-tint); color: var(--accent-ink); }
.si-badge {
  margin-left: auto; font-family: var(--font-mono); font-size: 11.5px; line-height: 1.6;
  padding: 1px 8px; border-radius: 999px; background: var(--panel2); color: var(--ink2); flex: none;
}
.side-item.is-on .si-badge { background: var(--accent-tint-strong); color: var(--accent-ink); }
.si-dot { margin-left: auto; width: 9px; height: 9px; border-radius: 50%; background: var(--ink2); flex: none; }
#cookieBtn[data-state="ok"] .si-dot { background: var(--ok); }
#cookieBtn[data-state="missing"] .si-dot { background: var(--danger); }

/* ------------------------------------------------------------ cards -------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--e1); }
.input-card { padding: 18px; }
.input-card .btn-block { margin-top: 16px; }

.banner {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; margin-bottom: 18px;
  border-radius: var(--radius-sm); font-size: 13.5px;
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  border: 1px solid var(--accent-tint-strong); color: var(--ink);
}
.banner .material-symbols-rounded { color: var(--accent-ink); font-size: 20px; flex: none; }

.hero { margin-bottom: 18px; }
.hero-title { font-size: clamp(1.5rem, 1.2rem + 1.6vw, 1.9rem); }
.hero-sub { color: var(--ink2); margin: 8px 0 0; max-width: 60ch; font-size: 14.5px; }

/* --------------------------------------------------------- add cards ------- */
.adds { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.add {
  display: flex; align-items: center; gap: 12px; padding: 13px 15px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--e1);
}
.add-spin {
  width: 20px; height: 20px; flex: none; border-radius: 50%;
  border: 2.5px solid var(--accent-tint-strong); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
.add[data-state="error"] .add-spin { display: none; }
.add-ico { flex: none; display: none; }
.add[data-state="error"] .add-ico { display: inline-grid; place-items: center; color: var(--danger); }
.add-body { flex: 1; min-width: 0; }
.add-url { font-family: var(--font-mono); font-size: 12px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.add-stage { font-family: var(--font-display); font-weight: 600; font-size: 13.5px; color: var(--ink); margin-top: 2px; }
.add[data-state="error"] .add-stage { color: var(--danger); }
.add-x { flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------- library -------- */
.library { margin-top: 26px; }
.lib-head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.lib-head-text { min-width: 0; }
.lib-title { font-size: 20px; }
.lib-summary { display: block; color: var(--ink2); font-family: var(--font-mono); font-size: 12.5px; margin-top: 3px; }
.lib-actions { margin-left: auto; display: flex; gap: 8px; }

/* Tile size tracks the viewport so the grid stays dense on big monitors and
   comfortable on small ones, filling whatever width the shell offers. */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(150px, 17vw, 210px), 1fr)); gap: clamp(10px, 1.3vw, 16px); }
.tile {
  position: relative; margin: 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--e1);
  transition: border-color var(--dur), box-shadow var(--dur), transform var(--dur);
}
.tile:hover { border-color: var(--line-strong); box-shadow: var(--e2); }
.tile-thumb {
  position: relative; display: block; width: 100%; aspect-ratio: 1 / 1; border: none; padding: 0;
  background: var(--panel2); cursor: pointer; overflow: hidden;
}
.tile-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-play {
  position: absolute; inset: 0; display: grid; place-items: center; color: #fff;
  background: linear-gradient(transparent 55%, rgba(0,0,0,.35));
}
.tile-play .material-symbols-rounded {
  font-size: 30px; background: rgba(0,0,0,.5); border-radius: 50%; width: 52px; height: 52px;
  display: grid; place-items: center; font-variation-settings: 'FILL' 1;
}
.tile-badge {
  position: absolute; top: 8px; left: 8px; font-family: var(--font-mono); font-size: 10.5px; font-weight: 500;
  color: #fff; background: rgba(0,0,0,.6); padding: 2px 7px; border-radius: 999px; letter-spacing: .3px;
}
.tile-meta { padding: 9px 11px; }
.tile-author { display: block; font-family: var(--font-display); font-weight: 600; font-size: 12.5px; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-info { display: block; font-family: var(--font-mono); font-size: 11px; color: var(--ink2); margin-top: 1px; }
.tile-actions {
  position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0;
  transition: opacity var(--dur);
}
.tile:hover .tile-actions, .tile:focus-within .tile-actions { opacity: 1; }
.tile-actions .btn-icon {
  width: 32px; height: 32px; background: rgba(0,0,0,.55); color: #fff;
}
.tile-actions .btn-icon:hover { background: rgba(0,0,0,.75); }
.tile-actions .btn-icon .material-symbols-rounded { font-size: 18px; }

.empty { text-align: center; padding: 44px 20px; color: var(--ink2); }
.empty-icon { font-size: 46px; opacity: .5; }
.empty-title { font-family: var(--font-display); font-weight: 600; font-size: 16px; color: var(--ink); margin: 10px 0 2px; }
.empty-sub { font-size: 13.5px; margin: 0; }

.footnote { color: var(--ink2); font-size: 12.5px; margin-top: 30px; max-width: 70ch; }

/* --------------------------------------------------------- lightbox -------- */
.lightbox {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 28px;
  background: rgba(0,0,0,.82); backdrop-filter: blur(4px);
}
.lb-close { position: absolute; top: 14px; right: 16px; background: rgba(255,255,255,.12); color: #fff; }
.lb-close:hover { background: rgba(255,255,255,.24); color: #fff; }
.lb-stage { max-width: min(1100px, 96vw); max-height: 90vh; display: grid; place-items: center; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 90vh; border-radius: 10px; display: block; box-shadow: var(--e2); }

/* --------------------------------------------------------- snackbar -------- */
.snackbar {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 95;
  max-width: min(92vw, 460px); background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: 12px; font-size: 13.5px; box-shadow: var(--e2);
}
:root[data-mode="dark"] .snackbar { background: #e7e9ea; color: #16181c; }

/* ------------------------------------------------------------- boot -------- */
.boot { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 100; overflow: hidden; background: transparent; }
.linear-indeterminate { position: relative; height: 3px; overflow: hidden; }
.linear-indeterminate::before {
  content: ""; position: absolute; height: 100%; width: 40%; background: var(--accent);
  animation: slide 1.1s infinite; border-radius: 3px;
}
@keyframes slide { 0% { left: -40%; } 100% { left: 100%; } }

/* ============================================================ MOBILE =======
   <=820px: the sidebar becomes a horizontally scrolling tab strip. */
@media (max-width: 820px) {
  .shell { flex-direction: column; gap: 14px; padding: 14px 14px calc(80px + env(safe-area-inset-bottom)); }
  .topbar { padding: 10px 14px; }
  .brand-tag { display: none; }

  .sidebar {
    position: sticky; top: var(--topbar-h); z-index: 30; width: auto; margin: 0 -14px;
    flex-direction: row; align-items: center; flex-wrap: nowrap; gap: 6px;
    overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; padding: 8px 14px; background: var(--bg); border-bottom: 1px solid var(--line);
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .side-profile, .nav-eyebrow { display: none; }
  .side-group { flex: none; display: flex; }
  .side-nav, .nav-foot {
    flex-direction: row; flex-wrap: nowrap; gap: 6px; margin: 0; padding: 0; border-top: none;
  }
  .side-group + .side-group { position: relative; padding-left: 7px; }
  .side-group + .side-group::before {
    content: ""; position: absolute; left: 0; top: 50%; width: 1px; height: 22px;
    transform: translateY(-50%); background: var(--line);
  }
  .side-item { white-space: nowrap; padding: 9px 13px; }
  .side-item .side-label { flex: none; }
  .btn { min-height: 44px; }
  .lib-actions { width: 100%; }
  .lib-actions .btn { flex: 1; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
}

@media (min-width: 821px) and (max-width: 1040px) {
  :root { --side-w: 220px; }
  .shell { gap: 18px; }
}
/* Large monitors: let the content breathe into the extra width. */
@media (min-width: 1500px) { :root { --shell-max: 1480px; --side-w: 288px; } }
@media (min-width: 1900px) { :root { --shell-max: 1720px; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
