:root {
      --crimson: #e8192c;
      --crimson-light: #ff3347;
      --crimson-glow: rgba(232, 25, 44, 0.3);
      --gold: #f0a500;
      --bg-deep: #04040a;
      --bg-card: rgba(10, 10, 22, 0.85);
      --bg-item: rgba(255,255,255,0.03);
      --text-primary: #f0eff5;
      --text-muted: #6e6d85;
      --border-subtle: rgba(255,255,255,0.07);
      --border-accent: rgba(232, 25, 44, 0.35);
    }

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

    body {
      font-family: 'Outfit', sans-serif;
      background: var(--bg-deep);
      color: var(--text-primary);
      min-height: 100vh;
      overflow-x: hidden;
    }

    /* ── Background ── */
    .bg-fixed {
      position: fixed;
      inset: 0;
      z-index: 0;
      pointer-events: none;
    }

    .bg-fixed::before {
      content: '';
      position: absolute;
      inset: 0;
      background:
        radial-gradient(ellipse 70% 50% at 0% 0%, rgba(232,25,44,0.07) 0%, transparent 60%),
        radial-gradient(ellipse 50% 70% at 100% 100%, rgba(80,10,180,0.06) 0%, transparent 60%);
    }

    .bg-fixed::after {
      content: '';
      position: absolute;
      inset: 0;
      background-image:
        linear-gradient(rgba(232,25,44,0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(232,25,44,0.025) 1px, transparent 1px);
      background-size: 50px 50px;
      mask-image: radial-gradient(ellipse 100% 100% at 50% 0%, black 20%, transparent 80%);
      animation: gridDrift 25s linear infinite;
    }

    @keyframes gridDrift {
      0% { transform: translate(0,0); }
      100% { transform: translate(50px, 50px); }
    }

    /* ── Page ── */
    .profile-page {
      position: relative;
      z-index: 10;
      max-width: 1180px;
      margin: 0 auto;
      padding: 90px 20px 60px; /* top padding accounts for fixed navbar */
    }

    /* ── Hero Banner ── */
    .profile-hero {
      position: relative;
      border-radius: 20px;
      margin-bottom: 30px;
      overflow: hidden;
    }

    .hero-bg {
      position: absolute;
      inset: 0;
      background: linear-gradient(135deg, rgba(232,25,44,0.12) 0%, rgba(80,10,180,0.1) 50%, rgba(0,0,0,0) 100%);
      border: 1px solid var(--border-accent);
      border-radius: 20px;
    }

    .hero-bg::after {
      content: '';
      position: absolute;
      inset: 0;
      background: radial-gradient(ellipse 80% 100% at 100% 50%, rgba(240,165,0,0.04), transparent);
    }

    /* Top highlight line */
    .hero-bg::before {
      content: '';
      position: absolute;
      top: 0; left: 0; right: 0;
      height: 1px;
      background: linear-gradient(90deg, transparent, var(--crimson), var(--gold), var(--crimson), transparent);
      opacity: 0.6;
    }

    .hero-content {
      position: relative;
      z-index: 2;
      padding: 36px 36px 30px;
      display: flex;
      align-items: flex-end;
      gap: 28px;
    }

    /* Avatar */
    .avatar-wrap {
      position: relative;
      flex-shrink: 0;
    }

    .avatar-ring {
      position: absolute;
      inset: -4px;
      border-radius: 50%;
      background: conic-gradient(var(--crimson), var(--gold), var(--crimson));
      animation: ringRotate 4s linear infinite;
    }

    @keyframes ringRotate { to { transform: rotate(360deg); } }

    .avatar-mask {
      position: absolute;
      inset: 2px;
      border-radius: 50%;
      background: var(--bg-deep);
    }

    .avatar-circle {
      position: relative;
      z-index: 2;
      width: 100px; height: 100px;
      border-radius: 50%;
      background: linear-gradient(135deg, var(--crimson), #8b0010);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 40px;
      font-weight: 800;
      color: #fff;
      letter-spacing: -1px;
      box-shadow: 0 8px 32px var(--crimson-glow);
    }

    .avatar-status {
      position: absolute;
      bottom: 4px; right: 4px;
      z-index: 3;
      width: 18px; height: 18px;
      background: #4ade80;
      border-radius: 50%;
      border: 3px solid var(--bg-deep);
      box-shadow: 0 0 8px rgba(74,222,128,0.5);
    }

    /* Meta */
    .hero-meta {
      flex: 1;
      min-width: 0;
    }

    .hero-meta h1 {
      font-size: 32px;
      font-weight: 900;
      color: var(--text-primary);
      margin-bottom: 4px;
      letter-spacing: -0.5px;
      line-height: 1.1;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      max-width: 100%;
    }

    .hero-meta .email {
      font-size: 14px;
      color: var(--text-muted);
      margin-bottom: 2px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      max-width: 100%;
    }

    .hero-meta .joined {
      font-size: 12px;
      color: var(--text-muted);
      display: flex;
      align-items: center;
      gap: 5px;
    }

    .hero-meta .joined svg { width: 12px; height: 12px; opacity: 0.5; }

    .hero-badge {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      margin-top: 10px;
      padding: 4px 10px;
      background: rgba(240,165,0,0.1);
      border: 1px solid rgba(240,165,0,0.25);
      border-radius: 20px;
      font-size: 11px;
      font-weight: 700;
      color: var(--gold);
      letter-spacing: 0.5px;
      text-transform: uppercase;
    }

    .hero-badge svg { width: 12px; height: 12px; }

    /* Signout btn */
    .btn-signout {
      padding: 10px 18px;
      background: rgba(255,255,255,0.05);
      border: 1px solid var(--border-subtle);
      border-radius: 10px;
      color: var(--text-muted);
      font-family: 'Outfit', sans-serif;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      display: flex;
      align-items: center;
      gap: 7px;
      transition: all 0.2s;
      flex-shrink: 0;
      align-self: flex-start;
    }

    .btn-signout:hover {
      background: rgba(232,25,44,0.1);
      border-color: var(--border-accent);
      color: var(--crimson-light);
    }

    .btn-signout svg { width: 14px; height: 14px; }

    /* ── Stats ── */
    .stats-row {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
      gap: 14px;
      margin-bottom: 40px;
    }

    .stat-card {
      background: var(--bg-card);
      border: 1px solid var(--border-subtle);
      border-radius: 14px;
      padding: 22px 20px;
      position: relative;
      overflow: hidden;
      backdrop-filter: blur(16px);
      transition: border-color 0.3s, transform 0.3s, box-shadow 0.3s;
      cursor: default;
    }

    .stat-card::after {
      content: '';
      position: absolute;
      inset: 0;
      background: var(--stat-glow, rgba(232,25,44,0.04));
      opacity: 0;
      transition: opacity 0.3s;
      border-radius: 14px;
    }

    .stat-card:hover {
      border-color: var(--stat-color, var(--border-accent));
      transform: translateY(-4px);
      box-shadow: 0 12px 30px rgba(0,0,0,0.3);
    }

    .stat-card:hover::after { opacity: 1; }

    .stat-icon {
      font-size: 22px;
      margin-bottom: 10px;
      display: block;
    }

    .stat-num {
      font-size: 38px;
      font-weight: 900;
      letter-spacing: -1px;
      line-height: 1;
      background: var(--stat-gradient, linear-gradient(135deg, #fff, #aaa));
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      margin-bottom: 4px;
    }

    .stat-label {
      font-size: 11.5px;
      font-weight: 600;
      color: var(--text-muted);
      text-transform: uppercase;
      letter-spacing: 1px;
    }

    /* Decorative bar at bottom of stat */
    .stat-bar {
      position: absolute;
      bottom: 0; left: 0; right: 0;
      height: 2px;
      background: var(--stat-gradient, linear-gradient(90deg, var(--crimson), var(--gold)));
      transform: scaleX(0);
      transform-origin: left;
      transition: transform 0.4s ease;
    }

    .stat-card:hover .stat-bar { transform: scaleX(1); }

    /* ── Alert ── */
    .config-alert {
      background: rgba(240,165,0,0.07);
      border: 1px solid rgba(240,165,0,0.2);
      border-radius: 12px;
      padding: 14px 18px;
      margin-bottom: 28px;
      font-size: 13px;
      color: var(--gold);
      display: flex;
      align-items: flex-start;
      gap: 10px;
      line-height: 1.5;
    }

    .config-alert svg { flex-shrink: 0; margin-top: 1px; }

    .config-alert code {
      background: rgba(0,0,0,0.3);
      padding: 1px 6px;
      border-radius: 4px;
      font-size: 12px;
      font-family: monospace;
      color: #ffd060;
    }

    /* ── Section ── */
    .section {
      margin-bottom: 48px;
    }

    .section-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 20px;
    }

    .section-title {
      font-size: 17px;
      font-weight: 800;
      color: var(--text-primary);
      display: flex;
      align-items: center;
      gap: 10px;
      letter-spacing: -0.3px;
    }

    .section-title .icon-bg {
      width: 30px; height: 30px;
      border-radius: 8px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
    }

    .section-count {
      font-size: 11px;
      font-weight: 700;
      color: var(--text-muted);
      background: var(--bg-item);
      border: 1px solid var(--border-subtle);
      border-radius: 20px;
      padding: 3px 10px;
    }

    /* ── Cards grid ── */
    .cards-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
      gap: 14px;
    }

    .anime-card {
      position: relative;
      background: var(--bg-item);
      border: 1px solid var(--border-subtle);
      border-radius: 12px;
      overflow: hidden;
      text-decoration: none;
      color: inherit;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      transition: border-color 0.25s, transform 0.25s, box-shadow 0.25s;
    }

    .anime-card:hover {
      border-color: var(--border-accent);
      transform: translateY(-6px) scale(1.02);
      box-shadow: 0 16px 40px rgba(0,0,0,0.4), 0 0 20px rgba(232,25,44,0.1);
    }

    .card-img-wrap {
      position: relative;
      overflow: hidden;
    }

    .card-img-wrap::after {
      content: '';
      position: absolute;
      bottom: 0; left: 0; right: 0;
      height: 50%;
      background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
      pointer-events: none;
    }

    .anime-card img {
      width: 100%;
      height: 175px;
      object-fit: cover;
      display: block;
      background: rgba(255,255,255,0.04);
      transition: transform 0.35s ease;
    }

    .anime-card:hover img { transform: scale(1.06); }

    /* Episode badge */
    .ep-badge {
      position: absolute;
      top: 8px; left: 8px;
      z-index: 2;
      background: var(--crimson);
      color: #fff;
      font-size: 10px;
      font-weight: 800;
      padding: 3px 7px;
      border-radius: 6px;
      letter-spacing: 0.3px;
      box-shadow: 0 2px 8px rgba(232,25,44,0.4);
    }

    /* Play overlay */
    .play-overlay {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      background: rgba(0,0,0,0.45);
      opacity: 0;
      transition: opacity 0.25s;
      z-index: 3;
    }

    .anime-card:hover .play-overlay { opacity: 1; }

    .play-overlay svg {
      width: 36px; height: 36px;
      color: #fff;
      filter: drop-shadow(0 2px 8px rgba(0,0,0,0.5));
    }

    .card-body {
      padding: 10px 12px 12px;
      flex: 1;
      display: flex;
      flex-direction: column;
    }

    .card-title {
      font-size: 12px;
      font-weight: 700;
      color: var(--text-primary);
      line-height: 1.35;
      margin-bottom: 6px;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .card-date {
      font-size: 10.5px;
      color: var(--text-muted);
      margin-top: auto;
      font-weight: 500;
    }

    .card-heart {
      position: absolute;
      top: 8px; right: 8px;
      z-index: 2;
      background: rgba(232,25,44,0.85);
      width: 26px; height: 26px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      backdrop-filter: blur(4px);
    }

    .card-heart svg { width: 12px; height: 12px; color: #fff; }

    /* ── Empty State ── */
    .empty-state {
      text-align: center;
      padding: 70px 30px;
      background: var(--bg-item);
      border: 1px dashed rgba(255,255,255,0.08);
      border-radius: 16px;
      animation: fadeIn 0.5s ease;
    }

    @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

    .empty-icon {
      width: 64px; height: 64px;
      margin: 0 auto 18px;
      background: rgba(232,25,44,0.08);
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .empty-icon svg { width: 30px; height: 30px; color: var(--crimson); opacity: 0.6; }

    .empty-state h3 {
      font-size: 18px;
      font-weight: 800;
      color: var(--text-primary);
      margin-bottom: 6px;
    }

    .empty-state p {
      font-size: 13.5px;
      color: var(--text-muted);
      margin-bottom: 24px;
    }

    .btn-browse {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      padding: 11px 22px;
      background: linear-gradient(135deg, var(--crimson), #b0001a);
      border: none;
      border-radius: 10px;
      color: #fff;
      font-family: 'Outfit', sans-serif;
      font-size: 14px;
      font-weight: 700;
      text-decoration: none;
      cursor: pointer;
      transition: transform 0.2s, box-shadow 0.2s;
      box-shadow: 0 4px 20px var(--crimson-glow);
    }

    .btn-browse:hover {
      transform: translateY(-2px);
      box-shadow: 0 8px 28px rgba(232,25,44,0.4);
    }

    /* ── Loading ── */
    .loading-screen {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      min-height: 60vh;
      gap: 18px;
    }

    .loading-logo {
      font-size: 22px;
      font-weight: 800;
      letter-spacing: -0.5px;
      color: var(--text-primary);
    }

    .loading-logo span {
      background: linear-gradient(135deg, var(--crimson-light), var(--gold));
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }

    .loading-spinner {
      width: 36px; height: 36px;
      border: 3px solid rgba(232,25,44,0.2);
      border-top-color: var(--crimson);
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
    }

    @keyframes spin { to { transform: rotate(360deg); } }

    .loading-text {
      font-size: 13px;
      color: var(--text-muted);
      font-weight: 500;
    }

    /* ── Responsive ── */

    /* Tablet (769px – 1024px) */
    @media (max-width: 1024px) {
      .profile-page { padding: 84px 24px 50px; }
      .hero-content { padding: 30px 30px 26px; gap: 22px; }
      .hero-meta h1 { font-size: 28px; }
      .avatar-circle { width: 90px; height: 90px; font-size: 36px; }
      .stats-row { gap: 12px; }
      .stat-card { padding: 18px 16px; }
      .stat-num { font-size: 34px; }
      .cards-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    }

    /* ── Mobile: convert cards to HORIZONTAL SCROLL ── */
    @media (max-width: 768px) {
      .profile-page { padding: 80px 16px 50px; }

      /* Hero */
      .hero-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
        padding: 24px 20px 20px;
      }
      .hero-meta { width: 100%; min-width: 0; }
      .hero-meta h1 { font-size: 26px; }
      .avatar-circle { width: 80px; height: 80px; font-size: 32px; }
      .btn-signout { align-self: stretch; width: 100%; justify-content: center; }

      /* Stats */
      .stats-row { grid-template-columns: repeat(3, 1fr); gap: 10px; }
      .stat-num { font-size: 28px; }

      /* Section – relative so fade overlay positions correctly */
      .section { position: relative; }

      /* Right-edge fade hint — shows there's more to scroll */
      .section::after {
        content: '';
        position: absolute;
        right: 0;
        top: 48px;          /* below section-header */
        bottom: 14px;
        width: 48px;
        background: linear-gradient(to left, var(--bg-deep) 0%, transparent 100%);
        pointer-events: none;
        z-index: 10;
      }

      /* Horizontal scroll row */
      .cards-grid {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: visible;
        gap: 12px;
        /* bleed to screen edges, padding keeps first card aligned */
        margin-left: -16px;
        margin-right: -16px;
        padding-left: 16px;
        padding-right: 60px;   /* space for fade + last card breathing room */
        padding-bottom: 14px;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;           /* Firefox */
      }
      .cards-grid::-webkit-scrollbar { display: none; } /* Chrome / Safari / Edge */

      /* Fixed-width cards — never shrink */
      .anime-card {
        flex: 0 0 130px;
        width: 130px;
        scroll-snap-align: start;
      }
      .anime-card:hover { transform: translateY(-4px) scale(1.01); }
      .anime-card img { height: 172px; }

      /* Section header wraps gracefully when title + count don't fit */
      .section-header { flex-wrap: wrap; gap: 8px; }

      /* Alerts & empty state take up less room on mobile */
      .config-alert { padding: 12px 14px; font-size: 12.5px; }
      .empty-state { padding: 50px 20px; }
      .empty-icon { width: 52px; height: 52px; margin-bottom: 14px; }
      .btn-browse { width: 100%; justify-content: center; }

      /* Comfortable touch target */
      .btn-signout { min-height: 46px; }
    }

    /* Mobile portrait ≤ 480px */
    @media (max-width: 480px) {
      .profile-page { padding: 75px 12px 40px; }
      .hero-content { padding: 20px 16px 18px; gap: 14px; }
      .hero-meta h1 { font-size: 22px; }
      .hero-meta .email { font-size: 13px; }

      .stats-row { gap: 8px; }
      .stat-card { padding: 16px 10px; }
      .stat-icon { font-size: 18px; margin-bottom: 6px; }
      .stat-num { font-size: 26px; }
      .stat-label { font-size: 10px; letter-spacing: 0.5px; }

      .empty-state { padding: 40px 16px; }
      .empty-state h3 { font-size: 16px; }
      .empty-state p { font-size: 12.5px; margin-bottom: 18px; }

      .cards-grid {
        margin-left: -12px;
        margin-right: -12px;
        padding-left: 12px;
        padding-right: 52px;
        gap: 10px;
      }
      .anime-card { flex: 0 0 118px; width: 118px; }
      .anime-card img { height: 158px; }
    }

    /* Small phones ≤ 375px */
    @media (max-width: 375px) {
      .profile-page { padding: 70px 10px 36px; }
      .hero-meta h1 { font-size: 20px; }
      .avatar-circle { width: 70px; height: 70px; font-size: 28px; }

      .stats-row { gap: 6px; }
      .stat-card { padding: 12px 8px; }
      .stat-num { font-size: 22px; }
      .stat-label { font-size: 9.5px; }
      .hero-badge { font-size: 10px; padding: 3px 8px; }

      .cards-grid {
        margin-left: -10px;
        margin-right: -10px;
        padding-left: 10px;
        padding-right: 46px;
        gap: 9px;
      }
      .anime-card { flex: 0 0 110px; width: 110px; }
      .anime-card img { height: 148px; }
    }

    /* Fold / tiny phones ≤ 320px */
    @media (max-width: 320px) {
      .stats-row { gap: 5px; }
      .stat-card { padding: 10px 6px; }
      .stat-num { font-size: 18px; }

      .cards-grid { padding-left: 10px; padding-right: 42px; gap: 8px; }
      .anime-card { flex: 0 0 100px; width: 100px; }
      .anime-card img { height: 136px; }
    }


    /* Profile picture image support */
    .avatar-circle {
      overflow: hidden;
    }
    .avatar-circle img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      border-radius: 50%;
    }
    .avatar-wrap {
      cursor: pointer;
      position: relative;
    }

    /* Pencil icon overlay on hover */
    .avatar-wrap::after {
      content: '✎';
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      background: rgba(0, 0, 0, 0.6);
      border-radius: 50%;
      color: #fff;
      font-size: 32px;
      font-weight: 700;
      opacity: 0;
      transition: opacity 0.25s ease;
      z-index: 10;
      pointer-events: none;
    }

    .avatar-wrap:hover::after {
      opacity: 1;
    }

    .avatar-wrap:hover .avatar-ring {
      border-color: rgba(230,57,70,0.7);
      box-shadow: 0 0 20px rgba(230,57,70,0.3);
    }

    .avatar-wrap:active::after {
      opacity: 1;
      transform: scale(0.95);
    }

    /* ── Accessibility & device capability ── */

    /* Respect reduced-motion preference */
    @media (prefers-reduced-motion: reduce) {
      *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
      }
    }

    /* Visible keyboard focus on every interactive element */
    .btn-signout:focus-visible,
    .btn-browse:focus-visible,
    .anime-card:focus-visible,
    .avatar-wrap:focus-visible,
    .stat-card:focus-visible {
      outline: 2px solid var(--crimson-light);
      outline-offset: 3px;
      border-radius: 8px;
    }

    /* Touch devices: kill "stuck" hover state after a tap, swap in a tap response instead */
    @media (hover: none) {
      .anime-card:hover { transform: none; box-shadow: none; }
      .anime-card:hover img { transform: none; }
      .anime-card:hover .play-overlay { opacity: 0; }
      .anime-card:active { transform: scale(0.97); transition: transform 0.1s; }
      .anime-card:active .play-overlay { opacity: 1; }

      .stat-card:hover { transform: none; box-shadow: none; border-color: var(--border-subtle); }
      .stat-card:hover .stat-bar { transform: scaleX(0); }
      .stat-card:active { transform: scale(0.97); }

      .btn-browse:hover { transform: none; box-shadow: 0 4px 20px var(--crimson-glow); }
      .btn-signout:hover { background: rgba(255,255,255,0.05); border-color: var(--border-subtle); color: var(--text-muted); }
      .avatar-wrap:hover .avatar-ring { border-color: rgba(232,25,44,0.35); }
      .avatar-wrap:hover::after { opacity: 0; }
    }

    /* Large desktop / wide monitors — give the hero a little more room to breathe */
    @media (min-width: 1440px) {
      .profile-page { max-width: 1280px; }
      .hero-content { padding: 42px 42px 36px; }
      .hero-meta h1 { font-size: 36px; }
      .stat-num { font-size: 42px; }
    }

    /* Short-height / landscape phones — recover vertical space the portrait rules waste */
    @media (max-width: 768px) and (max-height: 480px) {
      .profile-page { padding-top: 64px; }
      .loading-screen { min-height: 40vh; }
      .hero-content { flex-direction: row; align-items: center; padding: 16px 24px; gap: 18px; }
      .avatar-circle { width: 64px; height: 64px; font-size: 26px; }
      .btn-signout { align-self: center; width: auto; min-height: 38px; }
      .stats-row { grid-template-columns: repeat(6, 1fr); }
    }