/* ── Profile page layout ─────────────────────────────────── */
.profile-page {
  width: 100%;
  min-height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 24px 60px;
}

.profile-container {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 36px;
  animation: modalRise 340ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* ── Back link ───────────────────────────────────────────── */
.profile-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 8px 8px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: color 140ms ease, background 140ms ease;
  align-self: flex-start;
}

.profile-back svg {
  width: 16px;
  height: 16px;
  transition: transform 140ms ease;
}

.profile-back:hover {
  color: var(--accent);
  background: rgba(124, 129, 255, 0.08);
}

.profile-back:hover svg {
  transform: translateX(-2px);
}

/* ── Profile header card ─────────────────────────────────── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 32px 36px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 20px 50px -16px rgba(0, 0, 0, 0.45);
}

/* Avatar circle — clickable */
.profile-avatar-wrap {
  position: relative;
  cursor: pointer;
  flex: 0 0 auto;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 2px solid var(--line-strong);
  display: grid;
  place-items: center;
  font-size: 40px;
  line-height: 1;
  transition: border-color 200ms ease, transform 200ms ease;
  user-select: none;
}

.profile-avatar-wrap:hover .profile-avatar {
  border-color: var(--accent);
  transform: scale(1.05);
}

.profile-avatar-edit-hint {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #0e0e13;
  display: grid;
  place-items: center;
  font-size: 12px;
  border: 2px solid var(--surface);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 200ms ease, transform 200ms ease;
}

.profile-avatar-wrap:hover .profile-avatar-edit-hint {
  opacity: 1;
  transform: scale(1);
}

/* Avatar picker popover */
.avatar-picker {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  z-index: 50;
  box-shadow: 0 12px 40px -10px rgba(0, 0, 0, 0.6);
  animation: modalRise 200ms ease;
}

.avatar-picker[hidden] { display: none; }

.avatar-option {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: 22px;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.avatar-option:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.1);
}

.avatar-option.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Profile info */
.profile-info {
  flex: 1;
  min-width: 0;
}

.profile-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.profile-name {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.2;
}

.profile-name-edit {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  transition: color 140ms ease, background 140ms ease;
}

.profile-name-edit:hover {
  color: var(--accent);
  background: rgba(124, 129, 255, 0.08);
}

.profile-name-edit svg {
  width: 16px;
  height: 16px;
}

/* Inline edit mode */
.profile-name-input {
  appearance: none;
  border: 1.5px solid var(--accent);
  background: var(--surface-2);
  color: var(--ink);
  font-family: var(--font);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  outline: none;
  width: 100%;
  max-width: 300px;
  box-shadow: 0 0 0 3px rgba(124, 129, 255, 0.18);
}

.profile-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  font-size: 13px;
  color: var(--muted);
}

.profile-meta span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.profile-meta svg {
  width: 13px;
  height: 13px;
  opacity: 0.7;
}

/* ── Stats grid ──────────────────────────────────────────── */
.profile-section-title {
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-section-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.profile-group-title {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-top: 18px;
  margin-bottom: 10px;
  opacity: 0.85;
}

.profile-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.profile-stat-card {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 140ms ease, border-color 140ms ease;
}

.profile-stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.18);
}

.profile-stat-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  font-weight: 600;
}

.profile-stat-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
  display: flex;
  align-items: baseline;
}

.profile-stat-sub-val {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
  letter-spacing: 0;
}

.profile-stat-card.accent-card {
  border-color: rgba(124, 129, 255, 0.3);
  background: radial-gradient(circle at top right, rgba(124, 129, 255, 0.08), var(--surface));
}

.profile-stat-card.accent-card .profile-stat-value {
  color: var(--accent);
}

/* ── Game history ────────────────────────────────────────── */
.profile-history-section {
  display: flex;
  flex-direction: column;
}

.profile-history-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
  font-size: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.profile-history-empty-icon {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.profile-history-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.history-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 20px;
  align-items: center;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  transition: background 140ms ease, border-color 140ms ease;
  cursor: pointer;
}

.history-row:hover {
  background: var(--surface-2);
}

.history-stats {
  display: flex;
  gap: 16px;
  align-items: center;
}

.history-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 68px;
}

