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

:root {
  --bg: #070e1b;
  --surface: #0c1525;
  --border: #1a2d4a;
  --accent: #f59e0b;
  --accent2: #fbbf24;
  --gold: #fbbf24;
  --green: #34d399;
  --red: #f87171;
  --text: #e8edf8;
  --muted: #8892aa;
  --felt: #0a3d1f;
  --felt-border: #0f5c2e;
  --felt-inner: #0c4a26;
  --card-bg: #ffffff;
  --card-back: #1a237e;
  --card-radius: 8px;
  --radius: 12px;
  --header-h: 52px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

button { touch-action: manipulation; }

/* ── App shell ─────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: min(100dvh, 900px);
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Header ────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: var(--header-h);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.back-btn {
  color: var(--muted);
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}
.back-btn svg { width: 20px; height: 20px; }

.logo {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logo span { color: var(--accent); }

/* Auth kjører i bakgrunnen, men vi trenger ikke vise navn/knapper i game-headeren */
#userArea { display: none; }

.chips-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.chips-display .label {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1;
}

.chips-display .value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1.2;
}

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

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

.icon-btn:active { background: var(--border); }

/* ── Session delta (under chips i header) ─────────────── */
.session-delta {
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  min-height: 0.7rem;
}
.session-delta.pos { color: #34d399; }
.session-delta.neg { color: #f87171; }

/* ── Table stats (tom bane) ────────────────────────────── */
.table-stats {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  pointer-events: none;
}
.ts-row {
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 14px;
  padding: 12px 20px;
  backdrop-filter: blur(4px);
}
.ts-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.ts-label {
  font-size: 0.58rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.ts-val {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.ts-val.pos { color: #34d399; }
.ts-val.neg { color: #f87171; }
.ts-divider {
  width: 1px;
  height: 30px;
  background: rgba(255,255,255,0.1);
  flex-shrink: 0;
}

/* ── Table / felt ──────────────────────────────────────── */
#table {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: radial-gradient(ellipse at center, var(--felt-inner) 0%, var(--felt) 100%);
  border: 6px solid var(--felt-border);
  border-radius: 24px;
  margin: 10px 12px;
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 12px rgba(0,0,0,0.4), 0 4px 20px rgba(0,0,0,0.5);
}

/* Felt texture overlay */
#table::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 2px,
    rgba(255,255,255,0.012) 2px,
    rgba(255,255,255,0.012) 4px
  );
  pointer-events: none;
}

/* ── Zone labels ───────────────────────────────────────── */
.zone-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.5);
}

.hand-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(0,0,0,0.35);
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 28px;
  text-align: center;
  transition: color 0.2s;
}

.hand-value.bust { color: var(--red); }
.hand-value.blackjack { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); }

/* ── Hand / card row ───────────────────────────────────── */
.hand {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-height: 110px;
  flex-wrap: nowrap;
  overflow: visible;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
  width: 68px;
  height: 98px;
  padding: 0;
  border-radius: var(--card-radius);
  position: relative;
  flex-shrink: 0;
  transform-origin: bottom center;
  box-shadow: 2px 3px 10px rgba(0,0,0,0.5), 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.15s ease;
}

