/* ===================================================================
   Profile Center  -  Apple-inspired redesign
   =================================================================== */

/* --- Design tokens ------------------------------------------------ */
:root {
  --p-space-1: 8px;
  --p-space-2: 16px;
  --p-space-3: 24px;
  --p-space-4: 32px;
  --p-space-5: 48px;
  --p-space-6: 64px;

  --p-radius-s: 14px;
  --p-radius-m: 22px;
  --p-radius-l: 30px;

  --p-bg: #f5f5f7;
  --p-bg-alt: #e8e8ed;
  --p-surface: rgba(255, 255, 255, 0.72);
  --p-surface-solid: rgba(255, 255, 255, 0.92);
  --p-surface-hover: rgba(255, 255, 255, 0.88);
  --p-border: rgba(0, 0, 0, 0.06);
  --p-border-strong: rgba(0, 0, 0, 0.12);

  --p-ink: #1d1d1f;
  --p-ink-secondary: #6e6e73;
  --p-ink-tertiary: #86868b;

  --p-accent: #0071e3;
  --p-accent-hover: #0077ed;
  --p-accent-soft: rgba(0, 113, 227, 0.08);
  --p-focus: rgba(0, 125, 250, 0.6);

  --p-danger: #ff3b30;
  --p-danger-hover: #e0342b;
  --p-danger-soft: rgba(255, 59, 48, 0.08);

  --p-success: #34c759;
  --p-warning: #ff9500;

  --p-shadow-card:
    0 2px 8px rgba(0, 0, 0, 0.04),
    0 12px 40px rgba(0, 0, 0, 0.06);
  --p-shadow-hover:
    0 4px 16px rgba(0, 0, 0, 0.06),
    0 16px 48px rgba(0, 0, 0, 0.1);
  --p-shadow-hero:
    0 4px 12px rgba(0, 0, 0, 0.03),
    0 20px 60px rgba(0, 0, 0, 0.08);

  /* keep old names alive so JS/tests never break */
  --profile-space-1: var(--p-space-1);
  --profile-space-2: var(--p-space-2);
  --profile-space-3: var(--p-space-3);
  --profile-space-4: var(--p-space-4);
  --profile-space-5: var(--p-space-5);
  --profile-radius-s: var(--p-radius-s);
  --profile-radius-m: var(--p-radius-m);
  --profile-radius-l: var(--p-radius-l);
  --profile-bg-top: var(--p-bg);
  --profile-bg-bottom: var(--p-bg-alt);
  --profile-surface: var(--p-surface);
  --profile-surface-strong: var(--p-surface-solid);
  --profile-border: var(--p-border);
  --profile-ink: var(--p-ink);
  --profile-muted: var(--p-ink-secondary);
  --profile-accent: var(--p-accent);
  --profile-accent-strong: var(--p-accent-hover);
  --profile-focus: var(--p-focus);
  --profile-danger: var(--p-danger);
  --profile-danger-strong: var(--p-danger-hover);
  --profile-shadow: var(--p-shadow-card);
}

/* --- Reset -------------------------------------------------------- */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

/* --- Page shell --------------------------------------------------- */
body.profile-page {
  min-height: 100vh;
  font-family:
    'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display',
    'Segoe UI', Helvetica, Arial, sans-serif;
  line-height: 1.5;
  color: var(--p-ink);
  background: var(--p-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.profile-page [hidden] {
  display: none !important;
}

/* --- Skip link ---------------------------------------------------- */
.profile-skip-link {
  position: absolute;
  left: var(--p-space-2);
  top: -60px;
  z-index: 100;
  border-radius: var(--p-radius-s);
  padding: var(--p-space-1) var(--p-space-3);
  background: var(--p-accent);
  color: #ffffff;
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
  transition: top 0.2s ease;
}

.profile-skip-link:focus-visible {
  top: var(--p-space-2);
}

/* --- Header bar --------------------------------------------------- */
.profile-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: var(--p-space-2);
  width: min(980px, calc(100% - 48px));
  margin: var(--p-space-3) auto var(--p-space-2);
  padding: 10px var(--p-space-2);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius-m);
  background: rgba(245, 245, 247, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.profile-home-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 980px;
  border: 1px solid var(--p-border-strong);
  padding: 8px 18px;
  color: var(--p-accent);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  background: var(--p-surface-solid);
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    transform 0.15s ease;
}

.profile-home-link:hover {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.18);
  transform: scale(1.02);
}

