/* ============ RESET & TOKENS ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0a0b14;
  --bg-2: #11131f;
  --card: rgba(255,255,255,0.04);
  --card-border: rgba(255,255,255,0.08);
  --text: #e8eaf2;
  --muted: #8b90a8;
  --accent: #6c5ce7;
  --accent-2: #00d2ff;
  --good: #2ecc71;
  --bad: #ff5470;
  --warn: #ffb443;
  --gold: #ffd24a;
  --lane-h: 56px;
}

html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  min-height: 100vh;
  position: relative;
}

/* ============ BACKGROUND FX ============ */
.bg-grid {
  position: fixed; inset: 0; z-index: 0;
  background-image:
    linear-gradient(rgba(108,92,231,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(108,92,231,0.06) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at 50% 0%, #000 30%, transparent 80%);
}
.bg-glow {
  position: fixed; top: -200px; left: 50%; transform: translateX(-50%);
  width: 900px; height: 600px; z-index: 0;
  background: radial-gradient(circle, rgba(108,92,231,0.35), transparent 60%);
  filter: blur(40px); pointer-events: none;
}

/* ============ LAYOUT ============ */
.app {
  position: relative; z-index: 1;
  max-width: 1080px; margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 40px) 60px;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 32px;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 22px; }
.logo-mark {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 20px; box-shadow: 0 6px 24px rgba(108,92,231,0.4);
}
.logo-text .accent { background: linear-gradient(135deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.best-badge { font-size: 13px; color: var(--muted); background: var(--card); border: 1px solid var(--card-border); padding: 8px 14px; border-radius: 999px; }
.best-badge strong { color: var(--gold); }
.icon-btn { background: var(--card); border: 1px solid var(--card-border); color: var(--text); width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 18px; transition: .2s; }
.icon-btn:hover { background: rgba(255,255,255,0.09); }

/* ============ SCREENS ============ */
.screen { display: none; animation: fade .4s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ============ MENU ============ */
.hero { text-align: center; margin-bottom: 40px; }
.hero-title { font-size: clamp(30px, 5vw, 52px); font-weight: 900; letter-spacing: -1.5px; line-height: 1.05; }
.grad { background: linear-gradient(135deg, var(--accent-2), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-sub { color: var(--muted); margin-top: 14px; font-size: 17px; max-width: 560px; margin-inline: auto; }

.setup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; margin-bottom: 32px; }
.setup-card { background: var(--card); border: 1px solid var(--card-border); border-radius: 18px; padding: 22px; }
.setup-card h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 14px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 12px; line-height: 1.5; }

.seg { display: flex; gap: 6px; background: rgba(0,0,0,0.25); padding: 5px; border-radius: 12px; flex-wrap: wrap; }
.seg-btn { flex: 1; min-width: 52px; background: transparent; border: none; color: var(--muted); padding: 10px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; font-family: inherit; transition: .18s; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 4px 16px rgba(108,92,231,0.35); }

.cta-btn {
  display: block; width: 100%; max-width: 360px; margin: 0 auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; padding: 18px; border-radius: 16px;
  font-size: 18px; font-weight: 800; cursor: pointer; font-family: inherit;
  box-shadow: 0 10px 30px rgba(108,92,231,0.4); transition: .2s;
}
.cta-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 40px rgba(108,92,231,0.55); }
.cta-btn:active { transform: translateY(0); }

/* ============ RACE: STATS ============ */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 22px; }
.stat { background: var(--card); border: 1px solid var(--card-border); border-radius: 16px; padding: 16px; text-align: center; }
.stat-val { display: block; font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.stat-val small { font-size: 15px; color: var(--muted); }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-top: 8px; display: block; }

/* ============ RACE: TRACK ============ */
.track {
  background: linear-gradient(180deg, #0d1020, #0a0c16);
  border: 1px solid var(--card-border); border-radius: 18px;
  padding: 14px 16px; margin-bottom: 22px; overflow: hidden;
}
.lane {
  position: relative; height: var(--lane-h);
  display: flex; align-items: center;
  border-bottom: 1px dashed rgba(255,255,255,0.06);
}
.lane:last-child { border-bottom: none; }
.lane-name { position: absolute; left: 6px; font-size: 12px; color: var(--muted); font-weight: 600; width: 120px; z-index: 2; pointer-events: none; }
.lane-name.you { color: var(--accent-2); }
.lane-track-line { position: absolute; left: 130px; right: 46px; height: 2px; background: repeating-linear-gradient(90deg, rgba(255,255,255,0.08) 0 14px, transparent 14px 28px); }
.finish-flag { position: absolute; right: 10px; font-size: 20px; z-index: 2; }
.racer {
  position: absolute; left: 130px; font-size: 26px; z-index: 3;
  transition: left .25s linear; will-change: left;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
}
.racer.you { font-size: 30px; }
.racer-prog { position: absolute; left: 130px; right: 46px; height: 100%; pointer-events: none; }

/* ============ RACE: TYPING ============ */
.type-area { position: relative; background: var(--card); border: 1px solid var(--card-border); border-radius: 18px; padding: 24px; }
.text-display {
  font-family: 'JetBrains Mono', monospace; font-size: 22px; line-height: 1.85;
  letter-spacing: .3px; user-select: none; min-height: 100px;
  filter: blur(4px); opacity: .5; transition: .4s; pointer-events: none;
}
.text-display.live { filter: none; opacity: 1; }
.text-display .char { position: relative; color: var(--muted); transition: color .05s; }
.text-display .char.correct { color: var(--text); }
.text-display .char.wrong { color: var(--bad); background: rgba(255,84,112,0.15); border-radius: 3px; }
.text-display .char.current { color: var(--text); }
.text-display .char.current::before {
  content: ''; position: absolute; left: -1px; top: 8%; width: 2px; height: 84%;
  background: var(--accent-2); border-radius: 2px; animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* mobilde klavyenin açılması için input ekran içinde (görünmez) tutulur */
.hidden-input { position: absolute; bottom: 0; left: 0; width: 1px; height: 1px; opacity: 0.01; border: none; padding: 0; color: transparent; background: transparent; pointer-events: none; }

.refocus-overlay {
  position: absolute; inset: 0; z-index: 5; display: none;
  place-items: center; background: rgba(10,11,20,0.55); backdrop-filter: blur(2px);
  border-radius: 18px; cursor: pointer;
}
.refocus-overlay.show { display: grid; }
.refocus-overlay span { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; padding: 12px 22px; border-radius: 12px; font-weight: 700; font-size: 15px; box-shadow: 0 8px 24px rgba(108,92,231,0.4); }

.type-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }
.type-hint { font-size: 13px; color: var(--muted); }
.ghost-btn { background: transparent; border: 1px solid var(--card-border); color: var(--muted); padding: 10px 18px; border-radius: 10px; cursor: pointer; font-weight: 600; font-family: inherit; transition: .2s; }
.ghost-btn:hover { color: var(--text); border-color: var(--bad); }

/* ============ COUNTDOWN ============ */
.countdown {
  position: fixed; inset: 0; z-index: 50; display: none;
  place-items: center; background: rgba(10,11,20,0.7); backdrop-filter: blur(6px);
}
.countdown.show { display: grid; }
.countdown span {
  font-size: 140px; font-weight: 900;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: pop .6s ease;
}
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 50% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }

/* ============ RESULT ============ */
.result-card { background: var(--card); border: 1px solid var(--card-border); border-radius: 24px; padding: 40px; max-width: 600px; margin: 0 auto; text-align: center; }
.result-badge { font-size: 72px; animation: pop .6s ease; }
#resultTitle { font-size: 36px; font-weight: 900; margin-top: 8px; }
.result-sub { color: var(--muted); margin-top: 8px; font-size: 16px; }
.result-stats { display: flex; justify-content: center; gap: 32px; margin: 28px 0; }
.rstat { display: flex; flex-direction: column; gap: 4px; }
.rstat span { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rstat small { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }

.leaderboard { text-align: left; margin: 24px 0; display: flex; flex-direction: column; gap: 8px; }
.lb-row { display: flex; align-items: center; gap: 12px; background: rgba(0,0,0,0.25); border: 1px solid var(--card-border); border-radius: 12px; padding: 12px 16px; }
.lb-row.you { border-color: var(--accent-2); background: rgba(0,210,255,0.06); }
.lb-rank { font-weight: 800; width: 28px; color: var(--muted); }
.lb-row:nth-child(1) .lb-rank { color: var(--gold); }
.lb-icon { font-size: 20px; }
.lb-name { flex: 1; font-weight: 600; }
.lb-wpm { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.lb-wpm strong { color: var(--text); }

.result-actions { display: flex; gap: 12px; margin-top: 28px; }
.result-actions .cta-btn { margin: 0; flex: 1; }
.result-actions .ghost-btn { flex: 1; }

/* ============ TOPBAR PROGRESSION ============ */
.lvl-badge { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--card-border); padding: 7px 12px; border-radius: 999px; }
.lvl-num { font-size: 13px; color: var(--muted); white-space: nowrap; }
.lvl-num strong { color: var(--accent-2); }
.xp-bar { width: 70px; height: 6px; background: rgba(0,0,0,0.4); border-radius: 999px; overflow: hidden; }
.xp-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width .5s ease; }
.coin-badge, .streak-badge { font-size: 13px; color: var(--muted); background: var(--card); border: 1px solid var(--card-border); padding: 8px 12px; border-radius: 999px; white-space: nowrap; }
.coin-badge strong { color: var(--gold); }
.streak-badge strong { color: var(--warn); }

/* ============ PROFILE CARD ============ */
.profile-card { display: flex; align-items: center; gap: 18px; background: var(--card); border: 1px solid var(--card-border); border-radius: 18px; padding: 18px 22px; margin-bottom: 24px; }
.profile-avatar { font-size: 44px; width: 68px; height: 68px; display: grid; place-items: center; border-radius: 50%; background: radial-gradient(circle at 50% 40%, rgba(108,92,231,0.35), rgba(0,0,0,0.2)); border: 2px solid var(--accent); flex-shrink: 0; }
.profile-info { flex: 1; min-width: 0; }
.profile-name-input { background: transparent; border: none; border-bottom: 1px dashed var(--card-border); color: var(--text); font-size: 20px; font-weight: 800; font-family: inherit; padding: 2px 0; width: 100%; max-width: 200px; outline: none; }
.profile-name-input:focus { border-bottom-color: var(--accent-2); }
.profile-meta { display: flex; gap: 16px; margin-top: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.profile-meta strong { color: var(--text); }

/* ============ AVATAR MODAL ============ */
.modal { position: fixed; inset: 0; z-index: 60; display: none; place-items: center; background: rgba(5,6,12,0.75); backdrop-filter: blur(8px); padding: 20px; }
.modal.show { display: grid; animation: fade .25s ease; }
.modal-box { background: var(--bg-2); border: 1px solid var(--card-border); border-radius: 22px; padding: 28px; width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 22px; font-weight: 800; }
.modal-sub { color: var(--muted); font-size: 14px; margin: 8px 0 18px; }
.avatar-preview-row { display: flex; gap: 18px; align-items: center; margin-bottom: 20px; }
.avatar-big { font-size: 48px; width: 84px; height: 84px; display: grid; place-items: center; border-radius: 50%; background: radial-gradient(circle at 50% 40%, rgba(108,92,231,0.35), rgba(0,0,0,0.2)); border: 2px solid var(--accent); flex-shrink: 0; }
.avatar-build label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.ring-row { display: flex; gap: 8px; margin-top: 8px; }
.ring-dot { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: .15s; }
.ring-dot.active { border-color: #fff; transform: scale(1.15); }
.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 10px; }
.avatar-cell { aspect-ratio: 1; display: grid; place-items: center; font-size: 28px; background: var(--card); border: 1px solid var(--card-border); border-radius: 14px; cursor: pointer; position: relative; transition: .15s; }
.avatar-cell:hover { background: rgba(255,255,255,0.08); transform: translateY(-2px); }
.avatar-cell.selected { border-color: var(--accent-2); box-shadow: 0 0 0 2px var(--accent-2); }
.avatar-cell.locked { opacity: .55; }
.avatar-cell .lock-cost { position: absolute; bottom: 3px; right: 4px; font-size: 10px; font-weight: 700; color: var(--gold); background: rgba(0,0,0,0.6); padding: 1px 5px; border-radius: 6px; }
.avatar-cell .lock-ico { position: absolute; top: 3px; left: 4px; font-size: 11px; }

/* ============ PROFILE BUTTONS ============ */
.profile-btns { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }

/* ============ ACHIEVEMENTS LIST ============ */
.ach-list { display: flex; flex-direction: column; gap: 10px; }
.ach-item { display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--card-border); border-radius: 14px; padding: 14px 16px; }
.ach-item.locked { opacity: .5; }
.ach-item .a-ico { font-size: 30px; filter: grayscale(0); }
.ach-item.locked .a-ico { filter: grayscale(1); }
.ach-item .a-title { font-weight: 700; font-size: 15px; }
.ach-item .a-desc { font-size: 13px; color: var(--muted); }
.ach-item .a-state { margin-left: auto; font-size: 20px; }

/* ============ ACHIEVEMENT TOAST ============ */
.toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast { display: flex; align-items: center; gap: 12px; background: var(--bg-2); border: 1px solid var(--accent); border-radius: 14px; padding: 14px 18px; box-shadow: 0 10px 40px rgba(0,0,0,0.5); animation: toastIn .4s ease, toastOut .4s ease 3.4s forwards; max-width: 320px; }
.toast .t-ico { font-size: 28px; }
.toast .t-title { font-weight: 800; font-size: 14px; }
.toast .t-sub { font-size: 12px; color: var(--muted); }
@keyframes toastIn { from { transform: translateX(120%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateX(120%); opacity: 0; } }

/* ============ XP/REWARD ON RESULT ============ */
.reward-row { display: flex; justify-content: center; gap: 24px; margin: 18px 0 4px; flex-wrap: wrap; }
.reward-chip { background: rgba(0,0,0,0.25); border: 1px solid var(--card-border); border-radius: 12px; padding: 10px 16px; font-weight: 700; font-size: 14px; }
.reward-chip.xp { color: var(--accent-2); }
.reward-chip.coin { color: var(--gold); }

/* ============ RESPONSIVE ============ */
@media (max-width: 560px) {
  .topbar-right { gap: 8px; }
  .streak-badge, .coin-badge { padding: 7px 9px; font-size: 12px; }
  .xp-bar { width: 48px; }
  .profile-card { flex-wrap: wrap; }
}
@media (max-width: 640px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .stat-val { font-size: 24px; }
  .text-display { font-size: 18px; }
  .lane-name { width: 80px; font-size: 10px; }
  .racer { left: 88px; }
  .lane-track-line, .racer-prog { left: 88px; }
  .result-stats { gap: 18px; }
}