/* Deal-in animation */
@keyframes dealIn {
  from { transform: translateY(-28px) scale(0.82); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

.card.dealing {
  animation: dealIn 0.28s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

/* Flip animation */
@keyframes flipOut {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

@keyframes flipIn {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.card.flip-out { animation: flipOut 0.15s ease-in forwards; }
.card.flip-in  { animation: flipIn 0.15s ease-out forwards; }

/* Face-up card */
.card.face-up {
  background: var(--card-bg);
  border: 1px solid #d0d0d8;
}

/* Card inner border for face cards */
.card.face-up::after {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 4px;
  pointer-events: none;
}

/* Card corners */
.card-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-family: Georgia, 'Times New Roman', serif;
}

.card-corner.tl {
  top: 5px;
  left: 6px;
}

.card-corner.br {
  bottom: 5px;
  right: 6px;
  transform: rotate(180deg);
}

.card-rank {
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1;
}

.card-suit-sm {
  font-size: 0.62rem;
  line-height: 1.1;
}

/* Center suit */
.card-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.1rem;
  line-height: 1;
  pointer-events: none;
}

/* Red suits */
.card.red .card-rank,
.card.red .card-suit-sm,
.card.red .card-center { color: #c0392b; }

/* Black suits */
.card.black .card-rank,
.card.black .card-suit-sm,
.card.black .card-center { color: #111; }

/* Face card label */
.card-face-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
}

.card-face-char {
  font-size: 1.8rem;
  font-family: Georgia, serif;
  font-weight: 700;
  line-height: 1;
}

.card-face-suit {
  font-size: 1rem;
  line-height: 1;
}

/* Card back */
.card.face-down {
  background: var(--card-back);
  border: 1px solid #283593;
  cursor: default;
}

.card.face-down::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 2px solid rgba(255,255,255,0.18);
  border-radius: 4px;
}

.card.face-down::after {
  content: '';
  position: absolute;
  inset: 9px;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.06) 0px, rgba(255,255,255,0.06) 1px, transparent 1px, transparent 6px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,0.06) 0px, rgba(255,255,255,0.06) 1px, transparent 1px, transparent 6px);
  border-radius: 2px;
}

/* ── Result banner ─────────────────────────────────────── */
#result-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  z-index: 10;
  background: rgba(0,0,0,0.85);
  border-radius: 16px;
  padding: 12px 28px;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.12);
  pointer-events: none;
}

#result-text {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

