/* ===== 1. Design tokens (our colours and sizes, defined once) ===== */
:root {
  --bg: #F6F8FF;
  --navy: #0B1F4B;
  --blue: #2F6BFF;
  --blue-soft: #E3EBFF;
  --blue-mid: #BFD2FF;
  --yellow: #FFC93C;
  --red: #E5484D;
  --white: #FFFFFF;

  --tile: 96px;        /* tile width and height */
  --gap: 16px;         /* space between tiles */
  --pad: 16px;         /* padding inside the tile stage */
  --max: 920px;        /* max width of the page content */
  --pair-index: 1;     /* spotlight starts on this tile (JS changes it) */

  --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===== 2. Base ===== */
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(11, 31, 75, 0.09) 1.5px, transparent 1.5px);
  background-size: 26px 26px;
  color: var(--navy);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

/* ===== 3. Top bar ===== */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  max-width: var(--max);
  margin: 0 auto;
  padding: 24px;
}

.logo {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.logo span {
  color: var(--blue);
  background: linear-gradient(transparent 62%, var(--yellow) 62%);
  padding: 0 4px;
}

.stats { display: flex; gap: 12px; }

.stat {
  position: relative;
  background: var(--white);
  border: 3px solid var(--navy);
  border-radius: 12px;
  padding: 6px 14px;
  font-weight: 700;
  box-shadow: 0 4px 0 var(--navy);
}

.stat strong {
  display: inline-block;
  margin-left: 6px;
  font-size: 1.3rem;
  color: var(--blue);
}

/* ===== 4. Game area and progress ===== */
.game {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 24px 48px;
}

.progress-area { margin: 8px 0 24px; }

#progress-label { margin: 0 0 8px; font-weight: 700; }

.progress-track {
  height: 18px;
  background: var(--white);
  border: 3px solid var(--navy);
  border-radius: 12px;
  overflow: hidden;
}

.progress-fill {
  width: 7%;
  height: 100%;
  background: var(--blue);
  border-radius: 8px;
  transition: width 0.5s var(--bounce);
}

/* ===== 5. The arena card ===== */
.arena-card {
  background: var(--white);
  border: 3px solid var(--navy);
  border-radius: 24px;
  padding: 32px 24px 36px;
  box-shadow: 8px 8px 0 var(--blue-mid);
  text-align: center;
}

#question {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

/* ===== 6. Tiles, spotlight, pointer ===== */
.tile-stage {
  position: relative;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 56px var(--pad) 24px;
}

.tile-row {
  position: relative;
  z-index: 1;               /* keeps tiles above the spotlight */
  display: flex;
  gap: var(--gap);
}

.tile {
  position: relative;       /* lets the MIN / KEY tags sit on a tile */
  width: var(--tile);
  height: var(--tile);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  font-weight: 800;
  background: var(--white);
  border: 3px solid var(--navy);
  border-radius: 18px;
  box-shadow: 0 6px 0 var(--navy);      /* the chunky bottom edge */
  transition:
    transform 0.45s var(--bounce),      /* slide-with-bounce on swap */
    translate 0.25s var(--bounce),      /* lift when compared */
    background-color 0.2s;
}

/* Tile states. Order matters: later rules win when two apply. */
.tile.is-compared {
  background: var(--blue);
  color: var(--white);
  translate: 0 -6px;
}

.tile.is-sorted {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 6px 0 var(--blue);
}

.tile.is-min,
.tile.is-key {
  background: var(--yellow);
  color: var(--navy);
  border-color: var(--navy);
  box-shadow: 0 6px 0 var(--navy);
}

.tile.is-min::after,
.tile.is-key::after {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  padding: 1px 8px;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--white);
  background: var(--navy);
  border-radius: 8px;
}

.tile.is-min::after { content: "MIN"; }
.tile.is-key::after { content: "KEY"; }

.spotlight {
  position: absolute;
  top: 42px;
  left: calc(var(--pad) + var(--pair-index) * (var(--tile) + var(--gap)) - 12px);
  width: calc(var(--tile) * 2 + var(--gap) + 24px);
  height: calc(var(--tile) + 34px);
  background: var(--blue-soft);
  border: 3px dashed var(--blue);
  border-radius: 22px;
  transition: left 0.45s var(--bounce);
}

.pointer {
  position: absolute;
  top: 12px;
  left: calc(var(--pad) + var(--pair-index) * (var(--tile) + var(--gap)) + var(--tile) + var(--gap) / 2 - 14px);
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 22px solid var(--navy);
  transition: left 0.45s var(--bounce);
  animation: bob 1.1s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(6px); }
}

/* ===== 7. Buttons ===== */
.actions {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 28px;
}

.btn {
  font: inherit;
  font-size: 1.4rem;
  font-weight: 800;
  min-width: 170px;
  padding: 16px 32px;
  border: 3px solid var(--navy);
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--navy);
  transition: transform 0.18s var(--bounce), box-shadow 0.18s var(--bounce);
}

.btn-swap { background: var(--blue); color: var(--white); }
.btn-keep { background: var(--white); color: var(--navy); }

.btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 9px 0 var(--navy);
}

.btn:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 var(--navy);
}

