/* ── Design tokens ─────────────────────────────────────────────── */
:root {
  --bg:          #070e1b;
  --surface:     #0c1525;
  --surface2:    #111e33;
  --border:      #1e2d47;
  --accent:      #7c6af7;
  --accent-dim:  rgba(124,106,247,.18);
  --text:        #e8eaf0;
  --muted:       #6b7a99;

  /* Player piece colours */
  --me:          #fbbf24;   /* amber – your pieces  */
  --me-dim:      rgba(251,191,36,.15);
  --opp:         #7c6af7;   /* purple – opponent    */
  --opp-dim:     rgba(124,106,247,.15);
  --win-glow:    rgba(251,191,36,.5);

  /* Board sizing — adapts to screen */
  --cell:        min(40px, calc((100vw - 64px) / 7 - 5px));
  --cell-gap:    5px;

  --radius:      12px;
  --radius-sm:   8px;
  --font:        system-ui, -apple-system, sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── Screens ───────────────────────────────────────────────────── */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px env(safe-area-inset-bottom, 8px);
}
.screen[hidden] { display: none; }

.screen--game {
  padding: 12px 12px env(safe-area-inset-bottom, 8px);
  gap: 10px;
  justify-content: center;
}

.screen--result {
  justify-content: center;
  gap: 20px;
  overflow-y: auto;
}

/* ── Info-modal ────────────────────────────────────────────────── */
.info-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(4, 8, 20, 0.82);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.info-overlay[hidden] { display: none; }

.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.info-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.info-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.btn-icon-close {
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
  transition: color .15s;
}
.btn-icon-close:hover { color: var(--text); }

.info-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.info-list li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.5;
}

.info-list li strong { color: var(--text); }

.info-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
  margin-top: 1px;
}

/* ── Info-trigger (?) ──────────────────────────────────────────── */
.btn-info-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 10px;
  transition: color .15s, border-color .15s;
}
.btn-info-trigger:hover { color: var(--text); border-color: var(--accent); }

/* ── Back link ─────────────────────────────────────────────────── */
.back-link {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 8px;
}
.back-link:hover { color: var(--text); }

/* ── Top bar / Logo ────────────────────────────────────────────── */
.top-bar {
  width: 100%;
  max-width: 420px;
  text-align: center;
  padding: 24px 0 16px;
}

.logo { font-size: 1.6rem; font-weight: 800; letter-spacing: -.5px; color: var(--text); }
.logo span { color: var(--accent); }

.tagline { margin-top: 6px; font-size: .85rem; color: var(--muted); line-height: 1.4; }

/* ── Card ──────────────────────────────────────────────────────── */
.card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Form elements ─────────────────────────────────────────────── */
.field-label {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

.text-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color .18s;
}
.text-input:focus { border-color: var(--accent); }
.text-input::placeholder { color: var(--muted); }

.text-input--code {
  letter-spacing: .25em;
  text-transform: uppercase;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
}

