/* ── 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:      #f43f5e;
  --accent2:     #6c5fff;
  --gold:        #fbbf24;
  --green:       #34d399;
  --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: 8px;
}

/* ── 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;
  text-decoration: none;
}

.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;
}

.icon-btn {
  background: var(--surface2);
  border: none;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:active { transform: scale(0.9); background: var(--surface); }

/* ── Info bar ─────────────────────────────────────────────── */
.info-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.size-btns {
  display: flex;
  gap: 4px;
}

.size-btn {
  background: var(--surface2);
  border: none;
  color: var(--text-dim);
  padding: 5px 11px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.4;
}

.size-btn.active {
  background: var(--accent);
  color: #fff;
}

.size-btn:active { transform: scale(0.93); }

.timer-wrap {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
}

.timer-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#timer {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  min-width: 34px;
  text-align: right;
}

#app-version {
  color: rgba(245, 247, 251, 0.28);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ── Board ────────────────────────────────────────────────── */
#board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
}

#board {
  width: min(100%, calc(100dvh - 148px));
  aspect-ratio: 1 / 1;
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255,255,255,.05);
  touch-action: none;
}

/* ── Tiles ────────────────────────────────────────────────── */
.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.22),
    inset 0 -1px 0 rgba(0,0,0,.2),
    0 2px 6px rgba(0,0,0,.35);
  will-change: left, top;
  z-index: 1;
}

.tile:active {
  filter: brightness(1.15);
}

.tile-num {
  color: rgba(255,255,255,.92);
  font-weight: 900;
  letter-spacing: -0.5px;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0,0,0,.4);
  pointer-events: none;
}

/* ── Empty cell visual ────────────────────────────────────── */
.empty-cell {
  position: absolute;
  background: var(--cell-empty);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.03);
  pointer-events: none;
}

/* ── Feedback overlay ─────────────────────────────────────── */
#feedback {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.4rem;
  font-weight: 800;
  pointer-events: none;
  z-index: 10;
  text-align: center;
  text-shadow: 0 2px 12px rgba(0,0,0,.8);
  opacity: 0;
  white-space: nowrap;
}

#feedback.feedback-anim {
  animation: feedbackFloat 1.2s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.modal-backdrop.show {
  opacity: 1;
  pointer-events: all;
}

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

.modal-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 24px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: modalIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

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

.modal-note {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.35;
  text-align: center;
  margin-top: -8px;
}

.intro-card { max-width: 380px; }

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

.intro-item {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: .9rem;
  line-height: 1.25;
}

.intro-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0d0d1a;
  font-weight: 900;
  background: linear-gradient(135deg, var(--gold), #f97316);
  box-shadow: 0 0 16px rgba(251,191,36,.28);
}

.size-select {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.size-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.size-btns-intro {
  display: flex;
  gap: 8px;
}

.size-choice {
  flex: 1;
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text-dim);
  padding: 10px 6px 8px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.size-choice span {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.size-choice.active {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(124,58,237,.12);
}

.size-choice:active { transform: scale(0.96); }

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

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

.result-item .r-value {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.result-item.highlight .r-value {
  background: linear-gradient(135deg, var(--gold), #f97316);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:active { opacity: 0.85; transform: scale(0.97); }

/* ── Animations ───────────────────────────────────────────── */
@keyframes feedbackFloat {
  0%   { opacity: 0; transform: translate(-50%, -30%); }
  15%  { opacity: 1; transform: translate(-50%, -50%); }
  70%  { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -70%); }
}

@keyframes tileShake {
  0%   { transform: translate(var(--tx), var(--ty)); }
  20%  { transform: translate(calc(var(--tx) - 6px), var(--ty)); }
  40%  { transform: translate(calc(var(--tx) + 6px), var(--ty)); }
  60%  { transform: translate(calc(var(--tx) - 4px), var(--ty)); }
  80%  { transform: translate(calc(var(--tx) + 4px), var(--ty)); }
  100% { transform: translate(var(--tx), var(--ty)); }
}

@keyframes tileWin {
  0%   { transform: translate(var(--tx), var(--ty)) scale(1); }
  35%  { transform: translate(var(--tx), var(--ty)) scale(1.12); filter: brightness(1.3); }
  65%  { transform: translate(var(--tx), var(--ty)) scale(0.96); filter: brightness(1.1); }
  100% { transform: translate(var(--tx), var(--ty)) scale(1); filter: brightness(1); }
}

@keyframes scoreBump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.25); color: var(--gold); }
  100% { transform: scale(1); }
}

@keyframes modalIn {
  from { transform: scale(0.85) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.tile-shake { animation: tileShake 0.32s ease-out; }
.tile-win   { animation: tileWin 0.5s cubic-bezier(0.34,1.56,0.64,1); }
.score-bump { animation: scoreBump 0.3s cubic-bezier(0.34,1.56,0.64,1); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Scrollbar hidden ─────────────────────────────────────── */
::-webkit-scrollbar { display: none; }

/* ── 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;
}


