:root {
  --bg: #041018;
  --bg2: #0a1f2e;
  --card: rgba(14, 40, 58, 0.85);
  --card-border: rgba(14, 165, 233, 0.25);
  --accent: #0ea5e9;
  --accent2: #06b6d4;
  --gold: #fbbf24;
  --text: #e2f4ff;
  --muted: #7dd3fc88;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 16px;
  --nav-h: 64px;
  --top-h: 52px;
  --font: 'Inter', system-ui, sans-serif;
  --font-display: 'Russo One', sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.ocean-bg {
  position: fixed; inset: 0; z-index: 0;
  background: linear-gradient(160deg, #020810 0%, #041018 30%, #0c2a3d 70%, #041018 100%);
}

.bubbles {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
.bubbles::before, .bubbles::after {
  content: ''; position: absolute; border-radius: 50%;
  background: radial-gradient(circle, rgba(14,165,233,0.15) 0%, transparent 70%);
  animation: float 8s ease-in-out infinite;
}
.bubbles::before { width: 300px; height: 300px; bottom: -50px; left: -80px; animation-delay: 0s; }
.bubbles::after { width: 200px; height: 200px; top: 20%; right: -60px; animation-delay: 3s; }

@keyframes float {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.6; }
  50% { transform: translateY(-30px) scale(1.1); opacity: 1; }
}

.screen {
  display: none; position: fixed; inset: 0; z-index: 1;
  flex-direction: column;
}
.screen.active { display: flex; }

/* AUTH */
#screen-auth { align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: 24px; padding: 32px 28px;
  backdrop-filter: blur(20px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 40px rgba(14,165,233,0.1);
}
.logo-block { text-align: center; margin-bottom: 28px; }
.logo-shark { font-size: 56px; animation: swim 3s ease-in-out infinite; display: inline-block; }
@keyframes swim { 0%,100%{transform:translateX(0) rotate(0)} 50%{transform:translateX(8px) rotate(5deg)} }
.logo-title { font-family: var(--font-display); font-size: 36px; color: var(--accent); letter-spacing: 2px; margin-top: 8px; }
.logo-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  background: rgba(0,0,0,0.3); border: 1px solid var(--card-border);
  border-radius: 12px; padding: 14px 16px; color: var(--text); font-size: 16px;
  outline: none; transition: border-color 0.2s;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-error { color: var(--red); font-size: 13px; text-align: center; }
.auth-hint { color: var(--muted); font-size: 11px; text-align: center; margin-top: 16px; }

/* TOP BAR */
.top-bar {
  height: var(--top-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: rgba(4,16,24,0.9); border-bottom: 1px solid var(--card-border);
  backdrop-filter: blur(12px); flex-shrink: 0; z-index: 10;
}
.brand-mini { font-family: var(--font-display); color: var(--accent); font-size: 16px; }
.user-badge { font-size: 12px; color: var(--muted); margin-right: 8px; }

.main-content {
  flex: 1; overflow-y: auto; padding: 16px;
  padding-bottom: calc(var(--nav-h) + 16px);
  -webkit-overflow-scrolling: touch;
}

/* BUTTONS */
.btn {
  border: none; border-radius: 12px; padding: 12px 20px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.btn-secondary { background: rgba(14,165,233,0.15); color: var(--accent); border: 1px solid var(--card-border); }
.btn-danger { background: rgba(239,68,68,0.2); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 12px; }
.btn-icon { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 8px; }

/* CARDS */
.card {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
  backdrop-filter: blur(12px);
}
.card-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }

/* ATHLETE CARD */
.team-member { margin-bottom: 20px; }
.team-card-row { display: flex; gap: 14px; align-items: center; }
.athlete-card {
  display: block;
  transition: transform 0.15s, box-shadow 0.15s;
  margin-bottom: 10px;
}
.team-profile-sheet { margin-top: 4px; }
.team-profile-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.team-profile-meta { font-size: 11px; color: var(--muted); }
.team-more-results { font-size: 11px; color: var(--muted); align-self: center; }
.team-profile-section {
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 12px;
  margin: 10px 0;
}
.team-profile-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.team-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.team-result-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(14,165,233,0.08);
  border: 1px solid rgba(14,165,233,0.15);
  font-size: 11px;
}
.team-result-chip strong { font-size: 14px; color: var(--gold); }
.team-profile-empty { font-size: 12px; color: var(--muted); margin: 0; }
.team-credentials {
  margin: 10px 0;
  padding: 12px;
  border-radius: 14px;
  background: rgba(168,85,247,0.1);
  border: 1px solid rgba(168,85,247,0.35);
}
.team-credentials-title { font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.cred-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  margin-bottom: 6px;
}
.cred-row span { color: var(--muted); }
.cred-val {
  font-family: ui-monospace, monospace;
  font-size: 13px;
  font-weight: 700;
  color: #fde68a;
  background: rgba(0,0,0,0.35);
  padding: 4px 8px;
  border-radius: 8px;
}
.team-member-clickable {
  cursor: pointer;
  border-radius: var(--radius);
  transition: transform 0.12s, box-shadow 0.12s;
}
.team-member-clickable:hover .athlete-card {
  box-shadow: 0 0 0 1px rgba(14, 165, 233, 0.35);
}
.team-member-clickable:active { transform: scale(0.995); }
.team-member-clickable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.profile-viewer-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: rgba(14, 165, 233, 0.08);
  border: 1px solid rgba(14, 165, 233, 0.25);
  border-radius: 14px;
}
.profile-viewer-label { font-size: 13px; color: var(--muted); }
.profile-viewer-label strong { color: var(--text); }
.team-result-date {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}
.best-mini-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.best-mini-date {
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
}
.team-open-full { margin-top: 10px; }
.athlete-card:active { transform: scale(0.98); }
.athlete-card:hover { box-shadow: 0 4px 20px rgba(14,165,233,0.15); }
.team-card-visual {
  display: flex; flex-direction: column; align-items: center; gap: 4px; flex-shrink: 0;
}
.team-mini-char { line-height: 0; transform: scale(0.85); margin-top: -4px; }
.team-mini-char .swimmer-team .swimmer-stand-svg { width: 56px; height: auto; }
.team-mini-char .coach-team .coach-stand-svg { width: 52px; height: auto; }
.team-mini-char .swimmer-hero-glow,
.team-mini-char .coach-hero-glow { display: none; }
.athlete-info { flex: 1; min-width: 0; }
.athlete-name { font-weight: 700; font-size: 16px; }
.athlete-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.level-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(251,191,36,0.15); color: var(--gold);
  border-radius: 20px; padding: 2px 10px; font-size: 11px; font-weight: 700;
}