.history-stat-val {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.history-stat-lbl {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-top: 1px;
}

.history-date {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}

/* Base card states: won (green glow) and lost/incomplete (red glow) */
.history-row.won-game {
  background: radial-gradient(circle at left, rgba(52, 211, 153, 0.05), var(--surface));
  border-left: 3px solid rgba(52, 211, 153, 0.4);
}
.history-row.won-game:hover {
  background: radial-gradient(circle at left, rgba(52, 211, 153, 0.1), var(--surface-2));
  border-left-color: var(--match);
}

.history-row.lost-game {
  background: radial-gradient(circle at left, rgba(248, 113, 113, 0.05), var(--surface));
  border-left: 3px solid rgba(248, 113, 113, 0.4);
}
.history-row.lost-game:hover {
  background: radial-gradient(circle at left, rgba(248, 113, 113, 0.1), var(--surface-2));
  border-left-color: var(--miss);
}

/* Best game highlight (outcome border color remains, but slightly offset padding) */
.history-row.best-game {
  padding-left: 17px;
}

.history-game-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 18px;
  flex: 0 0 auto;
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.history-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(124, 129, 255, 0.3);
}

.history-sub {
  font-size: 12px;
  color: var(--muted);
}



/* ── Tabs for history filter ─────────────────────────────── */
.profile-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.history-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.history-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 3px;
  cursor: pointer;
  transition: color 140ms ease, background 140ms ease;
}

.history-tab:hover {
  color: var(--ink-soft);
}

.history-tab.active {
  background: var(--accent);
  color: #0e0e13;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .profile-page {
    padding: 20px 14px 40px;
  }

  .profile-container {
    gap: 24px;
  }

  .profile-header {
    flex-direction: row;
    text-align: left;
    padding: 16px 20px;
    gap: 16px;
    align-items: center;
  }

  .profile-avatar {
    width: 60px;
    height: 60px;
    font-size: 30px;
  }

  .profile-avatar-edit-hint {
    width: 20px;
    height: 20px;
    font-size: 10px;
    bottom: -1px;
    right: -1px;
  }

  .profile-name-row {
    justify-content: flex-start;
    gap: 8px;
    margin-bottom: 4px;
  }

  .profile-name {
    font-size: 20px;
  }

  .profile-name-input {
    font-size: 20px;
    text-align: left;
    max-width: 180px;
    padding: 2px 8px;
  }

  .profile-meta {
    justify-content: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .profile-stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .profile-stat-card {
    padding: 16px;
  }

  .profile-stat-value {
    font-size: 22px;
  }

  .history-row {
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    padding: 12px 14px;
  }

  .history-date {
    grid-column: 2 / -1;
    grid-row: 2;
    text-align: left;
    font-size: 11px;
  }

  .history-stats {
    gap: 10px;
  }

  .history-stat {
    min-width: 0;
  }

  .history-stat.mobile-hide {
    display: none;
  }

  .avatar-picker {
    grid-template-columns: repeat(6, 1fr);
    left: 0;
    transform: none;
  }
}

/* ── Swipeable Tabs layout ───────────────────────────────── */
.profile-tabs-nav {
  display: flex;
  justify-content: center;
  gap: 12px;
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 16px;
  margin-bottom: 8px;
}

.profile-nav-btn {
  appearance: none;
  background: transparent;
  border: none;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 24px;
  border-radius: var(--radius-sm);
  transition: color 160ms ease, background 160ms ease;
}

.profile-nav-btn:hover {
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.04);
}

.profile-nav-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(124, 129, 255, 0.2);
  padding-top: 7px;
  padding-bottom: 7px;
}

.profile-tab-viewport {
  width: 100%;
  overflow: hidden;
  position: relative;
}

.profile-tab-slides {
  display: flex;
  width: 200%;
  transition: transform 380ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
  cursor: grab;
}

.profile-tab-slides:active {
  cursor: grabbing;
}

.profile-tab-pane {
  width: 50%;
  flex: 0 0 50%;
  box-sizing: border-box;
  padding: 4px 8px;
  overflow: hidden;
}

/* Ensure form/input selection is still possible */
.profile-tab-pane input,
.profile-tab-pane select,
.profile-tab-pane button,
.profile-tab-pane a {
  user-select: text;
}

/* Quick Size Filters (Pills) */
.history-sub-tabs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  margin-bottom: 14px;
  padding: 8px 0;
  border-top: 1px dashed var(--line);
}

.history-sub-tabs-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.history-row-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-right: 4px;
  user-select: none;
}

.history-sub-tab {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  padding: 5px 12px;
  border-radius: 100px;
  transition: color 140ms ease, border-color 140ms ease, background-color 140ms ease;
}

.history-sub-tab:hover {
  border-color: var(--line-strong);
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.04);
}

.history-sub-tab.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}
