.carbon-bg {
  background:
    var(--bg-texture),
    linear-gradient(rgba(24,26,36,0.88), rgba(24,26,36,0.88)) padding-box,
    repeating-linear-gradient(-45deg, rgba(99,102,241,0.04) 0 2px, transparent 2px 8px),
    linear-gradient(-45deg, rgba(99,102,241,0.08), rgba(34,211,238,0.02)) border-box;
  border-radius: var(--r-xl);
}
.modal-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.form-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  margin-bottom: 18px;
}
.input-label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-1);
  letter-spacing: 0.03em;
  margin-bottom: 2px;
  text-align: left;
}
.input.input-lg, .select-lg {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  color: var(--text-1);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  height: 48px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
/* Input focus styles */
.input.input-lg:focus {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18);
}
/* Select focus styles (increased specificity for cross-browser) */
select.input.select-lg:focus {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18);
}
.select-lg {
  appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg fill="%2394A3B8" height="18" viewBox="0 0 20 20" width="18" xmlns="http://www.w3.org/2000/svg"><path d="M7.293 7.293a1 1 0 011.414 0L10 8.586l1.293-1.293a1 1 0 111.414 1.414l-2 2a1 1 0 01-1.414 0l-2-2a1 1 0 010-1.414z"/></svg>');
  background-repeat: no-repeat;
  background-position: right 18px center;
  background-size: 18px 18px;
  padding-right: 38px;
}
/* Input placeholder style from styleguide */
.input.input-lg::placeholder {
  color: var(--text-3);
}
.select-lg option {
  background: var(--surface-solid);
  color: var(--text-1);
  font-size: 1em;
  padding: 10px 12px;
}
/* Onboarding modal polish */
.modal-desc {
  color: var(--text-2);
  font-size: 1.05em;
  margin-bottom: 18px;
  line-height: 1.5;
}
/* Onboarding modal styles */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(16, 18, 26, 0.72);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6vh;
  padding-bottom: 6vh;
  padding-left: 0;
  padding-right: 0;
}
.modal-content {
  position: relative;
  background:
    var(--bg-texture),
    linear-gradient(rgba(24,26,36,0.88), rgba(24,26,36,0.88)) padding-box,
    repeating-linear-gradient(-45deg, rgba(99,102,241,0.04) 0 2px, transparent 2px 8px),
    linear-gradient(-45deg, rgba(99,102,241,0.08), rgba(34,211,238,0.02)) border-box;
  border: none;
  border-radius: var(--r-xl);
  max-width: 400px;
  width: 100%;
  padding: 32px 28px 28px 28px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.32);
  text-align: left;
  color: var(--text-1);
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  margin: auto;
}
.modal-title {
  font-family: var(--ff-display);
  font-size: 1.5em;
  font-weight: 800;
  color: var(--text-1);
  margin-bottom: 24px;
  text-align: left;
  letter-spacing: 0.04em;
  position: relative;
}
/* Modal title underline */
.modal-title::after {
  content: "";
  display: block;
  margin-top: 8px;
  height: 1px;
  width: 100%;
  background: linear-gradient(90deg, var(--indigo), var(--pink));
  opacity: 0.4;
}

/* Wide modal variant for larger content */
.modal-content-wide {
  max-width: 800px;
}

/* Extra-wide modal for complex forms */
.modal-content-xl {
  max-width: 900px;
}

/* Two-column form layout for larger modals */
.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 24px;
}

.form-grid-2 .form-row-full {
  grid-column: 1 / -1;
}

@media (max-width: 700px) {
  .form-grid-2 {
    grid-template-columns: 1fr;
  }
  .modal-content-wide,
  .modal-content-xl {
    max-width: calc(100vw - 32px);
  }
}
.modal-desc { margin-bottom: 14px; }
.input {
  width: 100%;
  padding: var(--s-2);
  font-size: 1em;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}
