:root {
  --bg: #f4f7f4;
  --card: #ffffff;
  --ink: #1e2a1e;
  --muted: #6b7a6b;
  --accent: #2e7d32;
  --accent-dark: #1b5e20;
  --marked: #a5d6a7;
  --marked-ink: #14361a;
  --border: #d7e2d7;
  --error: #c62828;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  --mark: #e53935;
  --win: #f9a825;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141814;
    --card: #1e241e;
    --ink: #e8f0e8;
    --muted: #9bab9b;
    --accent: #66bb6a;
    --accent-dark: #43a047;
    --marked: #2e5d33;
    --marked-ink: #eafaea;
    --border: #334033;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    --mark: #ff5252;
    --win: #ffca28;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

header { text-align: center; margin-bottom: 20px; }
h1 { margin: 0 0 4px; font-size: 2rem; }
.tagline { margin: 0; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

form { display: flex; flex-direction: column; gap: 6px; }
label { font-weight: 600; font-size: 0.9rem; margin-top: 8px; }

input, select {
  padding: 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

button {
  margin-top: 16px;
  padding: 13px 16px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
button:hover { background: var(--accent-dark); }
button.secondary {
  margin: 0;
  padding: 9px 14px;
  font-size: 0.85rem;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--bg); }

.hint { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; }
.error { color: var(--error); font-weight: 600; margin-top: 12px; }

.game-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.game-head h2 { margin: 0; font-size: 1.3rem; }

.banner {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 800;
  padding: 12px;
  margin-bottom: 16px;
  border-radius: 10px;
  background: var(--marked);
  color: var(--marked-ink);
  animation: pop 0.4s ease;
}
@keyframes pop { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, transform 0.06s;
  overflow: hidden;
}
.cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
  pointer-events: none; /* langtrykk treffer knappen, ikke bildet (ingen «lagre bilde»-meny) */
}
.cell .label {
  position: relative;
  z-index: 1;
  padding: 2px 3px;
  font-size: clamp(0.55rem, 2.4vw, 0.78rem);
  font-weight: 700;
  line-height: 1.1;
  color: #fff;
  width: 100%;
  margin-top: auto;
  background: rgba(0, 0, 0, 0.55);
  word-break: break-word;
}
/* Ruter uten bilde: vis teksten sentrert i normal farge. */
.cell:not(:has(img)) .label {
  margin: auto;
  color: var(--ink);
  background: transparent;
  font-size: clamp(0.6rem, 2.6vw, 0.85rem);
}
.cell:hover { border-color: var(--accent); }
.cell:active { transform: scale(0.96); }
/* Avkrysset rute: tydelig rød ramme + rød hake-brikke i hjørnet. */
.cell.marked {
  border-color: var(--mark);
  box-shadow: inset 0 0 0 3px var(--mark);
}
.cell.marked img { opacity: 0.5; }
.cell.marked:not(:has(img)) { background: var(--marked); }
.cell.marked:not(:has(img)) .label { color: var(--marked-ink); }
.cell.marked::after {
  content: "✓";
  position: absolute;
  top: 3px;
  right: 3px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(17px, 5.5vw, 26px);
  height: clamp(17px, 5.5vw, 26px);
  border-radius: 50%;
  background: var(--mark);
  color: #fff;
  font-size: clamp(0.72rem, 3.4vw, 1rem);
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}
.cell.free { background: var(--accent); border-color: var(--accent); cursor: default; }
.cell.free .label { color: #fff; background: transparent; }
/* Vinnerrekke: gull ramme (vises også når ruten er avkrysset). */
.cell.win { outline: 3px solid var(--win); outline-offset: -3px; }

.tip { text-align: center; margin: 0 0 12px; }
.expiry { text-align: center; margin-top: 16px; }
footer { text-align: center; }

/* Unngå iOS-«lagre bilde»-meny ved langtrykk. */
.cell, .cell img { -webkit-touch-callout: none; }

/* Forstørret forhåndsvisning (hover på PC / langtrykk på mobil). */
#preview {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: rgba(0, 0, 0, 0.82);
  pointer-events: none; /* stjeler ikke musepekeren, så hover-tilstanden holder */
}
#preview.open { display: flex; }
#preview img {
  max-width: 88vw;
  max-height: 76vh;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 44px rgba(0, 0, 0, 0.6);
}
#preview .plabel {
  color: #fff;
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
}
