/* SNEK: a copy of LAMPONG's stylesheet (matrix green on black, Courier, glow); only the score bar labels differ. */
:root {
  --bg: #000;
  --green: #00ff41;
  --green-dim: #5fbf73;
  --focus: #fff;
  --glow: 0 0 10px var(--green);
  --text-glow: 0 0 8px var(--green);
  --font: "Courier New", Courier, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--green);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

#rain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.25;
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 840px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.title {
  margin: 0;
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 700;
  letter-spacing: clamp(2px, 1vw, 5px);
  text-transform: uppercase;
  text-shadow: 0 0 15px var(--green);
}

.scorebar {
  display: flex;
  justify-content: center;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 32px;
}
.lengthcount {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
  letter-spacing: 3px;
}
.lengthcount .num { font-size: 32px; font-weight: 700; text-shadow: 0 0 15px var(--green); }
.lengthcount .side { font-size: 16px; color: var(--green-dim); }

.score {
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 14px;
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
  letter-spacing: 3px;
}
.score .num { font-size: 48px; font-weight: 700; min-width: 1.2em; text-align: center; text-shadow: 0 0 15px var(--green); }
.score .side { font-size: 16px; color: var(--green-dim); }

.stage { position: relative; }

canvas#field {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 500;
  background: var(--bg);
  border: 2px solid var(--green);
  box-shadow: var(--glow);
  touch-action: none;
}
canvas#field.playing { cursor: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px;
  text-align: center;
  background: rgba(0, 0, 0, 0.82);
}
.overlay[hidden] { display: none; }
.overlay h2 {
  margin: 0;
  font-size: clamp(26px, 6vw, 40px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: clamp(2px, 1vw, 5px);
  text-shadow: 0 0 15px var(--green);
  animation: flicker 2.6s infinite;
}
.overlay p { margin: 0; font-size: 16px; color: var(--green-dim); max-width: 45ch; }

/* Gentle dips only: never a full blink, well under three flashes a second. */
@keyframes flicker {
  0%, 100% { opacity: 1; }
  41% { opacity: 1; }
  43% { opacity: 0.75; }
  46% { opacity: 1; }
  78% { opacity: 0.85; }
  80% { opacity: 1; }
}

button, .back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  min-width: 48px;
  padding: 10px 18px;
  font: 700 16px var(--font);
  letter-spacing: 3px;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--green);
  background: var(--bg);
  border: 2px solid var(--green);
  box-shadow: var(--glow);
  text-shadow: var(--text-glow);
  cursor: pointer;
}
button:focus-visible {
  color: var(--bg);
  background: var(--green);
  text-shadow: none;
}
/* Only real pointers hover; on touch screens a hover state sticks after a tap. */
@media (hover: hover) {
  button:hover {
    color: var(--bg);
    background: var(--green);
    text-shadow: none;
  }
  button.secondary:hover, .back:hover {
    color: var(--bg);
    background: var(--green-dim);
  }
}
button.secondary, .back {
  color: var(--green-dim);
  border-color: var(--green-dim);
  box-shadow: none;
  text-shadow: none;
  font-size: 14px;
}
button.secondary:focus-visible, .back:focus-visible {
  color: var(--bg);
  background: var(--green-dim);
}
button:focus-visible, .back:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.hint { margin: 0; font-size: 15px; color: var(--green); letter-spacing: 1px; }

/* GAME OVER: heads flood the screen, the panel stays readable on a solid backdrop. */
#flood {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}
.gameover {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  width: min(90vw, 460px);
  max-height: 90dvh;
  overflow-y: auto;
  padding: 28px 20px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  background: rgba(0, 0, 0, 0.96);
  border: 1px solid var(--green);
  box-shadow: var(--glow);
}
.gameover h2 {
  margin: 0;
  font-size: clamp(40px, 10vw, 64px);
  font-weight: 700;
  letter-spacing: clamp(2px, 1vw, 5px);
  text-transform: uppercase;
  text-shadow: 0 0 15px var(--green);
}
.gameover p {
  margin: 0;
  font-size: 20px;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.gameover .msg:empty { display: none; }
.gameover .msg, .gameover .note {
  font-size: 15px;
  letter-spacing: 1px;
  text-transform: none;
  color: var(--green);
}
.gameover .note { color: var(--green-dim); }
.gameover > button { width: 100%; }

/* The one filled button per state: Save score, or Play again once saved. */
button.primary {
  color: var(--bg);
  background: var(--green);
  text-shadow: none;
}
button:disabled {
  cursor: default;
  color: var(--green);
  background: var(--bg);
  border-style: dashed;
  box-shadow: none;
}

.save {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  text-align: left;
}
.save label {
  font-size: 15px;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.save input {
  min-height: 48px;
  padding: 10px 12px;
  font: 700 18px var(--font);
  letter-spacing: 1px;
  color: var(--green);
  background: var(--bg);
  border: 2px solid var(--green);
  border-radius: 0;
}
.save input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.save input[aria-invalid="true"] { border-style: dashed; }
.save input:disabled { color: var(--green-dim); border-color: var(--green-dim); }

.highscores { width: 100%; }
.highscores ol {
  margin: 0;
  padding: 0;
  list-style: none;
  font-variant-numeric: tabular-nums;
}
.highscores li {
  display: grid;
  grid-template-columns: 3ch 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 32px;
  font-size: 16px;
  text-align: left;
  border-bottom: 1px solid rgba(0, 255, 65, 0.25);
}
.highscores .rank { text-align: right; color: var(--green-dim); }
.highscores .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.highscores .col-score { text-align: right; }
.highscores li.mine { font-weight: 700; }
.highscores li.mine .rank { color: var(--green); }

@media (prefers-reduced-motion: reduce) {
  .overlay h2 { animation: none; }
  #rain { display: none; }
}