.text-input--link { font-size: .78rem; color: var(--muted); cursor: default; flex: 1; }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-ghost, .btn-small {
  font-family: var(--font);
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn-primary:active, .btn-secondary:active,
.btn-ghost:active,   .btn-small:active { transform: scale(.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  padding: 12px 20px;
  width: 100%;
}
.btn-primary:disabled { opacity: .38; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  padding: 12px 20px;
  width: 100%;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  font-size: .88rem;
  padding: 8px 12px;
  width: 100%;
  text-align: center;
}
.btn-ghost:hover { color: var(--text); }
.btn-share { display: inline-flex; align-items: center; gap: 6px; background: none; border: none; cursor: pointer; font-family: inherit; font-size: .82rem; font-weight: 600; color: var(--muted); padding: 8px 0; transition: color .15s; }
.btn-share:hover { color: var(--text); }
.btn-share svg { flex-shrink: 0; }

.btn-small {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: .78rem;
  padding: 8px 12px;
  white-space: nowrap;
}

/* ── Divider ───────────────────────────────────────────────────── */
.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: .78rem;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ── Error ─────────────────────────────────────────────────────── */
.error-text { color: #f87171; font-size: .85rem; text-align: center; min-height: 1.2em; }

/* ── Lobby ─────────────────────────────────────────────────────── */
.lobby-code-block {
  text-align: center;
  padding: 16px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.btn-del {
  font-size: .85rem;
  padding: 9px 22px;
  margin-top: 6px;
}
.lobby-label {
  font-size: .75rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 6px;
}
.lobby-code { font-size: 3rem; font-weight: 900; letter-spacing: .18em; color: var(--accent); line-height: 1; }

.lobby-link-row { display: flex; gap: 8px; align-items: center; }

.players-row { display: flex; align-items: center; gap: 12px; padding: 16px 0 8px; }
.player-slot { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }

.player-badge {
  font-size: .7rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; padding: 2px 8px; border-radius: 99px;
}
.player-badge--host  { background: rgba(124,106,247,.2); color: var(--accent); }
.player-badge--guest { background: rgba(34,197,94,.15); color: #4ade80; }

.player-name { font-size: 1rem; font-weight: 700; text-align: center; word-break: break-word; }
.player-name--waiting { color: var(--muted); font-style: italic; font-weight: 400; }

.vs-label { font-size: 1.1rem; font-weight: 900; color: var(--accent); flex-shrink: 0; }

.waiting-text { font-size: .82rem; color: var(--muted); text-align: center; padding: 4px 0; }

/* ── Opponent bar ──────────────────────────────────────────────── */
.opp-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: calc(var(--cell) * 7 + var(--cell-gap) * 6 + 24px);
}
.opp-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.opp-name  { font-size: .9rem; font-weight: 700; color: var(--text); }

/* ── Turn indicator ────────────────────────────────────────────── */
.turn-indicator {
  font-size: .95rem;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: 99px;
  text-align: center;
  transition: background .2s, color .2s;
}

.turn-indicator--mine {
  background: var(--me-dim);
  color: var(--me);
}

.turn-indicator--waiting {
  background: var(--surface);
  color: var(--muted);
}

/* ── Board ─────────────────────────────────────────────────────── */
.board {
  display: flex;
  flex-direction: row;
  gap: var(--cell-gap);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

.board-col {
  display: flex;
  flex-direction: column;
  gap: var(--cell-gap);
  background: none;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 4px 2px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.board-col:not(:disabled):hover,
.board-col:not(:disabled):focus-visible {
  background: var(--me-dim);
  border-color: rgba(251,191,36,.25);
  outline: none;
}

.board-col:disabled { cursor: default; }

/* ── Cells ─────────────────────────────────────────────────────── */
.cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--border);
  flex-shrink: 0;
  transition: background .15s, border-color .15s, box-shadow .15s;
}

.cell--me  { background: var(--me);  border-color: var(--me); }
.cell--opp { background: var(--opp); border-color: var(--opp); }

/* Win highlight */
.cell--win {
  box-shadow: 0 0 0 3px var(--win-glow), 0 0 16px var(--win-glow);
  animation: pulse-win 0.8s ease-in-out infinite alternate;
}

@keyframes pulse-win {
  from { box-shadow: 0 0 0 2px var(--win-glow), 0 0 8px  var(--win-glow); }
  to   { box-shadow: 0 0 0 4px var(--win-glow), 0 0 20px var(--win-glow); }
}

/* New piece pop-in */
.cell--new {
  animation: pop-in .25s cubic-bezier(.34,1.56,.64,1);
}

@keyframes pop-in {
  from { transform: scale(0); opacity: .4; }
  to   { transform: scale(1); opacity: 1; }
}

/* ── Game top bar (sound toggle) ───────────────────────────────── */
.game-top-bar {
  width: 100%;
  max-width: calc(var(--cell) * 7 + var(--cell-gap) * 6 + 24px);
  display: flex;
  justify-content: flex-end;
}

.btn-sound {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  padding: 2px 4px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity .15s;
  line-height: 1;
}
.btn-sound:hover  { opacity: 0.9; }
.btn-sound--muted { opacity: 0.30; }

/* ── Leave button ──────────────────────────────────────────────── */
.btn-leave {
  font-size: .78rem;
  padding: 4px 8px;
  height: auto;
  width: auto;
  margin-top: auto;
}

/* ── Result screen ─────────────────────────────────────────────── */
.result-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.result-emoji { font-size: 3.5rem; line-height: 1; }
.result-title { font-size: 1.8rem; font-weight: 900; }

.result-board {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.result-row {
  display: flex;
  gap: 3px;
}

.result-cell {
  width: min(32px, calc((100vw - 80px) / 7 - 3px));
  height: min(32px, calc((100vw - 80px) / 7 - 3px));
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.result-score {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
  text-align: center;
  letter-spacing: .04em;
  min-height: 1.6em;
}

.result-actions {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Invite-seksjon i lobby ────────────────────────────────────── */
.invite-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0 4px;
  border-top: 1px solid var(--border);
}

.invite-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.invite-status {
  font-size: .82rem;
  min-height: 1.2em;
  color: var(--muted);
}
.invite-status--pending  { color: #fbbf24; }
.invite-status--accepted { color: #4ade80; }
.invite-status--error    { color: #f87171; }


/* ── Nettverksbanner ───────────────────────────────────────────── */
.net-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 500;
  padding: 9px 16px;
  text-align: center;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .01em;
  animation: bannerIn .2s ease;
}
.net-banner--offline { background: #ef4444; color: #fff; }
.net-banner--warn    { background: #f59e0b; color: #000; }
.net-banner--ok      { background: #22c55e; color: #fff; }

@keyframes bannerIn {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}

/* ── Game toast ────────────────────────────────────────────────── */
.game-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: .88rem;
  font-weight: 600;
  white-space: nowrap;
  z-index: 400;
  pointer-events: none;
  animation: toastSlideIn .2s ease;
}
.game-toast--warn { border-left-color: #f59e0b; }
.game-toast--err  { border-left-color: #ef4444; }

@keyframes toastSlideIn {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 12px)); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}
