:root {
  color-scheme: dark;
  font-family: "Alexandria", "Segoe UI", Tahoma, sans-serif;
  background: #101010;
  color: #f5f5f5;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --surface: #181818;
  --surface-raised: #202020;
  --muted: #9c9c9c;
  --line: #2b2b2b;
  --accent: #ff3838;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(ellipse at 70% -30%, rgba(255, 56, 56, .07), transparent 45%),
    #101010;
}

button, input, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  height: 72px;
  padding: 0 34px;
  display: grid;
  grid-template-columns: 220px minmax(260px, 660px) minmax(100px, 1fr) auto;
  align-items: center;
  gap: 30px;
  background: rgba(16, 16, 16, .92);
  border-bottom: 1px solid #252525;
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 37px;
  height: 27px;
  background: var(--accent);
  border-radius: 9px;
  display: grid;
  place-items: center;
  box-shadow: 0 5px 22px rgba(255, 56, 56, .2);
}

.brand-mark span {
  width: 0;
  height: 0;
  margin-right: -2px;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 0;
  border-left: 10px solid white;
}

.brand-name { font-size: 15px; font-weight: 700; letter-spacing: -.5px; }
.brand-name b { color: var(--accent); font-weight: 600; }

.search {
  height: 42px;
  display: flex;
  overflow: hidden;
  background: #202020;
  border: 1px solid #333;
  border-radius: 12px;
  transition: border-color .2s, box-shadow .2s;
}

.search:focus-within {
  border-color: #555;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .035);
}

.search input {
  width: 100%;
  min-width: 0;
  padding: 0 16px;
  color: #f4f4f4;
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 12px;
}

