:root {
  --bg: #0b1220;
  --panel: #131c2e;
  --panel-2: #1a2540;
  --border: #243352;
  --text: #e7ecf5;
  --muted: #8b97b0;
  --accent: #4ea1ff;
  --accent-2: #2b6fdc;
  --good: #36c46a;
  --bad: #ff5c5c;
  --warn: #f0b740;
  --gold: #ffd35a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

#app { max-width: 980px; margin: 0 auto; padding: 16px; padding-bottom: 80px; }

h1, h2, h3 { margin: 0 0 12px; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.muted { color: var(--muted); }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.spacer { flex: 1; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background .12s, transform .04s;
}
.btn:hover:not(:disabled) { background: #243152; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent-2); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent); }
.btn.danger  { background: #5b1e1e; border-color: #8a2c2c; }
.btn.danger:hover:not(:disabled) { background: #7a2727; }
.btn.good    { background: #1d4d2c; border-color: #2a6e3f; }
.btn.good:hover:not(:disabled) { background: #2a6e3f; }
.btn.small   { padding: 6px 10px; min-height: 36px; font-size: 14px; }
.btn.full    { width: 100%; }

input[type=text], input[type=number] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  min-height: 44px;
  width: 100%;
}
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }

select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  min-height: 44px;
}

/* Home */
.home-hero { text-align: center; padding: 24px 0; }
.home-hero h1 { font-size: 32px; }
.home-divider { display: flex; align-items: center; gap: 8px; margin: 16px 0; color: var(--muted); }
.home-divider::before, .home-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Lobby / table */
.game-header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.join-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 22px; letter-spacing: .15em;
  background: var(--panel-2); padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.player-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; position: relative; min-height: 100px;
}
.player-card.you      { border-color: var(--accent); }
.player-card.action   { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255, 211, 90, 0.25); }
.player-card.folded   { opacity: 0.45; }
.player-card.allin    { border-color: var(--warn); }
.player-card.tappable {
  cursor: pointer;
  border-color: var(--good);
  box-shadow: 0 0 0 2px rgba(54, 196, 106, .25);
  animation: pulse-good 1.6s ease-in-out infinite;
}
.player-card.tappable:hover { box-shadow: 0 0 0 3px rgba(54, 196, 106, .55); }
.player-card.tappable::after {
  content: 'Tap to award';
  position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%);
  background: var(--good); color: #04210e;
  padding: 2px 10px; border-radius: 12px;
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  white-space: nowrap;
}
@keyframes pulse-good {
  0%, 100% { box-shadow: 0 0 0 2px rgba(54, 196, 106, .25); }
  50%      { box-shadow: 0 0 0 4px rgba(54, 196, 106, .45); }
}

.award-banner {
  background: linear-gradient(180deg, #1d4d2c 0%, #133720 100%);
  border: 1px solid var(--good); border-radius: 12px;
  padding: 12px 16px; margin-bottom: 12px;
  text-align: center;
}
.award-banner .what { font-size: 13px; color: rgba(255,255,255,.75); text-transform: uppercase; letter-spacing: .08em; }
.award-banner .which {
  font-size: 20px; font-weight: 800; color: #fff; margin-top: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.player-card .name    { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.player-card .budget  { font-size: 18px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.player-card .bet     { color: var(--gold); font-size: 13px; margin-top: 4px; }
.player-card .badges  { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.badge {
  font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px;
  background: var(--panel); border: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: .05em;
}
.badge.btn-d { background: #463a1a; border-color: #6e5b22; color: var(--gold); }
.badge.sb    { background: #2b3a4a; }
.badge.bb    { background: #2b3a4a; }
.badge.fold  { background: #4a2929; color: #ff8b8b; }
.badge.allin { background: #4a3b1f; color: var(--warn); }
.badge.adm   { background: #2c3f63; }

/* Felt — the “poker table” centerpiece */
.felt {
  position: relative;
  margin: 0 0 14px;
  padding: 22px 18px 18px;
  border-radius: 220px / 110px;
  border: 10px solid #3a2412;
  background:
    radial-gradient(ellipse at 50% 40%, #2c7a4a 0%, #1d5933 55%, #0d3a20 100%),
    #0d3a20;
  box-shadow:
    inset 0 0 80px rgba(0,0,0,.45),
    inset 0 0 0 2px rgba(0,0,0,.5),
    0 12px 40px rgba(0,0,0,.55);
  text-align: center;
  overflow: hidden;
}
.felt::before {
  /* subtle felt grain */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 4px 4px;
  border-radius: inherit;
  mix-blend-mode: overlay;
}
.felt-image {
  display: block; margin: 0 auto 14px;
  max-width: min(86%, 540px);
  max-height: 170px;
  border-radius: 8px;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,.55));
}
.felt-image-placeholder {
  display: block; margin: 0 auto 14px;
  width: min(86%, 540px); height: 120px;
  border: 2px dashed rgba(255,255,255,.15);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,.4); font-size: 13px;
}
.felt-pot {
  display: inline-block;
  background: rgba(0,0,0,.45);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 30px;
  padding: 8px 24px;
  font: 700 26px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--gold);
  letter-spacing: .03em;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}

/* Chip stacks — purely decorative, scale with the pot. */
.chip-stacks {
  display: flex; justify-content: center; align-items: flex-end;
  gap: 6px; margin: 6px auto 4px; min-height: 56px;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.45));
}
.chip-col { position: relative; width: 32px; height: 56px; }
.chip {
  position: absolute; left: 0; right: 0; height: 10px;
  border-radius: 5px / 6px;
  border: 1px solid rgba(0,0,0,.45);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25), inset 0 -1px 0 rgba(0,0,0,.35);
}
.chip-black { background: linear-gradient(#373737, #0e0e0e); }
.chip-green { background: linear-gradient(#3da966, #1f6c40); }
.chip-red   { background: linear-gradient(#e84a4a, #952425); }
.chip-white { background: linear-gradient(#fafafa, #c8c8c8); }
.felt-pot .label { font-size: 11px; color: rgba(255,255,255,.55); margin-right: 8px; letter-spacing: .15em; }
.felt-meta {
  margin-top: 10px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px;
  font-size: 13px; color: rgba(255,255,255,.85);
}
.felt-meta strong { color: #fff; }
.felt-action {
  background: var(--gold); color: #1a1300;
  padding: 4px 12px; border-radius: 20px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .08em; font-size: 11px;
}

/* Image picker grid */
.image-picker {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.image-picker .pick {
  position: relative; border: 2px solid var(--border); border-radius: 8px;
  overflow: hidden; cursor: pointer; aspect-ratio: 2 / 1; background: #000;
  transition: border-color .12s, transform .04s;
}
.image-picker .pick:hover { border-color: var(--accent); }
.image-picker .pick.selected { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255,211,90,.35); }
.image-picker .pick img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-picker .pick .lbl {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 6px;
  font-size: 11px; background: linear-gradient(to top, rgba(0,0,0,.85), transparent);
  color: #fff; text-shadow: 0 1px 2px #000;
}
.image-picker .pick.none { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }

.table-info {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin-bottom: 12px;
}
.info-tile {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; text-align: center;
}
.info-tile .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.info-tile .value { font-size: 22px; font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; margin-top: 4px; }
.info-tile.action-on { border-color: var(--gold); }
.info-tile.action-on .value { color: var(--gold); font-family: inherit; font-size: 18px; }

/* Action panel */
.action-panel {
  position: sticky; bottom: 0;
  background: var(--panel); border-top: 2px solid var(--accent);
  margin: 12px -16px -16px; padding: 14px 16px;
}
.action-panel.idle { border-top-color: var(--border); }
.pending-bet {
  font-size: 28px; font-weight: 700; text-align: center; padding: 10px;
  background: var(--panel-2); border-radius: 10px; margin-bottom: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.quick-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.act-row   { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.act-row.three { grid-template-columns: repeat(3, 1fr); }

/* Log */
.log {
  max-height: 180px; overflow-y: auto; font-size: 13px; color: var(--muted);
  background: var(--panel-2); border-radius: 10px; padding: 10px;
}
.log .row-line { padding: 2px 0; }
.log .name { color: var(--text); font-weight: 600; }

/* Admin drawer */
.admin-drawer summary {
  cursor: pointer; padding: 8px; list-style: none; font-weight: 600;
  background: var(--panel-2); border-radius: 8px; border: 1px solid var(--border);
}
.admin-drawer[open] summary { margin-bottom: 8px; }
.admin-grid {
  display: grid; grid-template-columns: 1fr; gap: 10px;
}
.admin-row {
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px;
  align-items: center; padding: 8px; background: var(--panel-2);
  border-radius: 8px; border: 1px solid var(--border);
}
.admin-row .who { font-weight: 600; }
.admin-row input[type=number] { width: 110px; }

/* Pots / showdown */
.pot-row {
  display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 8px; align-items: center;
  padding: 10px; background: var(--panel-2); border-radius: 10px;
  border: 1px solid var(--border); margin-bottom: 8px;
}
.pot-row .pot-amount { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; }

/* Toast */
.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--accent);
  color: var(--text); padding: 10px 16px; border-radius: 10px;
  z-index: 100; max-width: 90%; text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.toast.error { border-color: var(--bad); }

/* Modal — modal itself scrolls; body locks so iOS doesn't scroll the page underneath. */
body.modal-open { overflow: hidden; touch-action: none; }
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 50;
  display: flex; justify-content: center; align-items: center;
  padding: 16px;
  overscroll-behavior: contain;
}
.modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
  max-width: 420px; width: 100%;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* Mobile tightening */
@media (max-width: 520px) {
  #app { padding: 10px; padding-bottom: 80px; }
  h1 { font-size: 20px; }
  .player-card .budget { font-size: 16px; }
  .info-tile .value { font-size: 18px; }
  .quick-row { grid-template-columns: repeat(4, 1fr); }
}

/* Mobile background image. Fixed via ::before so it's compatible with iOS Safari
   (which has well-known bugs with background-attachment: fixed). */
@media (max-width: 768px) {
  body { background: transparent; }
  body::before {
    content: "";
    position: fixed; inset: 0; z-index: -1;
    background:
      linear-gradient(rgba(11,18,32,0.55), rgba(11,18,32,0.85)),
      url('images/Deep-Dive-BG.jpg') center/cover no-repeat;
  }
}

/* P&L summary */
.pl-table { width: 100%; border-collapse: collapse; }
.pl-table th, .pl-table td { padding: 8px; text-align: left; border-bottom: 1px solid var(--border); }
.pl-table .pos { color: var(--good); }
.pl-table .neg { color: var(--bad); }
