/* ============================================================
   ARXAIM — Precision Aim Trainer
   ============================================================ */

/* Self-hosted fonts — Orbitron (display/HUD) shared here, Inter reused from the
   main site. No Google Fonts request, matching arxangel.gg's zero-third-party rule. */
@font-face { font-family: 'Orbitron'; font-style: normal; font-weight: 500 900; font-display: swap; src: url('../fonts/orbitron.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: swap; src: url('../fonts/inter.woff2') format('woff2'); }

:root {
  --bg: #07060a;
  --panel: rgba(250, 239, 197, 0.045);
  --panel-hover: rgba(250, 239, 197, 0.08);
  --line: rgba(229, 189, 109, 0.16);
  --txt: #f7ecc8;
  --dim: #a99a74;
  /* var names kept from the original; values are now ARXANGEL gold. */
  --purple: #f5c400;   /* brand gold (primary accent) */
  --cyan: #ffdf82;     /* brand light-gold (gradient partner) */
  --font-display: 'Orbitron', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: var(--font-body);
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(1000px 600px at 15% -10%, rgba(245, 196, 0, 0.12), transparent 60%),
    radial-gradient(900px 600px at 90% 110%, rgba(255, 234, 166, 0.10), transparent 60%);
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  z-index: 0;
}

kbd {
  font-family: var(--font-body);
  font-size: 0.85em;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
}

/* ============ screens ============ */

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

/* ============ menu ============ */

#menu { overflow-y: auto; }

.menu-inner {
  max-width: 1060px;
  margin: 0 auto;
  padding: 48px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: 100%;
}

.brand { text-align: center; }

.brand h1 {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(42px, 7vw, 72px);
  letter-spacing: 0.12em;
  background: linear-gradient(100deg, var(--purple) 10%, var(--cyan) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 24px rgba(245, 196, 0, 0.35));
}

.brand h1 span { -webkit-text-stroke: 1px rgba(255, 255, 255, 0.25); }

.brand .sub {
  margin-top: 6px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.55em;
  text-indent: 0.55em;
  color: var(--dim);
}

/* ---- mode cards ---- */

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.mode-card {
  position: relative;
  text-align: left;
  font-family: var(--font-body);
  color: var(--txt);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 16px 14px;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.mode-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent, var(--purple));
  opacity: 0.9;
}

.mode-card:hover {
  transform: translateY(-3px);
  background: var(--panel-hover);
  border-color: var(--accent, var(--purple));
  box-shadow: 0 8px 32px -8px var(--accent-glow, rgba(245, 196, 0, 0.45));
}

.mode-card .mc-key {
  position: absolute;
  top: 12px; right: 12px;
  font-size: 12px;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 6px;
}

.mode-card .mc-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.08em;
  color: var(--accent, var(--purple));
}

.mode-card .mc-desc {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.35;
  color: var(--dim);
  min-height: 38px;
}

.mode-card .mc-pb {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--txt);
  opacity: 0.85;
}

.mode-card .mc-pb b { color: var(--accent, var(--purple)); font-weight: 700; }

/* ---- panels ---- */

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
}

.panel h3 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--dim);
  margin-bottom: 14px;
}

.setting-row {
  display: flex;
  flex-wrap: wrap;          /* segs drop below the label instead of clipping */
  align-items: center;
  gap: 8px 12px;
  padding: 7px 0;
}

.setting-row label {
  width: 92px;
  flex: none;
  font-size: 15px;
  font-weight: 600;
  color: var(--txt);
}

.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.seg button {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--dim);
  background: transparent;
  border: none;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--txt); }

.seg button.on {
  color: #1c1206;
  background: linear-gradient(100deg, var(--purple), var(--cyan));
  font-weight: 700;
}

input[type='color'] {
  width: 34px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

input[type='range'] {
  flex: 1;
  accent-color: var(--purple);
  cursor: pointer;
}

.vol-val {
  width: 44px;
  text-align: right;
  font-size: 14px;
  color: var(--dim);
}

/* ---- history ---- */

#historyList { list-style: none; max-height: 210px; overflow-y: auto; }

#historyList li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 14px;
}

#historyList li:last-child { border-bottom: none; }
#historyList li.empty { color: var(--dim); border: none; }

#historyList .h-mode { font-weight: 700; letter-spacing: 0.04em; width: 92px; flex: none; }
#historyList .h-score { font-weight: 700; width: 64px; flex: none; text-align: right; }
#historyList .h-extra { color: var(--dim); flex: 1; }
#historyList .h-when { color: var(--dim); font-size: 12px; }