#result-banner.win  #result-text { color: var(--green); }
#result-banner.lose #result-text { color: var(--red); }
#result-banner.push #result-text { color: var(--gold); }
#result-banner.blackjack #result-text {
  background: linear-gradient(135deg, var(--gold), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

@keyframes bannerPop {
  0%   { transform: translate(-50%, -50%) scale(0.7); opacity: 0; }
  60%  { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

#result-banner.show {
  animation: bannerPop 0.32s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

/* ── Bet area ──────────────────────────────────────────── */
#bet-area {
  flex-shrink: 0;
  padding: 10px 16px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bet-label {
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}

.bet-label strong {
  color: var(--gold);
  font-size: 1rem;
}

#chip-btns {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.chip-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 3px solid transparent;
  color: #fff;
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  position: relative;
  letter-spacing: -0.01em;
}

.chip-btn::before {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1px dashed rgba(255,255,255,0.3);
  pointer-events: none;
}

.chip-btn:active {
  transform: scale(0.92);
}

.chip-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

/* 25 — grønn (kasino-standard $25) */
.chip-btn[data-val="25"] {
  background: radial-gradient(circle at 40% 32%, #22c55e, #15803d 70%);
  border-color: #16a34a;
  box-shadow: 0 4px 14px rgba(21,128,61,0.5), inset 0 1px 0 rgba(255,255,255,0.2);
}

/* 50 — rød */
.chip-btn[data-val="50"] {
  background: radial-gradient(circle at 40% 32%, #f87171, #dc2626 70%);
  border-color: #b91c1c;
  box-shadow: 0 4px 14px rgba(220,38,38,0.45), inset 0 1px 0 rgba(255,255,255,0.2);
}

/* 100 — sort/antrasitt */
.chip-btn[data-val="100"] {
  background: radial-gradient(circle at 40% 32%, #475569, #1e293b 70%);
  border-color: #64748b;
  box-shadow: 0 4px 14px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.15);
}

/* 200 — lilla/premium */
.chip-btn[data-val="200"] {
  background: radial-gradient(circle at 40% 32%, #a78bfa, #6d28d9 70%);
  border-color: #7c3aed;
  box-shadow: 0 4px 14px rgba(109,40,217,0.5), inset 0 1px 0 rgba(255,255,255,0.2);
}

#bet-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ── Action area ───────────────────────────────────────── */
#action-area {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px 16px 6px;
  justify-content: center;
}

.action-btn {
  flex: 1;
  height: 52px;
  border-radius: var(--radius);
  border: none;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}

/* Ta kort — grønn: positiv handling */
#hit-btn {
  background: linear-gradient(160deg, #22c55e, #15803d);
  box-shadow: 0 3px 12px rgba(21,128,61,0.45);
}

/* Stå — rød: stopp-handling */
#stand-btn {
  background: linear-gradient(160deg, #f87171, #dc2626);
  box-shadow: 0 3px 12px rgba(220,38,38,0.4);
}

/* Doble — gull: premiumhandling, mørkere tekst for lesbarhet */
#double-btn {
  background: linear-gradient(160deg, #fbbf24, #d97706);
  box-shadow: 0 3px 12px rgba(217,119,6,0.4);
  color: #1a0800;
}

.action-btn:active { transform: scale(0.95); }
.action-btn:disabled { opacity: 0.28; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── Result area ───────────────────────────────────────── */
#result-area {
  flex-shrink: 0;
  padding: 10px 16px 6px;
  display: flex;
  justify-content: center;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn-primary {
  height: 48px;
  padding: 0 28px;
  border-radius: var(--radius);
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(124,58,237,0.4);
  transition: transform 0.1s, box-shadow 0.1s;
  min-width: 120px;
}

.btn-primary:active {
  transform: scale(0.96);
  box-shadow: 0 1px 6px rgba(124,58,237,0.3);
}

.btn-secondary {
  height: 48px;
  padding: 0 20px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-secondary:active { border-color: var(--accent); color: var(--accent); }

/* ── 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;
  backdrop-filter: blur(6px);
}

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

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.modal-card h2 {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 16px;
  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 {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 16px;
  line-height: 1.5;
}

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

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

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

.result-grid {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.result-item {
  flex: 1;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.result-item.highlight {
  border-color: var(--accent);
  background: rgba(124,58,237,0.1);
}

.r-label {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.r-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gold);
}

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

/* ── Chip delta flash ──────────────────────────────────── */
@keyframes chipDelta {
  0%   { opacity: 1; transform: translateY(0); }
  80%  { opacity: 1; transform: translateY(-22px); }
  100% { opacity: 0; transform: translateY(-30px); }
}

.chip-delta {
  position: fixed;
  font-size: 1rem;
  font-weight: 800;
  pointer-events: none;
  animation: chipDelta 0.8s ease-out forwards;
  z-index: 200;
}

.chip-delta.pos { color: var(--green); }
.chip-delta.neg { color: var(--red); }

/* ── Hidden util ───────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Table stats — 4 items (tighter) ──────────────────── */
.ts-row { gap: 10px; padding: 10px 14px; }
.ts-label { font-size: 0.52rem; }
.ts-val   { font-size: 0.9rem; }

/* ── Action area — compact font for 4 buttons ─────────── */
.action-btn { font-size: 0.88rem; }

/* ── Split button (blue) ───────────────────────────────── */
#split-btn {
  background: linear-gradient(160deg, #38bdf8, #0284c7);
  box-shadow: 0 3px 12px rgba(2, 132, 199, 0.4);
  color: #fff;
}
#split-btn:disabled { opacity: 0.28; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── Split layout ──────────────────────────────────────── */
#player-zone {
  display: flex;
  flex-direction: column;
}

#player-zone.is-split {
  flex-direction: row;
  gap: 10px;
  align-items: flex-end;
}

#player-zone.is-split #main-hand-zone,
#player-zone.is-split #split-zone {
  flex: 1;
  min-width: 0;
}

/* Active hand highlight during split */
#main-hand-zone.active-hand,
#split-zone.active-hand {
  outline: 2px solid rgba(251, 191, 36, 0.65);
  border-radius: 10px;
  padding: 4px;
  margin: -4px;
}

/* ── Result banner — two-line support ─────────────────── */
#result-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#result-text2 {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  color: rgba(255,255,255,0.65);
}

/* ── Game-over grid — 2×2 ──────────────────────────────── */
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

