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

  :root {
    --bg: #0a0a0f;
    --surface: #111118;
    --surface2: #1a1a24;
    --surface3: #22222f;
    --border: rgba(255,255,255,0.07);
    --border2: rgba(255,255,255,0.12);
    --text: #f0eff8;
    --text2: #9895b0;
    --text3: #5c5a72;
    --accent: #7c6af7;
    --accent2: #a896ff;
    --accent-bg: rgba(124,106,247,0.12);
    --success: #34c87a;
    --success-bg: rgba(52,200,122,0.12);
    --amber: #f5a623;
    --amber-bg: rgba(245,166,35,0.1);
    --danger: #f05050;
    --font-display: 'Syne', sans-serif;
    --font-body: 'DM Sans', sans-serif;
    --r: 10px;
    --r-lg: 16px;
  }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
  }

  /* AUTH GATE */
  #auth-gate {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    text-align: center;
    background: #0a0a0f !important;
    position: relative !important;
    z-index: 9999 !important;
  }
  #auth-gate h1 {
    font-family: var(--font-display);
    font-size: 40px;
    font-weight: 700;
    margin-bottom: 8px;
    color: #fff;
  }
  #auth-gate p { color: var(--text2); margin-bottom: 2rem; font-size: 15px; }
  #auth-gate .gate-box {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: var(--r-lg);
    padding: 2rem;
    width: 100%;
    max-width: 460px;
  }
  #auth-gate label { display: block; text-align: left; font-size: 12px; color: var(--text2); margin-bottom: 6px; letter-spacing: 0.05em; text-transform: uppercase; }
  #auth-gate input {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: var(--r);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    padding: 10px 14px;
    outline: none;
    margin-bottom: 12px;
    transition: border-color 0.2s;
  }
  #auth-gate input:focus { border-color: var(--accent); }
  #auth-gate button {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--r);
    padding: 11px;
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
  }
  #auth-gate button:hover { opacity: 0.88; }
  #auth-gate .hint { margin-top: 14px; font-size: 12px; color: var(--text3); }
  #auth-gate .hint a { color: var(--accent2); text-decoration: none; }
  #gate-error { color: var(--danger); font-size: 13px; margin-top: 8px; display: none; }

  /* GOOGLE SIGN-IN BUTTON */
  #google-btn {
    background: #fff !important;
    color: #3c3c3c !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-family: var(--font-body) !important;
    font-size: 15px !important;
    font-weight: 500 !important;
    border: 1px solid #ddd !important;
    margin-bottom: 0 !important;
    transition: box-shadow 0.2s !important;
  }
  #google-btn:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.15); opacity: 1 !important; }

  .gate-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
    color: var(--text3);
    font-size: 12px;
  }
  .gate-divider::before, .gate-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border2);
  }

  /* USER AREA IN HEADER */
  #user-area { margin-left: auto; flex-shrink: 0; position: relative; }
  .user-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    border-radius: 50px;
    border: 1px solid var(--border2);
    background: var(--surface2);
    cursor: pointer;
    transition: border-color 0.2s;
    font-size: 13px;
    color: var(--text2);
  }
  .user-pill:hover { border-color: var(--accent); color: var(--text); }
  .user-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
  .user-avatar-ph {
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--surface3);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; color: var(--text3);
  }
  .user-name { font-weight: 500; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .user-guest-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    border-radius: 50px;
    border: 1px solid var(--border2);
    background: transparent;
    color: var(--text3);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
  }
  .user-guest-btn:hover { border-color: var(--danger); color: var(--danger); }

  .user-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: var(--r);
    min-width: 200px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 200;
    overflow: hidden;
  }
  .user-menu.open { display: block; }
  .user-menu-info { padding: 12px 14px; }
  .user-menu-divider { height: 1px; background: var(--border); }
  .user-menu-btn {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 10px 14px;
    background: none; border: none;
    color: var(--text2); font-size: 13px;
    cursor: pointer; text-align: left;
    transition: background 0.15s, color 0.15s;
  }
  .user-menu-btn:hover { background: var(--surface2); color: var(--danger); }

  /* MAIN APP */
  #app { display: none !important; flex-direction: column; min-height: 100vh; }

  /* HEADER */
  header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10,10,15,0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    height: 58px;
  }
  .logo {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    flex-shrink: 0;
  }
  .logo .track { color: #005BBB; }
  .logo .my    { color: #FFD500; }

  .search-wrap {
    flex: 1;
    position: relative;
    max-width: 540px;
  }
  .search-wrap i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text3);
    font-size: 17px;
    pointer-events: none;
  }
  #search-input {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: 50px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    padding: 8px 16px 8px 38px;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
  }
  #search-input:focus { border-color: var(--accent); background: var(--surface3); }
  #search-input::placeholder { color: var(--text3); }

  .lang-badge {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    font-weight: 600;
    color: var(--accent2);
    background: var(--accent-bg);
    padding: 2px 7px;
    border-radius: 50px;
    letter-spacing: 0.04em;
    transition: opacity 0.3s;
    opacity: 0;
  }
  .lang-badge.visible { opacity: 1; }

  /* TABS */
  .tabs {
    display: flex;
    gap: 4px;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn {
    background: none;
    border: none;
    color: #7e7a97;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    padding: 12px 14px;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .tab-btn:hover { color: #d0cde8; }
  .tab-btn.active { color: var(--accent2); border-bottom-color: var(--accent); }
  .tab-count {
    font-size: 11px;
    background: var(--surface3);
    padding: 1px 6px;
    border-radius: 50px;
    color: var(--text2);
  }
  .tab-btn.active .tab-count { background: var(--accent-bg); color: var(--accent2); }

  /* CONTENT */
  main { flex: 1; padding: 1.5rem; max-width: 1400px; margin: 0 auto; width: 100%; }

  .section-label {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 700;
    color: #c8c5e0;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 1rem;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border2);
  }

  /* GRID */
  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 16px;
  }

  /* CARD */
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    position: relative;
  }
  .card:hover {
    transform: translateY(-3px);
    border-color: var(--border2);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  }
  .card-poster {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    display: block;
    background: var(--surface2);
  }
  .card-poster-placeholder {
    width: 100%;
    aspect-ratio: 2/3;
    background: var(--surface2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text3);
    font-size: 32px;
  }

  /* POSTER bottom gradient — decorative only, no text */
  .card-overlay {
    position: absolute;
    bottom: 0;
    left: 0; right: 0;
    height: 48px;
    background: linear-gradient(to top, rgba(0,0,0,0.55) 0%, transparent 100%);
    pointer-events: none;
  }
  /* Genre + seasons shown inside card-body, not floating over poster */
  .overlay-genre {
    font-size: 10px;
    font-weight: 500;
    color: #7e7a97;
    line-height: 1.4;
    margin-bottom: 2px;
  }
  .overlay-seasons {
    font-size: 10px;
    font-weight: 600;
    color: #9895b0;
    display: flex;
    align-items: center;
    gap: 3px;
    margin-bottom: 2px;
  }
  .overlay-seasons i { font-size: 11px; }
  .card-body { padding: 10px 10px 8px; }
  .card-title {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 700;
    color: #f0eff8;
    margin-bottom: 4px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .card-meta { font-size: 11px; color: #7e7a97; line-height: 1.5; }
  .card-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
  .badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 50px;
  }
  .badge-type { background: var(--accent-bg); color: #c4b5ff; }
  .badge-year { background: var(--surface3); color: #9895b0; }
  /* Air status badge on card */
  .badge-onair    { background: rgba(52,200,122,0.18);  color: #34c87a; }
  .badge-ended    { background: rgba(245,166,35,0.18);  color: #f5c842; }
  .badge-canceled { background: rgba(240,80,80,0.15);   color: #f07070; }

  .card-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
  }
  .card:hover .card-actions { opacity: 1; }
  .wl-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--border2);
    background: rgba(10,10,15,0.85);
    color: var(--text2);
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    backdrop-filter: blur(4px);
  }
  .wl-btn:hover { background: var(--surface3); }
  .wl-btn.wl-active-watchlist { color: var(--accent2); }
  .wl-btn.wl-active-watching { color: var(--amber); }
  .wl-btn.wl-active-watched { color: var(--success); }

  .status-ribbon {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
  }
  .ribbon-watchlist { background: var(--accent); }
  .ribbon-watching { background: var(--amber); }
  .ribbon-watched { background: var(--success); }

  /* EMPTY STATE */
  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    color: var(--text3);
    text-align: center;
    gap: 12px;
  }
  .empty-state i { font-size: 40px; }
  .empty-state p { font-size: 14px; max-width: 300px; }

  /* SPINNER */
  .spinner {
    width: 28px; height: 28px;
    border: 2px solid var(--border2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 3rem auto;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* DETAIL VIEW */
  #detail-view {
    display: none;
    flex-direction: column;
    min-height: 100vh;
  }
  .detail-header {
    position: relative;
    overflow: hidden;
    min-height: 300px;
    display: flex;
    align-items: flex-end;
  }
  .detail-backdrop {
    position: absolute;
    inset: 0;
    object-fit: cover;
    width: 100%;
    height: 100%;
    filter: brightness(0.3) saturate(0.8);
  }
  .detail-backdrop-placeholder {
    position: absolute;
    inset: 0;
    background: var(--surface2);
  }
  .detail-gradient {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, var(--bg) 0%, rgba(10,10,15,0.4) 60%, transparent 100%);
  }
  .detail-content {
    position: relative;
    z-index: 2;
    padding: 1.5rem;
    display: flex;
    gap: 1.5rem;
    align-items: flex-end;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
  }
  .detail-poster {
    width: 110px;
    border-radius: var(--r);
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.1);
    display: block;
  }
  .detail-poster-ph {
    width: 110px;
    height: 165px;
    background: var(--surface2);
    border-radius: var(--r);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text3);
    font-size: 28px;
  }
  .detail-info { flex: 1; }
  .detail-title {
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 6px;
  }
  .detail-tagline {
    font-size: 13px;
    color: var(--text2);
    font-style: italic;
    margin-bottom: 10px;
  }
  .detail-chips { display: flex; flex-wrap: wrap; gap: 6px; }
  .chip {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 50px;
    border: 1px solid var(--border2);
    color: var(--text2);
  }

  .detail-body {
    padding: 1.5rem;
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
  }
  .detail-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text2);
    font-size: 13px;
    cursor: pointer;
    margin-bottom: 1.5rem;
    padding: 6px 12px;
    border-radius: 50px;
    border: 1px solid var(--border);
    background: var(--surface);
    transition: border-color 0.2s, color 0.2s;
    width: fit-content;
  }
  .detail-back:hover { border-color: var(--border2); color: var(--text); }

  .detail-actions { display: flex; gap: 8px; margin-bottom: 1.5rem; flex-wrap: wrap; }
  .action-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: 50px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border2);
    background: var(--surface2);
    color: var(--text2);
    transition: all 0.2s;
  }
  .action-btn:hover { color: var(--text); }
  .action-btn.act-watchlist.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent2); }
  .action-btn.act-watching.active { background: var(--amber-bg); border-color: var(--amber); color: var(--amber); }
  .action-btn.act-watched.active { background: var(--success-bg); border-color: var(--success); color: var(--success); }

  .detail-desc {
    font-size: 15px;
    color: #c0bdd8;
    line-height: 1.75;
    margin-bottom: 1.5rem;
    max-width: 680px;
  }

  .detail-facts {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    margin-bottom: 2rem;
  }
  .fact-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 12px;
  }
  .fact-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #7e7a97; margin-bottom: 4px; font-weight: 600; }
  .fact-value { font-size: 13px; font-weight: 600; color: #f0eff8; }

  /* SEASONS */
  .seasons-title {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text);
  }
  .season-block { margin-bottom: 8px; }
  .season-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    cursor: pointer;
    transition: border-color 0.2s;
    user-select: none;
  }
  .season-header:hover { border-color: var(--border2); }
  .season-header.open { border-radius: var(--r) var(--r) 0 0; border-bottom-color: transparent; }
  .season-name { font-weight: 700; font-size: 14px; color: #e8e5f8; }
  .season-ep-count { font-size: 12px; color: #7e7a97; font-weight: 500; }
  .season-chevron { color: #7e7a97; font-size: 14px; transition: transform 0.2s; }
  .season-header.open .season-chevron { transform: rotate(180deg); }

  .episodes-list {
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--r) var(--r);
    overflow: hidden;
    display: none;
  }
  .episodes-list.open { display: block; }
  .episode-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
  }
  .episode-row:last-child { border-bottom: none; }
  .episode-row:hover { background: var(--surface2); }
  .ep-check {
    width: 16px;
    height: 16px;
    accent-color: var(--success);
    cursor: pointer;
    flex-shrink: 0;
  }
  .ep-num { font-size: 11px; color: #7e7a97; min-width: 28px; font-weight: 600; }
  .ep-title { flex: 1; font-size: 13px; color: #e8e5f8; }
  .ep-date { font-size: 11px; color: #7e7a97; white-space: nowrap; }

  .ep-released {
    background: rgba(168,150,255,0.05);
    border-left: 2px solid rgba(168,150,255,0.4);
  }
  .ep-released:hover { background: rgba(168,150,255,0.1) !important; }
  .ep-released .ep-title { color: #f0eff8; font-weight: 500; }
  .ep-released .ep-num   { color: #a896ff; font-weight: 700; }
  .ep-released .ep-date  { color: var(--text2); }

  .ep-unreleased {
    background: transparent;
    border-left: 2px solid transparent;
    opacity: 1;
  }
  .ep-unreleased:hover { background: transparent !important; cursor: default; }
  .ep-unreleased .ep-check { cursor: not-allowed; pointer-events: none; opacity: 0.2; }
  .ep-unreleased .ep-num   { color: #5c5a72; }
  .ep-unreleased .ep-title { color: #6e6b88; font-style: italic; }
  .ep-unreleased .ep-date  { color: #7e7a97; }

  .ep-countdown {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 50px;
    background: var(--amber-bg);
    color: var(--amber);
    white-space: nowrap;
    flex-shrink: 0;
  }
  .ep-countdown.soon {
    background: var(--accent-bg);
    color: var(--accent2);
  }

  .ep-done .ep-title { color: var(--text3); text-decoration: line-through; text-decoration-color: var(--text3); opacity: 0.6; }

  ::-webkit-scrollbar { width: 5px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }

  /* AIR STATUS BADGES */
  .air-badge { font-weight: 600; letter-spacing: 0.03em; }
  .air-onair    { background: rgba(52,200,122,0.15) !important;  color: #34c87a !important; border-color: rgba(52,200,122,0.4) !important; }
  .air-ended    { background: rgba(245,166,35,0.15) !important;  color: #f5c842 !important; border-color: rgba(245,166,35,0.4) !important; }
  .air-canceled { background: rgba(240,80,80,0.12)  !important;  color: #f07070 !important; border-color: rgba(240,80,80,0.3)  !important; }
  .air-fact-onair    { color: #34c87a; }
  .air-fact-ended    { color: #f5c842; }
  .air-fact-canceled { color: #f07070; }

  /* WATCHED COMPLETION POPUP */
  #watched-popup {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999;
    align-items: center;
    justify-content: center;
    padding: 1rem;
  }
  #watched-popup-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(6px);
  }
  #watched-popup-box {
    position: relative;
    z-index: 1;
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: var(--r-lg);
    padding: 2rem 2rem 1.5rem;
    max-width: 360px;
    width: 100%;
    text-align: center;
    box-shadow: 0 24px 64px rgba(0,0,0,0.7);
    animation: popIn 0.25s cubic-bezier(0.34,1.56,0.64,1);
  }
  @keyframes popIn {
    from { transform: scale(0.85); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
  }
  #watched-popup-icon { font-size: 48px; margin-bottom: 12px; }
  #watched-popup-title {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
  }
  #watched-popup-desc {
    font-size: 14px;
    color: var(--text2);
    line-height: 1.6;
    margin-bottom: 1.5rem;
  }
  #watched-popup-desc strong { color: var(--success); }
  #watched-popup-actions { display: flex; flex-direction: column; gap: 8px; }
  .wpop-btn {
    width: 100%;
    padding: 10px 16px;
    border-radius: var(--r);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.18s;
  }
  .wpop-confirm {
    background: var(--success-bg);
    border-color: var(--success);
    color: var(--success);
  }
  .wpop-confirm:hover { background: var(--success); color: #fff; }
  .wpop-cancel {
    background: transparent;
    border-color: var(--border2);
    color: var(--text2);
  }
  .wpop-cancel:hover { border-color: var(--text3); color: var(--text); }