/* ---- global leaderboard ---- */

.lb-panel h3 { display: flex; justify-content: space-between; align-items: baseline; }
.lb-dur { color: var(--purple); font-size: 12px; letter-spacing: 0.1em; }

.lb-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.lb-tabs button {
  font: 600 11px/1 var(--font-body);
  letter-spacing: 0.08em;
  color: var(--dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  cursor: pointer;
  transition: color 0.1s, border-color 0.1s, background 0.1s;
}
.lb-tabs button:hover { color: var(--txt); border-color: var(--accent, var(--purple)); }
.lb-tabs button.on { color: #1c1206; background: var(--accent, var(--purple)); border-color: transparent; font-weight: 700; }

.lb-list { list-style: none; max-height: 210px; overflow-y: auto; }
.lb-list li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 6px 4px;
  border-bottom: 1px solid rgba(250, 239, 197, 0.05);
  font-size: 14px;
}
.lb-list li:last-child { border-bottom: none; }
.lb-list li.empty { color: var(--dim); border: none; }
.lb-list li.me { background: rgba(245, 196, 0, 0.08); border-radius: 6px; }
.lb-rank { width: 30px; flex: none; font-family: var(--font-display); font-weight: 700; font-size: 12px; color: var(--dim); }
.lb-list li:nth-child(1) .lb-rank { color: #ffd76a; }
.lb-list li:nth-child(2) .lb-rank { color: #eadfc4; }
.lb-list li:nth-child(3) .lb-rank { color: #e59a4a; }
.lb-name { flex: 1; font-weight: 600; letter-spacing: 0.04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-score { font-family: var(--font-display); font-weight: 700; font-size: 13px; }

/* ---- results → leaderboard submit ---- */

.res-submit { display: flex; gap: 8px; width: 100%; margin-top: 4px; }
.res-submit.hidden { display: none; }
#lbName {
  flex: 1; min-width: 0;
  font: 700 14px/1 var(--font-body);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--txt);
  background: rgba(250, 239, 197, 0.05);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  outline: none;
}
#lbName:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(245, 196, 0, 0.15); }
#lbName::placeholder { color: var(--dim); }
.btn.res-post { min-width: 0; padding: 12px 18px; }

.res-rank {
  font-family: var(--font-display);
  font-weight: 700; font-size: 15px;
  letter-spacing: 0.14em;
  color: #ffd76a;
  text-shadow: 0 0 16px rgba(245, 196, 0, 0.45);
}
.res-rank.hidden { display: none; }

/* ---- footer ---- */

.menu-foot {
  margin-top: auto;
  display: flex;
  justify-content: center;
  gap: 26px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--dim);
  padding-top: 8px;
}

.foot-brand {
  font-weight: 700;
  letter-spacing: 0.08em;
  background: linear-gradient(100deg, var(--purple), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ============ game ============ */

#game { background: transparent; }

#canvas {
  position: absolute;
  inset: 0;
  /* CRITICAL: a <canvas> is a replaced element — without an explicit CSS size it
     renders at its INTRINSIC size (width/height attributes = viewport × DPR).
     On displays with OS scaling (DPR 1.25/1.5…) that made the canvas overflow
     the viewport, offsetting every visual from the real cursor position and
     making border targets unclickable. Locking it to 100% keeps the on-screen
     size equal to the coordinate space. resize() also sets style.width/height
     as a belt-and-suspenders guarantee. */
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#game.playing #canvas { cursor: none; }

/* ---- HUD ---- */

#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 22px;
  pointer-events: none;
}

.hud-block { display: flex; gap: 26px; min-width: 180px; }
.hud-right { justify-content: flex-end; }

.hud-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--dim);
}

.hud-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
}

.hud-center { flex-direction: column; align-items: center; gap: 0; }

.hud-time {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-shadow: 0 0 20px rgba(255, 234, 166, 0.35);
}

.hud-mode {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: var(--dim);
}

/* ---- overlays ---- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 10, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 5;
}

.overlay.hidden { display: none; }

#countdown {
  background: rgba(5, 5, 10, 0.35);
  pointer-events: none;
}

.count-num {
  font-family: var(--font-display);
  font-size: 120px;
  font-weight: 900;
  background: linear-gradient(100deg, var(--purple), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 30px rgba(245, 196, 0, 0.5));
  animation: pop 0.9s ease infinite;
}

@keyframes pop {
  0% { transform: scale(1.25); opacity: 0.4; }
  25% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.96); opacity: 0.9; }
}

.overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: rgba(14, 14, 22, 0.92);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 34px 44px;
  min-width: 320px;
  box-shadow: 0 24px 80px -20px rgba(0, 0, 0, 0.8);
}

.overlay-card h2 {
  font-family: var(--font-display);
  font-weight: 900;
  letter-spacing: 0.2em;
  margin-bottom: 8px;
}

/* ---- buttons ---- */

