/* EBS brand palette */
:root {
  --navy-900: #041e41; /* RGB 4,30,65 */
  --sand-500: #b29267; /* RGB 178,146,103 */
  --sand-400: #d1ad73; /* RGB 209,173,115 */
  --navy-800: #293455; /* RGB 41,52,85 */
  --blue-400: #6983be; /* RGB 105,131,190 */
  --blue-300: #8ea0bb; /* RGB 142,160,187 */
  --slate-600: #626574; /* RGB 98,101,116 */

  --bg: var(--navy-900);
  --card: #0b274e;
  --text: #f4f6fb;
  --muted: var(--blue-300);
  --accent: var(--sand-400);
  --accent-2: var(--sand-500);
  --primary: var(--blue-400);
  --line: var(--blue-300);
  --edge-pad: 80px; /* keep dot fully visible near edges with bigger dots */
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow-x: hidden; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg), var(--navy-800));
  color: var(--text);
}

.page {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.header {
  text-align: center;
  padding: 24px 16px 8px;
}
.header h1 {
  margin: 0 0 8px;
  font-weight: 700;
}
.subtitle {
  margin: 0;
  color: var(--muted);
}

.main {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 16px;
}

.card {
  background: rgba(4, 30, 65, 0.55);
  border: 1px solid rgba(142, 160, 187, 0.25);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

.card#gameSection {
  /* full-bleed: span viewport width and center */
  grid-column: 1 / -1;
  width: 100%;
  margin-left: 0;
  transform: none;
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto; /* title, instructions, arena, result */
  min-height: calc(100vh - 220px);
}
.card#gameSection h2 { text-align: center; margin: 8px 0 4px; }
.card#gameSection .instructions { text-align: center; margin: 0 0 8px; color: var(--muted); }
.attempt-counter { text-align: center; margin: 4px 0 12px; color: var(--muted); font-size: 0.95rem; }

/* Balance game */
.balance-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; margin: 12px 0; grid-row: 3; align-self: center; }
.timer { font-weight: 800; letter-spacing: 1px; font-size: clamp(72px, 12vw, 160px); line-height: 1; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-variant-numeric: tabular-nums; }
.discount { font-size: 28px; color: var(--muted); text-align: center; }
.balance-result { text-align: center; margin: 8px 0 0; }
.field.checkbox label { display: flex; align-items: center; gap: 8px; }

#formSection.card, #scoresSection.card {
  grid-column: 1 / -1;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  justify-self: center; /* ensure equal width in grid */
}

.field { margin-bottom: 12px; }
label { display: block; margin-bottom: 6px; color: var(--muted); }
input[type="text"], input[type="email"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(142,160,187,0.35);
  background: rgba(255,255,255,0.06);
  color: var(--text);
}
input::placeholder { color: rgba(255,255,255,0.5); }

input.invalid {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(209,173,115,0.25);
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  color: var(--text);
  background: var(--slate-600);
}
.btn.primary { background: var(--primary); }
.card #playerForm .btn.primary { width: 100%; display: block; font-size: xx-large; }
.btn:focus { outline: 3px solid rgba(209,173,115,0.6); outline-offset: 2px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.note { color: var(--muted); font-size: 0.9rem; }

.error {
  margin: 6px 0 0;
  color: var(--accent);
  font-size: 0.9rem;
  min-height: 1.1em; /* reserve space to reduce layout shift */
}

.arena {
  outline: none;
  margin: 12px 0 8px;
  /* Center this block to viewport and allow full viewport width */
  width: 100%;
  margin-left: 0;
  transform: none;
  padding: 24px 0;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(105,131,190,0.08), rgba(4,30,65,0.6));
  place-self: stretch; /* fill row */
  display: flex;
  align-items: center; /* vertically center the line/dot */
  justify-content: center; /* horizontally center the line container */
}
.line {
  position: relative;
  height: 20px;
  background: linear-gradient(90deg, rgba(142,160,187,0.35), rgba(142,160,187,0.35));
  border-radius: 999px;
  overflow: visible;
  /* extend close to viewport width with safe side padding */
  width: min(1400px, calc(100vw - var(--edge-pad) * 2));
  margin: 0 auto;
}
.center-mark {
  position: absolute;
  left: 50%;
  top: -26px;
  transform: translateX(-50%);
  width: 6px;
  height: 72px;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(209,173,115,0.2);
}
.ghost-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 96px; height: 96px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.8), rgba(178,146,103,0.8));
  opacity: 0.25;
  pointer-events: none;
}
.dot {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 96px; height: 96px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff, var(--accent-2));
  box-shadow: 0 20px 36px rgba(0,0,0,0.45), 0 0 0 10px rgba(178,146,103,0.25);
  left: 0%;
}