/* XP BAR */
.xp-bar-wrap { margin-top: 8px; }
.xp-bar-label { font-size: 10px; color: var(--muted); display: flex; justify-content: space-between; margin-bottom: 4px; }
.xp-bar { height: 6px; background: rgba(0,0,0,0.3); border-radius: 3px; overflow: hidden; }
.xp-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); border-radius: 3px; transition: width 0.5s; }

/* STROKE BUTTONS */
.stroke-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px;
}
.stroke-btn {
  background: rgba(14,165,233,0.1); border: 1px solid var(--card-border);
  border-radius: 14px; padding: 14px 8px; text-align: center; cursor: pointer;
  color: var(--text); transition: all 0.2s;
}
.stroke-btn.active, .stroke-btn:hover {
  background: rgba(14,165,233,0.25); border-color: var(--accent);
  box-shadow: 0 0 16px rgba(14,165,233,0.2);
}
.stroke-btn .stroke-icon { font-size: 24px; display: block; margin-bottom: 4px; }
.stroke-btn .stroke-label { font-size: 11px; font-weight: 600; }

/* RESULT ROWS */
.result-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.result-row:last-child { border-bottom: none; }
.result-dist { font-size: 13px; color: var(--muted); width: 60px; }
.result-time { font-weight: 700; font-size: 15px; flex: 1; }
.result-strokes { font-size: 12px; color: var(--muted); width: 80px; text-align: right; }

.delta-up { color: var(--green); font-size: 12px; font-weight: 600; }
.delta-down { color: var(--red); font-size: 12px; font-weight: 600; }
.delta-same { color: var(--muted); font-size: 12px; }

/* EVENT TABS */
.event-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.event-tab {
  flex: 1; padding: 12px; text-align: center; border-radius: 12px;
  background: rgba(14,165,233,0.08); border: 1px solid var(--card-border);
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted);
  transition: all 0.2s;
}
.event-tab.active { background: rgba(14,165,233,0.25); color: var(--accent); border-color: var(--accent); }