.input:focus {
  border-color: var(--indigo);
  outline: 3px solid rgba(99,102,241,0.32);
}
/* Design tokens */
:root {
  color-scheme: dark;
  --bg-0: #0A0B10;
  --surface: rgba(22, 24, 34, 0.7);
  --surface-solid: #181A24;
  --border: rgba(99, 102, 241, 0.2);
  --border-strong: rgba(99, 102, 241, 0.6);

  --text-1: #F3F4F6;
  --text-2: #A1A1AA;
  --text-3: #94A3B8;
  --indigo: #6366F1;
  --pink: #F472B6;
  --azure: #22D3EE;
  --amber: #F59E0B;
  --jade: #34D399;
  --gold: #FFD700;
  --silver: #C0C0C0;
  --bronze: #CD7F32;
  --win: #22D3EE;
  --loss: #F472B6;

  /* Gradients */
  --grad-hero: linear-gradient(90deg, var(--indigo), var(--pink), var(--azure));
  --grad-primary: linear-gradient(135deg, var(--indigo), var(--pink));
  --grad-secondary: linear-gradient(135deg, var(--jade), var(--azure));

  /* Background texture: subtle diagonal weave (carbon-like) */
  --bg-texture:
    radial-gradient(ellipse at 20% 0%, rgba(99, 102, 241, 0.14), transparent 55%),
    radial-gradient(ellipse at 80% 100%, rgba(244, 114, 182, 0.08), transparent 60%),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.02) 0 2px, transparent 2px 6px);

  .form-row:focus-within .input-label { color: var(--text-1); }

  @media (max-width: 520px) {
    .form-row { flex-direction: column; align-items: stretch; gap: 6px; }
    .input-label { min-width: 0; text-align: left; }
  }
  /* Typography */
  --ff-primary: 'Inter', system-ui, -apple-system, sans-serif;
  --ff-display: 'Exo 2', sans-serif;

  /* Spacing */
  --s-1: 6px; --s-2: 10px; --s-3: 16px; --s-4: 24px; --s-5: 32px; --s-6: 48px; --s-7: 64px;

  /* Radius */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 18px; --r-pill: 9999px;

  /* Shadows */
  --shadow-indigo: 0 0 36px -8px rgba(99, 102, 241, 0.6);
  --shadow-pink: 0 0 36px -8px rgba(244, 114, 182, 0.6);
  --shadow-azure: 0 0 36px -8px rgba(34, 211, 238, 0.6);
  --shadow-card: 0 6px 28px rgba(0,0,0,0.45);

  /* Legacy aliases for backward compatibility */
  --bg: var(--bg-0);
  --panel: var(--surface-solid);
  --card: var(--surface-solid);
  --text: var(--text-1);
  --muted: var(--text-2);
  --chip: var(--surface-solid);
  --a1: var(--indigo);
  --a2: var(--jade);
  --a3: var(--pink);
  --accent-quiet: rgba(99, 102, 241, 0.1);
}
#userMenuDropdown a:hover, #userMenuDropdown a:focus {
  background: var(--surface);
  color: var(--text-1);
}
#userMenuDropdown a::after {
  content: none;
}
#userMenuDropdown #signOutBtn {
  color: #EF4444;
  font-weight: 700;
  border-top: 1px solid var(--border);
  margin-top: var(--s-2);
  padding: var(--s-1) var(--s-3);
}
#userMenuDropdown #signOutBtn:hover, #userMenuDropdown #signOutBtn:focus {
  color: #DC2626;
  background: rgba(239, 68, 68, 0.1);
}

    * {
      box-sizing: border-box;
      margin: 0;
    }
    html, body {
      height: 100%;
    }
    body {
      font-family: var(--ff-primary);
      background: var(--bg-0);
      background-image: var(--bg-texture);
      background-attachment: fixed;
      color: var(--text-1);
      position: relative;
      overflow-x: hidden;
      line-height: 1.6;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }
    body::before {
      content: "";
      position: fixed;
      inset: -20vmax;
      z-index: -1;
      /* More restrained ambient gradient */
      background:
        radial-gradient(900px 600px at 8% -12%, color-mix(in oklab, var(--a1) 16%, transparent), transparent 55%),
        radial-gradient(900px 600px at 102% 12%, color-mix(in oklab, var(--a2) 12%, transparent), transparent 55%);
      background-repeat: no-repeat;
      filter: saturate(1.15) contrast(1.05);
    }

    /* Typography */
    h1, h2, h3, h4 {
      font-family: var(--ff-display);
      font-weight: 700;
      letter-spacing: 0.02em;
    }
    p { color: var(--text-2); }
    a {
      color: var(--azure);
      text-decoration: none;
    }
    a:hover { color: var(--pink); }

    /* Buttons */
    .btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: var(--s-2);
      font-family: var(--ff-primary);
      font-weight: 700;
      letter-spacing: 0.05em;
      font-size: 0.95rem;
      padding: 12px 22px;
      border-radius: var(--r-pill);
      border: 2px solid transparent;
      cursor: pointer;
      transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }
    .btn-primary {
      background: var(--grad-primary);
      color: white;
      box-shadow: var(--shadow-indigo);
    }
    .btn-primary:hover {
      transform: translateY(-2px);
      box-shadow: var(--shadow-pink);
    }
    .btn-secondary {
      background: var(--grad-secondary);
      color: white;
      box-shadow: var(--shadow-azure);
    }
    .btn-secondary:hover {
      transform: translateY(-2px);
      box-shadow: var(--shadow-azure);
    }
    .btn-outline {
      background: transparent;
      color: var(--text-1);
      border-color: var(--border);
    }
    .btn-outline:hover {
      background: var(--surface);
      border-color: var(--border-strong);
    }
    .btn-ghost {
      background: transparent;
      color: var(--text-2);
    }
    .btn-ghost:hover {
      background: var(--surface);
      color: var(--text-1);
    }

    nav {
      position: sticky;
      top: 0;
      z-index: 100;
      display: grid;
      grid-template-columns: auto 1fr auto; /* logo / content / menu */
      align-items: center;
      padding: calc(var(--s-1) + 2px) var(--s-4);
      min-height: 58px;
      background: rgba(16, 18, 26, 0.78);
      backdrop-filter: blur(18px) saturate(180%);
      -webkit-backdrop-filter: blur(18px) saturate(180%);
      border-bottom: 1px solid rgba(99, 102, 241, 0.22);
  box-shadow: 0 18px 36px rgba(8, 12, 24, 0.72);
      margin-bottom: var(--s-6);
    }

    .nav-links {
      grid-column: 2;
      justify-self: start; /* left-align within center column */
      display: flex;
      align-items: center;
      gap: calc(var(--s-3) + 12px); /* slightly more breathing room */
      margin-left: var(--s-6); /* a lot more spacing between logo and titles */
    }

    .refa-logo {
      grid-column: 1;
      justify-self: start;
      font-family: var(--ff-display);
      font-weight: 900;
      font-size: 1.8rem;
      letter-spacing: 0.15em;
      text-transform: uppercase;
      background: var(--grad-primary);
      background-clip: text;
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      flex-shrink: 0;
    }

    nav a {
      color: var(--text-2);
      font-weight: 600;
      font-size: 0.92rem;
      /* text-transform: uppercase; */
      letter-spacing: 0.06em; /* slightly tighter for a refined look */
      text-decoration: none;
      position: relative;
      padding: var(--s-1) 0;
      transition: color 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }
    nav a:hover,
    nav a:focus-visible {
      color: var(--text-1);
    }
    nav a[aria-current="page"],
    nav a.active {
      color: var(--text-1);
    }
    nav a::after {
      content: '';
      position: absolute;
      bottom: -3px; /* bring underline closer to text */
      left: 0;
      width: 0;
      height: 2px;
      background: var(--grad-primary);
      border-radius: 999px;
      transition: width 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }
    nav a:hover::after,
    nav a:focus-visible::after {
      width: 100%;
    }
    nav a[aria-current="page"]::after,
    nav a.active::after {
      width: 100%;
    }

    /* Notification bell inline with user menu */
    .notification-bell {
      display: flex;
      align-items: center;
    }

    /* Right side of nav: notification + user menu */
    .nav-right {
      grid-column: 3;
      justify-self: end;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    #userMenu {
      position: relative;
      display: flex;
      align-items: center;
    }

    #userMenuButton {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 6px 18px 6px 8px;
      border-radius: var(--r-pill);
      font-family: var(--ff-primary);
      font-size: 0.95rem;
      font-weight: 700;
      letter-spacing: 0.05em;
      color: var(--text-1);
      background: transparent;
      border: 2px solid var(--border);
      cursor: pointer;
      box-shadow: none;
      transition: none;
    }
    #userMenuButton:hover,
    #userMenuButton:focus-visible {
      border-color: var(--border-strong);
      color: var(--text-1);
      background: var(--surface);
      transition: none;
    }
    #userMenuButton:focus-visible {
      outline: 2px solid var(--azure);
      outline-offset: 3px;
    }
    #userMenuButton.open {
      border-color: var(--indigo);
      background: var(--surface);
    }

    #userMenuButton.has-avatar #userAvatarContainer {
      display: flex;
    }

    #userAvatarContainer {
      display: none;
      width: 34px;
      height: 34px;
      border-radius: 50%; /* perfect circle */
      overflow: hidden;
      background: linear-gradient(var(--surface), var(--surface)) padding-box,
                  linear-gradient(135deg, rgba(99,102,241,0.45), rgba(244,114,182,0.35)) border-box;
      border: 1px solid transparent;
      align-items: center;
      justify-content: center;
      pointer-events: none;
  margin-left: -2px; /* nudge 1px right for fine-tuned alignment */
      box-shadow: 0 2px 8px rgba(0,0,0,0.35) inset;
    }

    #userAvatarContainer .user-avatar {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }

    #userMenuName {
      white-space: nowrap;
    }

    .user-menu-caret {
      width: 0;
      height: 0;
      border-left: 5px solid transparent;
      border-right: 5px solid transparent;
      border-top: 6px solid var(--text-2);
      transition: transform 0.2s ease, border-top-color 0.2s ease;
      margin-left: 8px;
    }

    #userMenuButton:not(.is-authenticated) .user-menu-caret {
      display: none;
    }

    #userMenuButton.open .user-menu-caret {
      transform: rotate(180deg);
      border-top-color: var(--text-1);
    }

    #userMenuDropdown {
      position: absolute;
      top: calc(100% + var(--s-2));
      right: 0;
      min-width: 220px;
      background: linear-gradient(var(--surface), var(--surface)) padding-box,
                  linear-gradient(135deg, rgba(99,102,241,0.35), rgba(34,211,238,0.18)) border-box;
      color: var(--text-1);
      border-radius: var(--r-lg);
      border: 1px solid transparent;
      box-shadow: var(--shadow-card), 0 20px 40px rgba(8, 12, 24, 0.45);
      padding: var(--s-2);
      visibility: hidden;
      z-index: 100;
      opacity: 0;
      transform: translateY(-10px);
      transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.3s ease;
      overflow: hidden;
    }
    #userMenuDropdown.show {
      visibility: visible;
      opacity: 1;
      transform: translateY(0);
    }
    /* remove decorative top line for edge-to-edge look */
    #userMenuDropdown::before { content: none; }
    #userMenuDropdown a {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: var(--s-2);
      padding: 10px 14px; /* consistent hit area */
      color: var(--text-2);
      font-weight: 600;
      font-size: 0.9rem;
      letter-spacing: 0.04em;
      border-radius: var(--r-md);
      transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
      text-decoration: none;
    }
    #userMenuDropdown a:hover,
    #userMenuDropdown a:focus-visible {
      background: linear-gradient(135deg, rgba(99,102,241,0.22), rgba(244,114,182,0.16));
      color: var(--text-1);
      /* remove translate movement */
    }
    #userMenuDropdown #signOutBtn {
      color: #ef4444;
      font-weight: 700;
      border-top: 1px solid rgba(239, 68, 68, 0.2);
      margin-top: var(--s-2);
      padding: 10px 14px; /* match other items */
    }
    #userMenuDropdown #signOutBtn:hover,
    #userMenuDropdown #signOutBtn:focus-visible {
      background: rgba(239, 68, 68, 0.12);
      color: #f87171;
    }

/* Toast notification animations */
@keyframes toastSlideIn {
  from {
    transform: translate(-50%, -100%);
    opacity: 0;
  }
  to {
    transform: translateX(-50%);
    opacity: 1;
  }
}

@keyframes toastSlideOut {
  from {
    transform: translateX(-50%);
    opacity: 1;
  }
  to {
    transform: translate(-50%, -100%);
    opacity: 0;
  }
}