.btn {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--txt);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 28px;
  min-width: 230px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
}

.btn:hover { transform: translateY(-1px); background: rgba(255, 255, 255, 0.1); }

.btn.primary {
  color: #1c1206;
  background: linear-gradient(100deg, var(--purple), var(--cyan));
  border: none;
}

.btn.primary:hover { box-shadow: 0 6px 28px -6px rgba(245, 196, 0, 0.7); }

.btn.ghost { background: transparent; color: var(--dim); }
.btn.ghost:hover { color: var(--txt); }

/* ---- results ---- */

.results-card { min-width: 380px; max-width: 92vw; }

.res-mode {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: var(--accent, var(--purple));
}

.res-best {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #facc15;
  text-shadow: 0 0 16px rgba(250, 204, 21, 0.5);
  animation: bestPulse 1.2s ease infinite;
}

.res-best.hidden { display: none; }

@keyframes bestPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.res-score {
  font-family: var(--font-display);
  font-size: 64px;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(100deg, var(--purple), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 24px rgba(255, 234, 166, 0.35));
}

.res-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 8px 26px;
  width: 100%;
  margin: 10px 0 6px;
}

.res-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 5px 0;
  font-size: 15px;
}

.res-stat .rs-label { color: var(--dim); font-weight: 600; }
.res-stat .rs-value { font-weight: 700; font-size: 16px; }

.res-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.res-hint { font-size: 12px; color: var(--dim); margin-top: 4px; }

/* ---- scrollbar ---- */

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* ---- brand sigil + title glow ---- */

.brand-sigil {
  font-size: 15px;
  letter-spacing: 0.6em;
  text-indent: 0.6em;
  color: var(--purple);
  opacity: 0.85;
  margin-bottom: 6px;
}

.brand h1 { animation: brandGlow 5s ease-in-out infinite; }
@keyframes brandGlow {
  0%, 100% { filter: drop-shadow(0 0 24px rgba(245, 196, 0, 0.35)); }
  50%      { filter: drop-shadow(0 0 40px rgba(245, 196, 0, 0.55)); }
}

/* ---- leaderboard platform filter + mobile badge ---- */

.lb-plat-seg { margin-bottom: 12px; }
.lb-plat-seg button { flex: 1; padding: 5px 8px; font-size: 13px; }

.lb-plat {
  width: 12px;
  height: 12px;
  margin-left: 6px;
  vertical-align: -1px;
  color: var(--purple);
  opacity: 0.9;
}

/* ============ mobile / touch ============ */

/* No physical keyboard → hotkey hints are noise */
@media (hover: none) and (pointer: coarse) {
  .menu-foot span { display: none; }
  .res-hint { display: none; }
}

@media (max-width: 700px) {
  .menu-inner { padding: 26px 14px 22px; gap: 18px; }
  .brand h1 { font-size: clamp(34px, 11vw, 48px); }
  .brand .sub { font-size: 12px; letter-spacing: 0.4em; text-indent: 0.4em; }

  .mode-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .mode-card { padding: 14px 12px 12px; }
  .mode-card .mc-desc { min-height: 0; font-size: 13px; }

  .setting-row { flex-wrap: wrap; row-gap: 6px; }
  .setting-row label { width: 100%; }

  /* HUD: compact so score / time / accuracy all fit a 360px screen */
  #hud { padding: 10px 12px; }
  .hud-block { min-width: 0; gap: 14px; }
  .hud-value { font-size: 19px; }
  .hud-time { font-size: 25px; }
  .hud-mode { font-size: 10px; letter-spacing: 0.22em; }
  .hud-label { font-size: 9px; }

  .overlay { padding: 14px; }
  .overlay-card { min-width: 0; width: min(100%, 400px); padding: 24px 18px; }
  .results-card { min-width: 0; }
  .btn { min-width: 0; width: 100%; }
  .res-score { font-size: 48px; }
  .res-stats { grid-template-columns: 1fr; }
  .res-submit { flex-direction: column; }
  .count-num { font-size: 88px; }
}

/* Very small landscape phones: keep the countdown/results on screen */
@media (max-height: 460px) {
  .overlay-card { padding: 16px 18px; gap: 8px; max-height: 92vh; overflow-y: auto; }
  .res-score { font-size: 40px; }
}
