/* Your profile (/me) */
body.me-page {
  min-height: 100vh;
  background: var(--bg);
  overflow-y: auto;
}

.me {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: max(16px, calc(env(safe-area-inset-top) + 12px)) 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.me-top {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.me-top h1 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 800;
}

.me-back {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}

.me-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.me-card[hidden],
#signed-in[hidden] {
  display: none;
}

#signed-in {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.me-card h2,
.me-card h3 {
  margin: 0;
}

.me-card h3 {
  font-size: 1.15rem;
}

.me-sub {
  margin: 8px 0 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.me-muted {
  margin: 0;
  color: var(--muted);
}

.me-small {
  font-size: 0.85rem;
}

.me-loading {
  color: var(--muted);
  text-align: center;
}

.me-signed-out,
.me-deleted {
  align-items: center;
  text-align: center;
}

.me-big-emoji {
  margin: 0;
  font-size: 3.4rem;
}

/* You, at the top */
.me-hero {
  flex-direction: row;
  align-items: center;
  gap: 16px;
}

.me-avatar {
  --c: #38bdf8;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  font-size: 2.8rem;
  background: color-mix(in srgb, var(--c) 30%, var(--surface-2));
  box-shadow: 0 0 0 4px var(--c);
}

.me-hero-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.me-hero-text h2 {
  font-size: 1.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.me-level {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.me-level-badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.6em;
  height: 1.6em;
  padding: 0 0.35em;
  border-radius: 999px;
  background: linear-gradient(135deg, #a855f7, #7c3aed);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 800;
}

.me-xp-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.me-xp-bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #a855f7, #f0abfc);
  transition: width 0.6s ease-out;
}

/* Name, emoji, colour */
.me-label {
  margin: 4px 0 0;
  font-weight: 700;
  font-size: 0.9rem;
}

.me input[type='text'] {
  width: 100%;
  box-sizing: border-box;
  padding: 0.8rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-primary);
  font: 600 1.05rem var(--font-sans);
}

.me-emojis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.8rem, 1fr));
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
  padding: 2px;
  overscroll-behavior: contain;
}

.me-emoji {
  aspect-ratio: 1;
  padding: 0;
  font-size: 1.55rem;
  line-height: 1;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 12px;
}

.me-emoji[aria-checked='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.me-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.me-color {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  background: var(--c);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}

.me-color[aria-checked='true'] {
  border-color: var(--text-primary);
  transform: scale(1.12);
}

.me-saved {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.9rem;
}

.me-saved.good { color: var(--success); }
.me-saved.bad { color: var(--danger); }

/* Stats */
.me-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.me-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  border-radius: 14px;
  background: var(--surface-2);
}

.me-tile b {
  font-size: 1.45rem;
  font-variant-numeric: tabular-nums;
}

.me-tile span {
  font-size: 0.75rem;
  color: var(--muted);
}

.me-games,
.me-parties {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.me-games li,
.me-parties li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--surface-2);
}

.me-game-icon {
  flex-shrink: 0;
  width: 1.6em;
  font-size: 1.4rem;
  text-align: center;
}

/* Every row is two lines (title, stats) that never wrap, so all rows are the same height. */
.me-games li,
.me-parties li {
  min-height: 3.1rem;
  box-sizing: border-box;
}

.me-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.me-row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}

.me-game-name,
.me-party-when {
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
}

.me-row-title em {
  flex-shrink: 0;
  padding: 1px 7px;
  border-radius: 999px;
  background: #facc15;
  color: #1c1305;
  font-style: normal;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.me-party-games {
  overflow: hidden;
  letter-spacing: 2px;
}

.me-row-stats {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  color: var(--muted);
}

.me-empty {
  padding: 8px 0;
}

/* The account */
.me-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.me-danger-link {
  align-self: flex-start;
  padding: 0.4rem 0;
  border: none;
  background: none;
  color: var(--danger);
  font-weight: 700;
}

.me-danger {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--danger) 60%, transparent);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.me-danger[hidden] {
  display: none;
}

.me-danger p {
  margin: 0;
}

.me-danger-button {
  background: #dc2626;
  color: #fff;
}

.me-danger-button:disabled {
  opacity: 0.45;
}

.me-error {
  margin: 0;
  min-height: 1.2em;
  color: var(--danger);
  font-size: 0.9rem;
}

.me-button-link {
  padding: 0.8rem 1.4rem;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 800;
  text-decoration: none;
}

.me-footer {
  text-align: center;
  font-size: 0.85rem;
}