/* CHAT */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - var(--top-h) - var(--nav-h) - 32px); }
.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.chat-msg {
  display: flex; gap: 10px; align-items: flex-start;
  animation: msgIn 0.3s ease;
}
@keyframes msgIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }
.chat-msg.own { flex-direction: row-reverse; }
.chat-msg-body {
  background: rgba(14,165,233,0.12); border-radius: 14px; padding: 10px 14px;
  max-width: 75%; font-size: 14px;
}
.chat-msg.own .chat-msg-body { background: rgba(14,165,233,0.25); }
.chat-msg-name { font-size: 11px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.chat-msg-time { font-size: 10px; color: var(--muted); margin-top: 4px; }
.chat-input-row {
  display: flex; gap: 8px; padding-top: 12px;
  border-top: 1px solid var(--card-border);
}
.chat-input-row input {
  flex: 1; background: rgba(0,0,0,0.3); border: 1px solid var(--card-border);
  border-radius: 12px; padding: 12px 14px; color: var(--text); font-size: 14px; outline: none;
}

/* PROFILE CARD CONSTRUCTOR */
.profile-header {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 20px 0;
}
.profile-name { font-family: var(--font-display); font-size: 22px; margin-top: 12px; }
.profile-level { margin-top: 6px; }
.avatar-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 16px 0; }
.avatar-option {
  aspect-ratio: 1; border-radius: 14px; border: 2px solid transparent;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.2); transition: all 0.2s; overflow: hidden;
}
.avatar-option.selected { border-color: var(--accent); box-shadow: 0 0 12px rgba(14,165,233,0.4); }
.avatar-option .avatar-preview { transform: scale(0.6); }

.card-preview {
  border-radius: 20px; padding: 20px; margin: 16px 0;
  background: linear-gradient(135deg, rgba(14,165,233,0.15), rgba(6,182,212,0.08));
  border: 1px solid var(--card-border); text-align: center;
}
.card-preview.theme-fire { background: linear-gradient(135deg, rgba(239,68,68,0.2), rgba(251,191,36,0.1)); }
.card-preview.theme-ice { background: linear-gradient(135deg, rgba(147,197,253,0.2), rgba(14,165,233,0.1)); }
.card-preview.theme-gold { background: linear-gradient(135deg, rgba(251,191,36,0.2), rgba(245,158,11,0.1)); }
.card-preview.theme-dark { background: linear-gradient(135deg, rgba(30,30,30,0.8), rgba(60,60,60,0.3)); }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; background: rgba(0,0,0,0.3); border: 1px solid var(--card-border);
  border-radius: 10px; padding: 10px 12px; color: var(--text); font-size: 14px; outline: none;
}
.form-group textarea { resize: vertical; min-height: 60px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.target-speeds-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.section-title {
  font-family: var(--font-display); font-size: 18px; color: var(--accent);
  margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}

.hidden { display: none !important; }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-overlay:not(.hidden) { display: flex; }
.modal {
  width: 100%; max-width: 480px; max-height: 85vh;
  background: var(--bg2); border: 1px solid var(--card-border);
  border-radius: 20px 20px 0 0; overflow: hidden;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--card-border);
}
.modal-header h3 { font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; max-height: calc(85vh - 60px); }

/* TOAST */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; transform: translateX(-50%);
  background: rgba(14,165,233,0.9); color: #fff; padding: 10px 20px;
  border-radius: 20px; font-size: 13px; font-weight: 600; z-index: 200;
  animation: toastIn 0.3s ease;
}
@keyframes toastIn { from { opacity:0; transform: translateX(-50%) translateY(20px); } }
.toast.hidden { display: none; }

.coach-only { border-left: 3px solid var(--gold); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }

.best-highlight {
  background: linear-gradient(135deg, rgba(34,197,94,0.15), rgba(14,165,233,0.1));
  border: 1px solid rgba(34,197,94,0.3); border-radius: 14px;
  padding: 16px; text-align: center; margin-bottom: 16px;
}
.best-highlight .best-time { font-family: var(--font-display); font-size: 32px; color: var(--green); }
.best-highlight .best-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

.strokes-info {
  display: flex; justify-content: center; gap: 24px; margin-top: 8px;
  font-size: 13px; color: var(--muted);
}
.strokes-info strong { color: var(--text); }

.add-result-form .form-row { margin-bottom: 10px; }