.controls { margin-top: 1em; display: flex; justify-content: center; gap: 12px; align-items: center; }
.balance-controls .btn { font-size: clamp(1.25rem, 3.5vw, 2rem); padding: 18px 28px; min-width: 200px; }
.result { margin-top: 8px; font-size: 1.1rem; color: var(--accent); }

.scores { margin: 0; padding-left: 20px; }
.scores li { padding: 8px 0; }
.scores.hidden { display: none; }
.scores li.me { font-weight: 700; color: var(--accent); }

/* fullscreen overlays (countdown + result) */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(6px);
  z-index: 1000;
}
.overlay.hidden { display: none; }
.overlay-inner { text-align: center; padding: 16px; }
.overlay-title { font-size: clamp(1.25rem, 2.4vw, 2rem); color: var(--text); margin-bottom: 4px; }
.overlay-sub { font-size: clamp(1rem, 2vw, 1.25rem); color: var(--muted); margin-bottom: 12px; }
.overlay-number {
  font-size: clamp(4rem, 16vw, 12rem);
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 6px 24px rgba(0,0,0,0.5);
  line-height: 1;
}
.overlay-number.anim { animation: overlayPop 360ms ease-out both; }
.overlay-result { font-size: clamp(2rem, 6vw, 4rem); color: var(--accent); margin-bottom: 16px; font-weight: 800; }
.overlay-btn { font-size: clamp(1rem, 2.4vw, 1.25rem); padding: 14px 24px; }
.overlay-note { color: var(--text); margin-bottom: 12px; font-size: clamp(1rem, 2.2vw, 1.25rem); }
.overlay-scores { margin-top: 1em; max-width: 600px; margin: 0 auto; text-align: center; }
.overlay-scores ol.scores { list-style: none; padding-left: 0; margin: 0; }
.overlay-scores .scores li { text-align: center; }
.overlay-scores.hidden { display: none; }
/* More breathing room in overlay list */
.overlay-scores .overlay-sub { margin-bottom: 16px; }
/* Center main High Scores header */
#scoresSection h2 { text-align: center; }

@keyframes overlayPop {
  0% { opacity: 0; transform: scale(0.9); }
  40% { opacity: 1; transform: scale(1.05); }
  100% { opacity: 0.15; transform: scale(1); }
}

/* countdown overlay */
.countdown {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(2rem, 6vw, 5rem);
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 2px 10px rgba(0,0,0,0.45);
  pointer-events: none; /* don't block clicks */
  user-select: none;
  opacity: 0;
}
.countdown.anim {
  animation: fadePop 320ms ease-out both;
}
@keyframes fadePop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.9); }
  40% { opacity: 1; transform: translateX(-50%) scale(1.05); }
  100% { opacity: 0.15; transform: translateX(-50%) scale(1); }
}

/* animated bar while active */
.line.active {
  /* dual backgrounds: each half moves toward center */
  background-image:
    repeating-linear-gradient(90deg, rgba(142,160,187,0.28) 0 28px, rgba(142,160,187,0.16) 28px 56px),
    repeating-linear-gradient(-90deg, rgba(142,160,187,0.28) 0 28px, rgba(142,160,187,0.16) 28px 56px);
  background-size: 50% 100%, 50% 100%;
  background-position: 0 0, 100% 0;
  background-repeat: repeat;
  animation: stripes-in 3s ease-in-out infinite alternate;
}
.line.active::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 40%;
  height: 100%;
  pointer-events: none;
  background: radial-gradient(closest-side, rgba(209,173,115,0.35), rgba(209,173,115,0.15) 60%, rgba(209,173,115,0) 70%);
  animation: center-pulse 1.6s ease-in-out infinite;
}
@keyframes stripes-in {
  from { background-position: 0 0, 100% 0; }
  to   { background-position: 50% 0, 50% 0; }
}
@keyframes center-pulse {
  0%, 100% { opacity: 0.8; transform: translate(-50%, -50%) scaleX(1); }
  50%      { opacity: 1;   transform: translate(-50%, -50%) scaleX(1.15); }
}

/* footer toggle link */
.footer .toggle-link {
  color: var(--blue-300);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.95rem;
}
.footer .toggle-link:focus { outline: 3px solid rgba(209,173,115,0.6); outline-offset: 3px; }

.footer {
  text-align: center;
  padding: 16px;
  color: var(--muted);
}

.hidden { display: none !important; }

@media (min-width: 900px) {
  .main { grid-template-columns: 1fr 1fr; grid-auto-flow: dense; }
  #scoresSection { grid-column: 1 / span 2; }
}
