/* Same look as LAMPONG (matrix green on black, Courier, glow); the board replaces the playing field. */
: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;
}
.stat {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
  letter-spacing: 3px;
}
.stat .num { font-size: 32px; font-weight: 700; text-shadow: 0 0 15px var(--green); }
.stat .side { font-size: 16px; color: var(--green-dim); }

.stage { position: relative; }

/* The board: 4 columns on wide screens, 3 on phones, always fitting the screen height. */
.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 8px;
  width: min(100%, max(320px, calc((100dvh - 280px) * 4 / 3)));
  margin: 0 auto;
  background: var(--bg);
  border: 2px solid var(--green);
  box-shadow: var(--glow);
  touch-action: manipulation;
}
@media (max-width: 519px) {
  .board {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 6px;
    width: min(100%, max(240px, calc((100dvh - 300px) * 3 / 4)));
  }
}

/* A cabin is a button with two faces: the closed cabin and its picture. */
.board .cabin {
  position: relative;
  display: block;
  min-height: 0;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--green-dim);
  box-shadow: none;
  perspective: 600px;
}
.cabin .face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  transition: transform 0.3s;
}
.cabin .face img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cabin .closed img { filter: brightness(0.85); }
.cabin .picture { transform: rotateY(180deg); }
.cabin.open .closed, .cabin.found .closed { transform: rotateY(180deg); }
.cabin.open .picture, .cabin.found .picture { transform: rotateY(0); }
.cabin.found { border: 2px solid var(--green); box-shadow: var(--glow); }
.cabin .badge {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 1;
  display: none;
  padding: 0 6px;
  font: 700 16px var(--font);
  color: var(--bg);
  background: var(--green);
}
.cabin.found .badge { display: block; }
/* Without its image a face still says what it is, instead of a broken picture. */
.cabin .face.missing img { display: none; }
.cabin .face.missing::after {
  content: attr(data-label);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 700 14px var(--font);
  letter-spacing: 1px;
  color: var(--green);
  text-transform: uppercase;
}
.board .cabin:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  background: var(--bg);
}
@media (hover: hover) {
  .board .cabin:hover { background: var(--bg); border-color: var(--green); }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.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; }

/* Finish: the pictures 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 .gameover-time { font-size: 24px; font-weight: 700; text-shadow: 0 0 10px var(--green); }
.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. */
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 .time { 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; }
  .cabin .face { transition: none; }
}
