/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #070e1b;
  --surface:     #0c1525;
  --surface2:    #111e30;
  --cell-empty:  #0f1d35;
  --cell-border: #1a2d4a;
  --accent:      #22c55e;
  --accent2:     #6c5fff;
  --gold:        #fbbf24;
  --green:       #34d399;
  --red:         #f87171;
  --text:        #e8edf8;
  --text-dim:    #8892aa;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,.6);
}

html { height: 100%; background: var(--bg); }

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── App shell ────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: min(100dvh, 900px);
  max-width: 480px;
  padding: env(safe-area-inset-top, 8px) 12px env(safe-area-inset-bottom, 8px);
  gap: 6px;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 4px 0;
}

.logo {
  font-size: clamp(1.1rem, 5vw, 1.4rem);
  font-weight: 900;
  letter-spacing: -0.5px;
  white-space: nowrap;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  flex: 1;
}

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

.score-box { text-align: center; line-height: 1.1; }

.score-box .label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  display: block;
}

.score-box .value {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.header-btns { display: flex; gap: 6px; }

.lives {
  font-size: 1rem;
  letter-spacing: 2px;
  flex-shrink: 0;
}

.icon-btn {
  background: var(--surface2);
  border: 1px solid var(--cell-border);
  color: var(--text);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Timer ────────────────────────────────────────────────── */
.timer-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.timer-track {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

#timer-bar {
  height: 100%;
  width: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.9s linear, background 0.5s;
}

#timer-label {
  font-variant-numeric: tabular-nums;
  min-width: 28px;
  text-align: right;
}

.mult-badge {
  background: var(--surface2);
  border: 1px solid var(--cell-border);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold);
  min-width: 38px;
  text-align: center;
}

/* ── Board ────────────────────────────────────────────────── */
#board-wrap {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 3px;
  width: min(calc(100vw - 24px), 380px);
  aspect-ratio: 1;
  touch-action: none;
}

@keyframes shuffleAnim {
  0%   { opacity: 1; transform: scale(1); }
  40%  { opacity: 0; transform: scale(0.88); }
  60%  { opacity: 0; transform: scale(0.88); }
  100% { opacity: 1; transform: scale(1); }
}

#board.shuffling { animation: shuffleAnim 0.9s ease-in-out; }

/* ── Cells ────────────────────────────────────────────────── */
.cell {
  background: var(--cell-empty);
  border: 1px solid var(--cell-border);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.75rem, 2.8vw, 1rem);
  font-weight: 700;
  letter-spacing: 0;
  color: #c8c8e8;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, transform 0.08s;
  aspect-ratio: 1;
}

.cell.selecting {
  background: var(--accent);
  color: #fff;
  transform: scale(1.06);
  z-index: 2;
}

.cell.found {
  color: #fff;
}

.cell.found-target {
  background: #1d4e2a;
  border-color: var(--green);
  color: var(--green);
}

.cell.found-bonus {
  background: #2d2000;
  border-color: var(--gold);
  color: var(--gold);
}

.cell.unfound {
  background: #2a1020;
  border-color: var(--red);
  color: var(--red);
  opacity: 0.7;
}

@keyframes invalidFlash {
  0%, 100% { background: var(--cell-empty); }
  40%       { background: #3a1010; border-color: var(--red); }
}
.cell.invalid { animation: invalidFlash 0.4s ease; }

/* ── Feedback ─────────────────────────────────────────────── */
.feedback-msg {
  position: absolute;
  bottom: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.3s;
}

.feedback-msg.success { color: var(--green); }
.feedback-msg.bonus   { color: var(--gold); }
.feedback-msg.info    { color: var(--text-dim); }

/* ── Hint panel ───────────────────────────────────────────── */
.hint-panel {
  background: var(--surface);
  border: 1px solid var(--cell-border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.78rem;
  color: var(--text-dim);
  text-align: center;
  flex-shrink: 0;
  min-height: 28px;
  transition: opacity 0.3s;
}

.hint-panel strong { color: var(--text); }
.hint-panel.hidden { opacity: 0; pointer-events: none; }

/* ── Countdown ────────────────────────────────────────────── */
.countdown {
  text-align: center;
  font-size: 3rem;
  font-weight: 900;
  color: var(--text-dim);
  flex-shrink: 0;
  line-height: 1;
}

.countdown.hidden { display: none; }

/* ── Word list ─────────────────────────────────────────────── */
.wordlist-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  min-height: 0;
}

.wordlist-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow-y: auto;
  align-content: flex-start;
}

.word-item {
  background: var(--surface2);
  border: 1px solid var(--cell-border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text);
  transition: background 0.2s, color 0.2s;
}

.word-item.found {
  background: #1d4e2a;
  border-color: var(--green);
  color: var(--green);
  text-decoration: line-through;
  opacity: 0.7;
}

/* ── Modals ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop.hidden { display: none; }

.modal-card {
  background: var(--surface);
  border: 1px solid var(--cell-border);
  border-radius: var(--radius);
  padding: 28px 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  font-size: 1.4rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 20px;
  text-align: center;
}

.intro-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.intro-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--text-dim);
  line-height: 1.4;
}

.intro-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.result-grid {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 24px;
}

.result-item {
  text-align: center;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
}

.result-item.highlight { border: 1px solid var(--accent); }

.r-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
}

.r-value {
  font-size: 1.6rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.modal-btns { display: flex; gap: 10px; justify-content: center; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}

.btn-primary:active { opacity: 0.85; }

/* ── Tilbake-lenke i header ───────────────────────────────── */
.logo { display: flex; align-items: center; gap: 6px; }
.logo-back {
  color: var(--text-dim);
  -webkit-text-fill-color: var(--text-dim);
  background: none;
  -webkit-background-clip: initial;
  background-clip: initial;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s, -webkit-text-fill-color 0.15s, background 0.15s;
  text-decoration: none;
  flex-shrink: 0;
}
.logo-back:hover {
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  background: rgba(255,255,255,0.08);
}
.header-player {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255,255,255,0.38);
  letter-spacing: 0.01em;
}