/* Keyboard / remote focus: big, obvious, but it doesn't block anything */
.btn:focus-visible {
  outline: none;
  transform: scale(1.07);
  box-shadow: 0 6px 0 var(--navy), 0 0 0 5px var(--white), 0 0 0 10px var(--blue);
}

/* ===== 8. Feedback line ===== */
.feedback {
  max-width: 560px;
  margin: 28px auto 0;
  padding: 14px 18px;
  background: var(--blue-soft);
  border-left: 6px solid var(--blue);
  border-radius: 12px;
  font-size: 1.15rem;
  text-align: left;
}

.feedback.is-correct { background: #FFF6D9; border-left-color: var(--yellow); }
.feedback.is-wrong   { background: #FFE8E9; border-left-color: var(--red); }

/* ===== 9. Controls hint ===== */
.controls-hint {
  margin: 24px 0 0;
  font-size: 1rem;
  font-weight: 700;
  opacity: 0.75;
}

kbd {
  display: inline-block;
  min-width: 2em;
  padding: 2px 8px;
  font: inherit;
  font-weight: 800;
  background: var(--white);
  border: 2px solid var(--navy);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--navy);
}

/* ===== 10. Score pop ===== */
.score-pop {
  position: absolute;
  right: 6px;
  top: -4px;
  padding: 0 8px;
  font-weight: 800;
  color: var(--navy);
  background: var(--yellow);
  border: 2px solid var(--navy);
  border-radius: 10px;
  pointer-events: none;                    /* never blocks clicks or focus */
  z-index: 5;
}

/* ===== 11. Finish screen ===== */
.finish-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  background: rgba(246, 248, 255, 0.96);
  text-align: center;
}

.finish-screen[hidden] { display: none; }   /* without this, "hidden" would be ignored */

.finish-screen h2 { margin: 0; font-size: 3.2rem; }

.finish-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 8px;
}

/* ===== 12. Menu screen ===== */
.menu-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 24px 48px;
  text-align: center;
}

.menu-title { margin: 8px 0 4px; font-size: 2.2rem; font-weight: 800; }
.menu-sub   { margin: 0 0 28px; font-size: 1.15rem; }

.algo-cards {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 20px;
}

.algo-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 260px;
  padding: 20px;
  font: inherit;
  color: var(--navy);
  text-align: left;
  background: var(--white);
  border: 3px solid var(--navy);
  border-radius: 20px;
  box-shadow: 0 6px 0 var(--navy);
  cursor: pointer;
  transition: transform 0.18s var(--bounce), box-shadow 0.18s var(--bounce), background-color 0.2s;
}

.algo-name { font-size: 1.4rem; font-weight: 800; }
.algo-desc { font-size: 1rem; }

.algo-card.is-selected { background: var(--blue); color: var(--white); }

.algo-card:disabled {
  opacity: 0.55;
  border-style: dashed;
  box-shadow: 0 6px 0 var(--blue-mid);
  cursor: not-allowed;
}

.algo-card:not(:disabled):hover,
.size-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 9px 0 var(--navy);
}

.algo-card:not(:disabled):active,
.size-btn:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 var(--navy);
}

.algo-card:focus-visible,
.size-btn:focus-visible {
  outline: none;
  transform: scale(1.05);
  box-shadow: 0 6px 0 var(--navy), 0 0 0 5px var(--white), 0 0 0 10px var(--blue);
}

.menu-label { margin: 32px 0 12px; font-size: 1.2rem; font-weight: 800; }

.size-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
}

.size-btn {
  display: flex;
  flex-direction: column;
  min-width: 150px;
  padding: 12px 20px;
  font: inherit;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--navy);
  background: var(--white);
  border: 3px solid var(--navy);
  border-radius: 16px;
  box-shadow: 0 5px 0 var(--navy);
  cursor: pointer;
  transition: transform 0.18s var(--bounce), box-shadow 0.18s var(--bounce), background-color 0.2s;
}

.size-btn small { font-size: 0.85rem; font-weight: 700; opacity: 0.8; }
.size-btn.is-selected { background: var(--yellow); }

.btn-start { margin-top: 36px; }

/* ===== 13. Screen sizes ===== */
@media (max-width: 640px) {
  :root { --tile: 34px; --gap: 4px; --pad: 8px; }   /* so 7 tiles still fit on a phone */
  .game { padding: 0 12px 32px; }
  .arena-card { padding: 24px 12px 28px; }
  .tile { font-size: 1.2rem; border-radius: 10px; }
  #question { font-size: 1.2rem; }
  .btn { min-width: 120px; padding: 14px 20px; font-size: 1.15rem; }
  .actions { gap: 16px; }
  .menu-title { font-size: 1.7rem; }
  .algo-card { width: 100%; }
}

@media (min-width: 1400px) {          /* big-screen / TV-ish sizing */
  :root { --tile: 128px; --gap: 20px; --max: 1200px; }
  body { padding: 2.5vh 2.5vw; }      /* keeps content away from the screen edges */
  .tile { font-size: 3.4rem; }
  #question { font-size: 2rem; }
  .btn { font-size: 1.8rem; min-width: 220px; }
  .feedback { font-size: 1.4rem; max-width: 760px; }
}

/* ===== 14. Best score label ===== */
.algo-best {
  margin-top: 4px;
  font-size: 0.95rem;
  font-weight: 800;
  opacity: 0.9;
}