/* --- Main container ----------------------------------------------- */
.profile-main {
  width: min(980px, calc(100% - 48px));
  margin: 0 auto var(--p-space-6);
  display: grid;
  gap: var(--p-space-3);
}

/* --- Hero section ------------------------------------------------- */
.profile-hero {
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius-l);
  background:
    linear-gradient(135deg,
      rgba(255, 255, 255, 0.96) 0%,
      rgba(255, 255, 255, 0.7) 100%);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--p-shadow-hero);
  padding: var(--p-space-5) var(--p-space-5);
  animation: heroEntrance 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes heroEntrance {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.profile-kicker {
  margin: 0;
  color: var(--p-accent);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
}

.profile-hero h1 {
  margin: var(--p-space-1) 0 0;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  font-weight: 700;
  max-width: 18ch;
  background: linear-gradient(135deg,
      var(--p-ink) 0%,
      #4a4a4f 40%,
      var(--p-accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.profile-hero-copy {
  margin: var(--p-space-2) 0 0;
  color: var(--p-ink-secondary);
  font-size: 1.0625rem;
  line-height: 1.6;
  max-width: 52ch;
}

.profile-hero-actions {
  margin-top: var(--p-space-4);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

/* --- Card grid ---------------------------------------------------- */
.profile-grid {
  display: grid;
  gap: var(--p-space-3);
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

/* --- Card base ---------------------------------------------------- */
.profile-card {
  position: relative;
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius-m);
  background: var(--p-surface);
  backdrop-filter: saturate(180%) blur(40px);
  -webkit-backdrop-filter: saturate(180%) blur(40px);
  box-shadow: var(--p-shadow-card);
  padding: var(--p-space-3) var(--p-space-3) var(--p-space-4);
  overflow: hidden;
  transition:
    box-shadow 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    border-color 0.25s ease;
  animation: cardEntrance 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.profile-card:hover {
  box-shadow: var(--p-shadow-hover);
  transform: translateY(-2px);
  border-color: var(--p-border-strong);
}

@keyframes cardEntrance {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* staggered entrance for each card */
.profile-auth-card {
  animation-delay: 0.08s;
}

.profile-identity-card {
  animation-delay: 0.14s;
}

.profile-edit-card {
  animation-delay: 0.20s;
}

.profile-recovery-card {
  animation-delay: 0.26s;
}

.profile-battle-pass-card {
  animation-delay: 0.32s;
}

.profile-scores-card {
  animation-delay: 0.38s;
}

.profile-overall-card {
  animation-delay: 0.44s;
}

.profile-danger-card {
  animation-delay: 0.50s;
}

/* --- Card spanning ------------------------------------------------ */
.profile-auth-card {
  grid-column: span 5;
}

.profile-identity-card,
.profile-battle-pass-card,
.profile-overall-card {
  grid-column: span 7;
}

.profile-edit-card,
.profile-recovery-card,
.profile-scores-card,
.profile-danger-card {
  grid-column: span 6;
}

/* --- Card header -------------------------------------------------- */
.profile-card-head {
  display: grid;
  gap: 4px;
  margin-bottom: var(--p-space-3);
}

.profile-card-kicker {
  margin: 0;
  color: var(--p-ink-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.6875rem;
  font-weight: 700;
}

.profile-card h2 {
  margin: 0;
  line-height: 1.2;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--p-ink);
}

.profile-panel-body {
  display: grid;
  gap: var(--p-space-2);
}

/* --- Lock state --------------------------------------------------- */
.profile-lock-note {
  display: none;
  position: absolute;
  top: var(--p-space-3);
  right: var(--p-space-3);
  border-radius: 980px;
  border: 1px solid var(--p-border-strong);
  background: var(--p-surface-solid);
  color: var(--p-ink-secondary);
  padding: 5px 14px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.profile-card.is-locked .profile-lock-note {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.profile-card.is-locked .profile-lock-note::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--p-ink-tertiary);
}

.profile-card.is-locked .profile-panel-body {
  opacity: 0.32;
  pointer-events: none;
  filter: blur(1px);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

/* --- Segment toggle (auth tabs) ----------------------------------- */
.profile-segment {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--p-border-strong);
  border-radius: 980px;
  padding: 3px;
  gap: 2px;
  background: var(--p-bg-alt);
}

.profile-segment-btn {
  appearance: none;
  border: 0;
  border-radius: 980px;
  background: transparent;
  color: var(--p-ink-secondary);
  padding: 8px 18px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.25s ease,
    color 0.25s ease,
    box-shadow 0.25s ease;
}

.profile-segment-btn.is-active {
  background: #ffffff;
  color: var(--p-ink);
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.08),
    0 2px 8px rgba(0, 0, 0, 0.04);
}

.profile-segment-btn:hover:not(.is-active) {
  color: var(--p-ink);
}

/* --- Forms -------------------------------------------------------- */
.profile-form {
  display: grid;
  gap: var(--p-space-2);
}

.profile-form label {
  display: grid;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--p-ink-secondary);
}

.profile-form input,
.profile-form select {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--p-border-strong);
  background: #ffffff;
  color: var(--p-ink);
  padding: 10px 14px;
  font-size: 0.9375rem;
  font-family: inherit;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.profile-form input:hover,
.profile-form select:hover {
  border-color: rgba(0, 0, 0, 0.2);
}

.profile-form input:focus,
.profile-form select:focus {
  outline: none;
  border-color: var(--p-accent);
  box-shadow: 0 0 0 4px var(--p-accent-soft);
}

.profile-inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* --- Buttons ------------------------------------------------------ */
.profile-primary-btn,
.profile-secondary-btn,
.profile-danger-btn {
  appearance: none;
  border-radius: 980px;
  border: none;
  min-height: 44px;
  padding: 10px 24px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  line-height: 1;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    background 0.2s ease,
    transform 0.15s ease,
    box-shadow 0.2s ease;
}

.profile-primary-btn:active,
.profile-secondary-btn:active,
.profile-danger-btn:active {
  transform: scale(0.97);
}

.profile-primary-btn {
  background: var(--p-accent);
  color: #ffffff;
}

.profile-primary-btn:hover {
  background: var(--p-accent-hover);
  box-shadow: 0 4px 14px rgba(0, 113, 227, 0.3);
}

.profile-secondary-btn {
  background: var(--p-bg-alt);
  color: var(--p-ink);
  border: 1px solid var(--p-border-strong);
}

.profile-secondary-btn:hover {
  background: #ffffff;
  box-shadow: var(--p-shadow-card);
}

.profile-danger-btn {
  background: var(--p-danger);
  color: #ffffff;
}

.profile-danger-btn:hover {
  background: var(--p-danger-hover);
  box-shadow: 0 4px 14px rgba(255, 59, 48, 0.3);
}

.profile-danger-btn:disabled,
.profile-primary-btn:disabled,
.profile-secondary-btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
  box-shadow: none;
}

/* --- Identity panel ----------------------------------------------- */
.identity-head {
  display: flex;
  align-items: center;
  gap: var(--p-space-2);
}

.identity-badge {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #ffffff;
  background: linear-gradient(145deg, #007aff, #5856d6);
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.8),
    0 4px 12px rgba(0, 122, 255, 0.3);
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.identity-badge:hover {
  transform: scale(1.08);
}

.identity-name {
  margin: 0;
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.identity-handle {
  margin: 2px 0 0;
  color: var(--p-ink-tertiary);
  font-size: 0.875rem;
}

/* --- Stat list ---------------------------------------------------- */
.profile-stat-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.profile-stat-list div {
  display: grid;
  gap: 2px;
  border-radius: 12px;
  border: 1px solid var(--p-border);
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.6);
  transition: background 0.2s ease;
}

.profile-stat-list div:hover {
  background: rgba(255, 255, 255, 0.9);
}

.profile-stat-list dt {
  margin: 0;
  font-size: 0.6875rem;
  color: var(--p-ink-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.profile-stat-list dd {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--p-ink);
}

/* --- Battle pass & overall figures -------------------------------- */
.battle-pass-figures,
.overall-metrics {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.battle-pass-figures>div,
.overall-metrics>div {
  border-radius: 16px;
  border: 1px solid var(--p-border);
  background: rgba(255, 255, 255, 0.6);
  padding: 14px 16px;
  transition: background 0.2s ease, transform 0.2s ease;
}

.battle-pass-figures>div:hover,
.overall-metrics>div:hover {
  background: rgba(255, 255, 255, 0.95);
  transform: translateY(-1px);
}

.figure-label {
  margin: 0;
  color: var(--p-ink-tertiary);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.figure-value {
  margin: 6px 0 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--p-ink);
}

/* --- Progress bar ------------------------------------------------- */
.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 980px;
  overflow: hidden;
  background: var(--p-bg-alt);
}

.progress-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg,
      var(--p-accent),
      #5ac8fa);
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- Score table -------------------------------------------------- */
.score-table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--p-border);
  background: rgba(255, 255, 255, 0.5);
}

.score-table {
  width: 100%;
  border-collapse: collapse;
}

.score-table th,
.score-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--p-border);
  font-size: 0.875rem;
}

.score-table tr:last-child td {
  border-bottom: none;
}

.score-table tr:hover td {
  background: rgba(0, 113, 227, 0.03);
}

.score-table th {
  font-size: 0.6875rem;
  color: var(--p-ink-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.02);
}

/* --- Delete confirm ----------------------------------------------- */
.delete-confirm-wrap {
  display: grid;
  gap: var(--p-space-1);
  margin-top: var(--p-space-2);
  border: 1px solid rgba(255, 59, 48, 0.2);
  border-radius: var(--p-radius-s);
  padding: var(--p-space-3);
  background: var(--p-danger-soft);
}

/* --- Captions & statuses ------------------------------------------ */
.profile-caption,
.profile-status {
  margin: 0;
  color: var(--p-ink-secondary);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.profile-status {
  min-height: 1.3em;
}

.tone-neutral {
  color: var(--p-ink-secondary);
}

.tone-success {
  color: #248a3d;
}

.tone-warning {
  color: #c93400;
}

.tone-error {
  color: #ff3b30;
}

/* --- Links -------------------------------------------------------- */
a {
  color: var(--p-accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--p-accent-hover);
  text-decoration: underline;
}

/* --- Focus rings -------------------------------------------------- */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--p-focus);
  outline-offset: 2px;
}

/* do not double-up with the custom input focus styles */
.profile-form input:focus-visible,
.profile-form select:focus-visible {
  outline: none;
  border-color: var(--p-accent);
  box-shadow: 0 0 0 4px var(--p-accent-soft);
}

/* --- Responsive: tablet ------------------------------------------- */
@media (max-width: 1080px) {

  .profile-auth-card,
  .profile-identity-card,
  .profile-battle-pass-card,
  .profile-overall-card,
  .profile-edit-card,
  .profile-recovery-card,
  .profile-scores-card,
  .profile-danger-card {
    grid-column: span 12;
  }
}

/* --- Responsive: mobile ------------------------------------------- */
@media (max-width: 760px) {

  .profile-header,
  .profile-main {
    width: min(980px, calc(100% - 24px));
  }

  .profile-header {
    position: static;
    margin-top: var(--p-space-2);
    justify-content: flex-start;
  }

  .profile-hero {
    padding: var(--p-space-4) var(--p-space-3);
  }

  .profile-card {
    padding: var(--p-space-3);
  }

  .battle-pass-figures,
  .overall-metrics {
    grid-template-columns: 1fr;
  }

  .profile-lock-note {
    position: static;
    margin-bottom: var(--p-space-1);
    width: fit-content;
  }

  .identity-badge {
    width: 48px;
    height: 48px;
    font-size: 0.8125rem;
  }
}

/* --- Reduced motion ----------------------------------------------- */
@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;
  }
}