.search input::placeholder { color: #777; }
.search-button {
  width: 55px;
  flex: 0 0 55px;
  display: grid;
  place-items: center;
  cursor: pointer;
  background: #292929;
  border: 0;
  border-right: 1px solid #333;
  transition: background .2s;
}
.search-button:hover { background: #363636; }
.search-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #ddd;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.topbar-note {
  justify-self: end;
  color: #aaa;
  font-size: 10px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  white-space: nowrap;
}

.live-dot {
  width: 7px;
  height: 7px;
  background: #55d68b;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(85, 214, 139, .5);
}
.topbar-note.offline .live-dot { background: #e6ad52; box-shadow: 0 0 10px rgba(230, 173, 82, .45); }
.topbar-note.offline-ready { color: #e6c27e; }
.logout-button {
  padding: 8px 11px;
  color: #ddd;
  background: #202020;
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 9px;
  cursor: pointer;
}
.logout-button:hover { background: #2b2b2b; }

.auth-panel {
  min-height: calc(100vh - 72px);
  padding: 30px 16px;
  display: grid;
  place-items: center;
}
.auth-card {
  width: min(440px, 100%);
  padding: 34px;
  background: linear-gradient(145deg, #1d1b1b, #171717);
  border: 1px solid #342425;
  border-radius: 18px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, .28);
}
.auth-card h1 { margin: 8px 0; font-size: 27px; }
.auth-card > p { color: #aaa; font-size: 11px; line-height: 1.9; }
.auth-card form { margin-top: 23px; display: flex; flex-direction: column; gap: 9px; }
.auth-card label { margin-top: 7px; color: #c4c4c4; font-size: 10px; }
.auth-card input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  color: #f5f5f5;
  background: #101010;
  border: 1px solid #373737;
  border-radius: 8px;
  outline: none;
  font-size: 12px;
}
.auth-card input:focus { border-color: #9e4b4b; box-shadow: 0 0 0 3px rgba(255, 56, 56, .08); }
.auth-actions { margin-top: 12px; display: flex; gap: 9px; }
.auth-submit, .auth-register {
  min-height: 40px;
  padding: 0 15px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
}
.auth-submit { color: white; background: #d93030; border: 1px solid #ee4545; }
.auth-submit:hover { background: #ed3b3b; }
.auth-register { color: #ddd; background: #262626; border: 1px solid #414141; }
.auth-register:hover { background: #333; }
.auth-card .auth-disclaimer { margin: 17px 0 0; color: #858585; font-size: 9px; }
.auth-message { padding: 10px 12px; background: #1c2921; border-radius: 8px; }
.auth-message.is-error { color: #ffaaaa; background: #2c1b1b; }

.app-layout { min-height: calc(100vh - 72px); }
.sidebar {
  width: 230px;
  padding: 30px 17px 18px;
  position: fixed;
  top: 72px;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  background: rgba(16, 16, 16, .65);
  border-left: 1px solid #222;
}

.side-heading {
  margin: 0 12px 13px;
  color: #777;
  font-size: 10px;
  font-weight: 600;
}

.category {
  min-height: 43px;
  width: 100%;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: right;
  border: 0;
  border-radius: 10px;
  color: #b7b7b7;
  background: transparent;
  font-size: 11px;
  cursor: pointer;
  transition: color .2s, background .2s;
}
.category:hover { color: #fff; background: #1c1c1c; }
.category.active { color: #fff; background: #242424; font-weight: 600; }
.category.active .category-icon { color: var(--accent); }
.category-icon { width: 20px; color: #8d8d8d; font-size: 17px; text-align: center; }
.sidebar-divider { height: 1px; margin: 20px 10px; background: #292929; }

.sidebar-info {
  margin: 2px 6px;
  padding: 13px 12px;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  background: #191919;
  border: 1px solid #252525;
  border-radius: 11px;
}
.info-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  display: grid;
  place-items: center;
  border: 1px solid #666;
  border-radius: 50%;
  color: #aaa;
  font-family: serif;
  font-size: 11px;
}
.sidebar-info p { margin: 0; color: #888; font-size: 9px; line-height: 1.9; }
.sidebar-footer { margin-top: auto; padding: 17px 10px 0; color: #656565; font-size: 9px; }

.main-content {
  max-width: 1600px;
  margin-right: 230px;
  padding: 28px clamp(22px, 4vw, 64px) 25px;
}

.welcome {
  min-height: 222px;
  margin-bottom: 37px;
  padding: 30px 39px;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(112deg, #1d1b1b 0%, #211a1a 53%, #2c1517 100%);
  border: 1px solid #342425;
  border-radius: 18px;
}

.welcome-copy { position: relative; z-index: 1; }
.eyebrow {
  display: inline-block;
  color: #ff7777;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .3px;
}
.welcome h1 {
  margin: 11px 0 7px;
  font-size: clamp(24px, 3.2vw, 37px);
  line-height: 1.4;
  letter-spacing: -1.5px;
}
.welcome h1 span { color: var(--accent); }
.welcome p { margin: 0; color: #aaa; font-size: 11px; }

.welcome-art {
  width: 220px;
  height: 170px;
  flex: 0 0 220px;
  position: relative;
  margin-left: 8%;
}
.art-glow {
  width: 150px;
  height: 150px;
  position: absolute;
  top: 12px;
  right: 35px;
  background: radial-gradient(circle, rgba(255, 56, 56, .3), rgba(255, 56, 56, 0) 68%);
}
.art-play {
  width: 94px;
  height: 67px;
  position: absolute;
  top: 47px;
  right: 62px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #ff4d4d, #d91829);
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 19px;
  transform: rotate(-8deg);
  box-shadow: 0 18px 45px rgba(255, 31, 48, .3);
}
.art-play span {
  width: 0;
  height: 0;
  margin-right: -4px;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  border-left: 18px solid white;
}
.art-line {
  height: 1px;
  position: absolute;
  background: linear-gradient(90deg, transparent, rgba(255, 130, 130, .42), transparent);
  transform: rotate(-25deg);
}
.art-line-one { width: 154px; top: 39px; right: 9px; }
.art-line-two { width: 118px; bottom: 33px; right: 42px; }

.watch-section {
  margin: 0 0 36px;
  padding: 16px;
  background: #171717;
  border: 1px solid #2c2c2c;
  border-radius: 15px;
  scroll-margin-top: 92px;
}
.player-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #080808;
  border-radius: 10px;
}
.player-frame iframe { width: 100%; height: 100%; border: 0; }
.player-frame video { width: 100%; height: 100%; display: block; background: #080808; object-fit: contain; }
.offline-player-message {
  min-height: 225px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(255, 56, 56, .12), transparent 60%),
    #111;
  border: 1px solid #303030;
  border-radius: 10px;
}
.offline-player-icon { color: #ff7777; font-size: 30px; }
.offline-player-message h3 { margin: 10px 0 6px; font-size: 14px; }
.offline-player-message p { max-width: 520px; margin: 0 0 14px; color: #aaa; font-size: 10px; line-height: 1.9; }
.video-details {
  margin: 17px 2px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 15px;
}
.video-details h2 { margin: 0 0 7px; font-size: 16px; line-height: 1.7; }
.video-details p, .video-description { margin: 0; color: #aaa; font-size: 10px; }
.save-button {
  padding: 9px 13px;
  flex: 0 0 auto;
  color: #eee;
  background: #292929;
  border: 1px solid #444;
  border-radius: 8px;
  font-size: 9px;
  cursor: pointer;
}
.save-button:hover { background: #393939; }
.youtube-link {
  margin-right: auto;
  padding: 9px 13px;
  flex: 0 0 auto;
  color: #fff;
  background: #d93030;
  border: 1px solid #ee4545;
  border-radius: 8px;
  font-size: 9px;
  text-decoration: none;
}
.youtube-link:hover { background: #f03d3d; }
.embed-note { margin: 12px 2px 0; color: #858585; font-size: 9px; }
.back-button {
  padding: 9px 13px;
  flex: 0 0 auto;
  color: #ddd;
  background: #252525;
  border: 1px solid #363636;
  border-radius: 8px;
  font-size: 9px;
  cursor: pointer;
}
.back-button:hover { background: #333; }
.offline-player-message .back-button { width: fit-content; }
.video-description {
  margin-top: 13px;
  padding: 12px 14px;
  line-height: 1.9;
  white-space: pre-wrap;
  background: #1e1e1e;
  border-radius: 8px;
}
.library-note {
  margin: 0 0 17px;
  padding: 13px 15px;
  color: #b6b6b6;
  background: #1b1b1b;
  border: 1px solid #303030;
  border-radius: 10px;
  font-size: 10px;
  line-height: 1.9;
}
.history-section { margin-top: 35px; }
.history-section .results-heading { margin-bottom: 16px; }
.history-empty { margin: 0; color: #888; font-size: 10px; }

.results-heading {
  margin-bottom: 19px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 15px;
}
.results-heading .eyebrow { color: #888; font-size: 9px; }
.results-heading h2 { margin: 5px 0 0; font-size: 17px; letter-spacing: -.4px; }
.sort-control { display: flex; align-items: center; gap: 9px; color: #888; font-size: 9px; }
.sort-control select {
  padding: 8px 10px;
  color: #ddd;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 9px;
  outline: none;
}

.message {
  min-height: 90px;
  margin: 0 0 13px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  color: #aaa;
  background: #171717;
  border: 1px solid #242424;
  border-radius: 12px;
  font-size: 11px;
  text-align: center;
}
.message:not(.is-busy) { color: #e6a3a3; }
.spinner {
  width: 17px;
  height: 17px;
  display: none;
  border: 2px solid #464646;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
.is-busy .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.video-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 28px 17px;
}
.video-card {
  min-width: 0;
  display: block;
  border-radius: 12px;
}
.video-open {
  width: 100%;
  padding: 0;
  display: block;
  overflow: hidden;
  text-align: right;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}
.thumbnail-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  position: relative;
  display: block;
  overflow: hidden;
  background: #252525;
  border: 1px solid #303030;
  border-radius: 11px;
}
.thumbnail {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform .28s, filter .28s;
}
.video-open:hover .thumbnail { transform: scale(1.04); filter: brightness(.78); }
.thumbnail-empty { background: linear-gradient(135deg, #252525, #161616); }
.local-thumbnail::after {
  content: "ملف محلي";
  position: absolute;
  right: 12px;
  bottom: 10px;
  color: #aaa;
  font-size: 10px;
}
.thumbnail-play {
  width: 39px;
  height: 39px;
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  color: white;
  background: rgba(255, 56, 56, .92);
  border-radius: 50%;
  font-size: 12px;
  opacity: 0;
  transform: translate(-50%, -40%) scale(.8);
  transition: opacity .2s, transform .2s;
}
.video-open:hover .thumbnail-play, .video-open:focus-visible .thumbnail-play {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.video-copy { padding: 11px 2px 0; display: flex; flex-direction: column; align-items: flex-start; }
.card-title {
  width: 100%;
  display: -webkit-box;
  overflow: hidden;
  color: #eee;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.8;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-channel, .card-date { margin-top: 5px; color: #858585; font-size: 9px; }
.card-date { margin-top: 3px; color: #696969; }
.video-open:hover .card-title { color: #fff; }
.video-open:focus-visible { outline: 2px solid #ff6565; outline-offset: 4px; }
.card-actions { margin-top: 9px; display: flex; justify-content: flex-start; }
.card-action {
  padding: 6px 9px;
  color: #bdbdbd;
  background: #202020;
  border: 1px solid #333;
  border-radius: 7px;
  font-size: 8px;
  cursor: pointer;
}
.card-action:hover { color: #fff; background: #2b2b2b; }

.load-more {
  min-width: 150px;
  margin: 30px auto 0;
  padding: 11px 23px;
  display: block;
  color: white;
  background: #262626;
  border: 1px solid #3b3b3b;
  border-radius: 9px;
  font-size: 10px;
  cursor: pointer;
}
.load-more:hover:not(:disabled) { background: #333; }
.load-more:disabled { opacity: .6; cursor: wait; }

.page-footer {
  margin-top: 48px;
  padding: 17px 0 5px;
  display: flex;
  justify-content: space-between;
  gap: 15px;
  color: #626262;
  border-top: 1px solid #252525;
  font-size: 8px;
}

@media (max-width: 1180px) {
  .video-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { grid-template-columns: 185px minmax(240px, 1fr) auto auto; gap: 20px; }
  .welcome-art { margin-left: 2%; }
}

@media (max-width: 760px) {
  .topbar {
    height: 62px;
    padding: 0 14px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 15px;
  }
  .brand-name { display: none; }
  .topbar-note { display: none; }
  .logout-button { padding: 7px 8px; font-size: 8px; }
  .search { height: 39px; }
  .sidebar {
    width: auto;
    height: 58px;
    padding: 6px 12px;
    position: sticky;
    top: 62px;
    z-index: 4;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    border-left: 0;
    border-bottom: 1px solid #292929;
    background: rgba(16, 16, 16, .96);
  }
  .side-heading, .sidebar-divider, .sidebar-info, .sidebar-footer { display: none; }
  .category { width: auto; min-height: 35px; padding: 0 12px; flex: 0 0 auto; gap: 7px; font-size: 9px; }
  .category-icon { font-size: 14px; }
  .main-content { margin: 0; padding: 18px 15px 20px; }
  .auth-panel { min-height: calc(100vh - 120px); }
  .auth-card { padding: 25px 21px; }
  .welcome { min-height: 190px; margin-bottom: 28px; padding: 23px; }
  .welcome-art { width: 115px; height: 120px; flex-basis: 115px; margin: 0; }
  .art-glow { width: 120px; height: 120px; top: 0; right: 0; }
  .art-play { width: 67px; height: 49px; top: 35px; right: 23px; border-radius: 14px; }
  .art-play span { border-top-width: 9px; border-bottom-width: 9px; border-left-width: 14px; }
  .art-line-one { width: 95px; top: 20px; right: 0; }
  .art-line-two { width: 86px; bottom: 20px; right: 10px; }
  .welcome p { max-width: 290px; font-size: 9px; line-height: 1.8; }
  .results-heading h2 { font-size: 14px; }
  .sort-control { gap: 5px; font-size: 8px; }
  .sort-control select { max-width: 110px; padding: 7px; font-size: 8px; }
  .video-grid { gap: 22px 12px; }
  .card-title { font-size: 9px; }
}

@media (max-width: 480px) {
  .video-grid { grid-template-columns: minmax(0, 1fr); gap: 21px; }
  .welcome { min-height: 173px; }
  .welcome h1 { font-size: 24px; }
  .welcome-art { width: 85px; flex-basis: 85px; }
  .art-play { right: 9px; }
  .art-glow { right: -15px; }
  .results-heading { align-items: flex-start; flex-direction: column; }
  .sort-control { align-self: flex-end; }
  .video-details { align-items: stretch; flex-direction: column; }
  .save-button { width: fit-content; }
  .youtube-link { margin-right: 0; width: fit-content; }
  .page-footer { flex-direction: column; }
  .watch-section { padding: 9px; }
  .offline-player-message { min-height: 190px; padding: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