.me-footer a {
  color: var(--muted);
}

@media (max-width: 380px) {
  .me-tiles {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mail switches */
.me-switch {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  cursor: pointer;
}

.me-switch input {
  flex-shrink: 0;
  appearance: none;
  -webkit-appearance: none;
  width: 46px;
  height: 28px;
  margin: 2px 0 0;
  border-radius: 999px;
  background: var(--surface-2, #1f2633);
  border: 1px solid var(--border-strong, #334155);
  position: relative;
  cursor: pointer;
  transition: background 0.15s ease;
}

.me-switch input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #cbd5e1;
  transition: transform 0.15s ease;
}

.me-switch input:checked {
  background: #7c3aed;
  border-color: #7c3aed;
}

.me-switch input:checked::after {
  transform: translateX(18px);
  background: #fff;
}

.me-switch input:focus-visible {
  outline: 2px solid var(--accent, #38bdf8);
  outline-offset: 2px;
}

.me-switch-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.me-switch-text small {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* Your emoji and colour: two buttons, the choices in a sheet (as on the join page) */
.me-looks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.me-look {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-primary);
  font: inherit;
  text-align: left;
}

.me-look-emoji {
  font-size: 2rem;
  line-height: 1;
}

.me-look-color {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22);
}

.me-look-color.random {
  background: conic-gradient(#ef4444, #facc15, #22c55e, #38bdf8, #a855f7, #ef4444);
}

.me-look-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}

.me-look-text b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.me-look-text b::first-letter {
  text-transform: uppercase;
}

.me-look-text small {
  color: var(--muted);
  font-size: 0.78rem;
}

.me-sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(3, 6, 12, 0.6);
}

.me-sheet[hidden],
.me-sheet [hidden] {
  display: none;
}

.me-sheet-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(100%, 560px);
  max-height: 85dvh;
  box-sizing: border-box;
  padding: 18px 16px max(16px, env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
}

.me-sheet-panel h3 {
  margin: 0;
}

.me-sheet .me-colors {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  justify-items: center;
}

/* Ranks (app/levels.py): the ladder, and the hero card dressed in your rank's colours */
.me-ranks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.me-rank {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 3.1rem;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid transparent;
}

.me-rank.locked {
  opacity: 0.5;
}

.me-rank.current {
  border-color: var(--rank, #a855f7);
  background: color-mix(in srgb, var(--rank, #a855f7) 14%, var(--surface-2));
}

.me-rank-emoji {
  flex-shrink: 0;
  width: 1.6em;
  font-size: 1.4rem;
  text-align: center;
}

.me-rank-check {
  color: var(--success);
  font-weight: 800;
}

.tier-1 { --rank: #94a3b8; }
.tier-2 { --rank: #38bdf8; }
.tier-3 { --rank: #e2e8f0; }
.tier-4 { --rank: #facc15; }
.tier-5 { --rank: #fb923c; }
.tier-6 { --rank: #f0abfc; }

.me-hero[class*='tier-'] .me-avatar {
  box-shadow: 0 0 0 4px var(--c), 0 0 0 7px var(--rank), 0 0 24px -2px var(--rank);
}

.me-hero[class*='tier-'] .me-level-badge {
  background: linear-gradient(135deg, color-mix(in srgb, var(--rank) 85%, #fff), color-mix(in srgb, var(--rank) 55%, #000));
}

.me-hero.tier-6 {
  border-color: transparent;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    linear-gradient(90deg, #ef4444, #facc15, #22c55e, #38bdf8, #a855f7) border-box;
}

/* Where you stand, and the Top 10 */
.me-standing {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: linear-gradient(90deg, color-mix(in srgb, #facc15 22%, var(--surface-2)), var(--surface-2));
  font-size: 1.05rem;
}

.me-standing b {
  font-size: 1.3rem;
  font-weight: 900;
  color: #fde68a;
}

.me-standing span {
  color: var(--muted);
}

.me-leaders {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.me-leader {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 3.1rem;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--surface-2);
  border-left: 4px solid var(--c);
}

.me-leader.is-me {
  background: color-mix(in srgb, var(--c) 16%, var(--surface-2));
}

.me-leader-place {
  flex-shrink: 0;
  width: 1.6em;
  font-size: 1.3rem;
  text-align: center;
}

.me-place {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--muted);
}

.me-leader-emoji {
  flex-shrink: 0;
  font-size: 1.4rem;
}

.me-leader-xp {
  flex-shrink: 0;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
