:root {
  --bg: #2e2e2e;
  --panel: #3a3a3a;
  --panel-dark: #262626;
  --lamp-off: #224b63;
  --lamp-on: #ffd93d;
  --accent: #4ecdc4;
  --gold: #ffd93d;
  --silver: #d0d0d0;
  --bronze: #d9965b;
  --text: #f2f2f2;
  --muted: #a0a0a0;
  --danger: #ff6b6b;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
  padding: 2rem 1rem 3rem;
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Press Start 2P', cursive;
}

/* --- Topptekst --------------------------------------------------------- */

.header {
  text-align: center;
}

.header h1 {
  font-size: 1.4rem;
  margin: 0 0 0.75rem;
}

.subtitle {
  font-size: 0.6rem;
  line-height: 1.6;
  color: var(--muted);
  margin: 0;
}

/* --- To-kolonne-oppsett: spill til venstre, highscore til høyre --------- */

.layout {
  width: 100%;
  max-width: 900px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1.5rem;
  align-items: start;
}

.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

/* --- Statuslinje ------------------------------------------------------- */

.status-bar {
  display: flex;
  gap: 0.75rem;
  width: 100%;
  justify-content: center;
}

.status-box {
  flex: 1;
  max-width: 150px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.status-label {
  font-size: 0.5rem;
  color: var(--muted);
}

.status-value {
  font-size: 0.7rem;
  color: var(--accent);
}

/* --- Lampenett --------------------------------------------------------- */

.grid {
  width: 100%;
  max-width: 480px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 10px;
  border: 4px solid var(--panel);
  border-radius: var(--radius);
  background: var(--panel-dark);
}

.lamp {
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background-color: var(--lamp-off);
  opacity: 0.25;
  transition: opacity 0.08s ease-out;
  cursor: default;
}

.lamp.lamp-on {
  background-color: var(--lamp-on);
  opacity: 1;
  cursor: pointer;
  box-shadow: 0 0 20px 2px rgba(255, 217, 61, 0.6);
}

/* --- Knapper og hint ---------------------------------------------------- */

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.btn {
  font-family: 'Press Start 2P', cursive;
  border: none;
  border-radius: 12px;
  padding: 0.9rem 1.6rem;
  font-size: 0.65rem;
  cursor: pointer;
  transition: transform 0.05s ease-out, opacity 0.1s;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--accent);
  color: #103331;
}

.btn-secondary {
  background-color: var(--panel);
  color: var(--text);
}

.hint {
  font-size: 0.55rem;
  color: var(--muted);
  text-align: center;
  max-width: 420px;
  margin: 0;
}

/* --- Highscore-panel ----------------------------------------------------- */

.leaderboard {
  position: sticky;
  top: 1.5rem;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
}

.leaderboard h2 {
  font-size: 0.85rem;
  margin: 0;
  text-align: center;
}

.leaderboard-sub {
  font-size: 0.5rem;
  color: var(--muted);
  text-align: center;
  margin: 0.6rem 0 1rem;
}

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.55rem;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.6rem;
  background: var(--panel-dark);
  border-radius: 8px;
  line-height: 1.4;
}

/* Hver rad: plass | navn + dato | tid */
.player {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.date {
  font-size: 0.45rem;
  color: var(--muted);
}

.time {
  color: var(--accent);
  white-space: nowrap;
}

.leaderboard-list li:nth-child(1) .rank { color: var(--gold); }
.leaderboard-list li:nth-child(2) .rank { color: var(--silver); }
.leaderboard-list li:nth-child(3) .rank { color: var(--bronze); }

.rank {
  color: var(--accent);
  min-width: 1.6rem;
}

.leaderboard-empty {
  display: block !important;
  text-align: center;
  color: var(--muted);
  line-height: 1.6 !important;
}

/* --- Dialog / modal ------------------------------------------------------ */

.dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 1.5rem;
  width: min(90vw, 380px);
  font-family: 'Press Start 2P', cursive;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.dialog-form h2 {
  font-size: 1rem;
  margin: 0;
}

.dialog-form p {
  font-size: 0.6rem;
  line-height: 1.6;
  color: var(--muted);
  margin: 0;
}

.dialog-form label {
  font-size: 0.55rem;
  color: var(--muted);
}

.dialog-form input {
  font-family: inherit;
  font-size: 0.7rem;
  padding: 0.6rem;
  border-radius: 8px;
  border: 2px solid #555;
  background: var(--panel-dark);
  color: var(--text);
}

.dialog-form input:focus {
  outline: 2px solid var(--accent);
}

.error-text {
  color: var(--danger) !important;
  min-height: 1em;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* --- Smale skjermer: highscore flyttes under spillet --------------------- */

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    max-width: 520px;
  }

  .leaderboard {
    position: static;
  }
}

@media (max-width: 480px) {
  body {
    padding: 1.5rem 1rem 2.5rem;
  }

  .header h1 {
    font-size: 1.1rem;
  }

  .status-box {
    padding: 0.6rem 0.4rem;
  }

  .status-value {
    font-size: 0.6rem;
  }
}
