/* ============================================================
   Jungle Run — Chicken Road-style tile grid game
   Vibrant jungle palette with bright, playful tiles.
   Mobile-first; 5-tile grid per row.
   ============================================================ */

:root {
  --bg0: #0c1a08;
  --bg1: #0f2210;
  --bg2: #163018;
  --ink: #f0ead6;
  --ink-dim: #b0a88a;
  --ink-mute: #706850;
  --line: #1e3818;
  --line-bright: #2a5020;
  --accent: #f5c842;
  --accent-dim: #c49a10;
  --ir: #4ade80;
  --ir-dim: #22c55e;
  --danger: #ef4444;
  --danger-dim: #b91c1c;
  --safe-bg: #166534;
  --safe-border: #4ade80;
  --trap-bg: #7f1d1d;
  --trap-border: #ef4444;
  --tile-bg: #1a3a14;
  --tile-border: #2d5a22;
  --tile-active-bg: #2a4a1a;
  --tile-active-border: #f5c842;
  --gold: #fbbf24;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,0.5);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  touch-action: manipulation;
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #0a1608 0%, #0c1a0a 40%, #101e0c 100%);
}

/* ===== Top bar ===== */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(10,22,8,0.95);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); }
.brand-mark { flex: 0 0 auto; }
.brand-text { font-weight: 800; letter-spacing: 2px; font-size: 15px; color: var(--accent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: transparent; border: 1px solid var(--line-bright);
  color: var(--ink-dim); border-radius: 8px;
  width: 34px; height: 32px; font-size: 14px; cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--accent); }
.demo-badge[hidden] { display: none; }
.demo-badge {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 8px;
  background: linear-gradient(135deg, #22c55e, #16a34a); color: #fff;
  font-size: 10px; font-weight: 800; letter-spacing: 0.1em;
  font-family: var(--mono); animation: demo-pulse 2s ease-in-out infinite;
}
@keyframes demo-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }
.balance-box {
  padding: 6px 10px; border: 1px solid var(--line-bright); border-radius: 8px;
  font-family: var(--mono); font-size: 14px; color: var(--ir); letter-spacing: 0.5px;
}
.balance-box small { color: var(--ink-mute); margin-left: 4px; font-weight: 400; }

/* ===== Session strip ===== */
.session-strip {
  display: flex; gap: 0;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  overflow-x: auto;
  flex-shrink: 0;
}
.ss-cell {
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 6px 12px;
  border-right: 1px solid var(--line);
  white-space: nowrap;
}
.ss-label { font-size: 9px; color: var(--ink-mute); letter-spacing: 1.2px; }
.ss-value { font-family: var(--mono); color: var(--ink); font-size: 13px; margin-top: 1px; }
.ss-verdict { margin-left: auto; border-right: none; border-left: 1px solid var(--line); align-items: flex-end; }

/* ===== Mode picker ===== */
.mode-picker {
  padding: 12px 14px;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.picker-title {
  margin: 0 0 10px; font-size: 13px; font-weight: 700;
  letter-spacing: 1.5px; color: var(--accent);
}
.picker-grid {
  display: flex; gap: 8px; overflow-x: auto;
  padding-bottom: 4px;
}
.picker-card {
  flex: 1; min-width: 70px;
  padding: 10px 6px 8px; border-radius: 12px;
  background: var(--bg2); border: 2px solid var(--line-bright);
  color: var(--ink); cursor: pointer; text-align: center;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.picker-card:hover { border-color: var(--accent-dim); background: rgba(245,200,66,0.05); }
.picker-card.selected {
  border-color: var(--accent); background: rgba(245,200,66,0.1);
  box-shadow: 0 0 14px rgba(245,200,66,0.25);
}
.picker-icon { font-size: 22px; margin-bottom: 4px; }
.picker-name { font-size: 10px; font-weight: 800; letter-spacing: 1.2px; margin-bottom: 6px; color: var(--ink); }
.picker-card.selected .picker-name { color: var(--gold); }
.picker-detail { display: flex; flex-direction: column; gap: 2px; }
.picker-row { display: flex; justify-content: space-between; align-items: center; padding: 0 2px; }
.pk-label { font-size: 9px; color: var(--ink-mute); letter-spacing: 0.5px; }
.pk-val { font-size: 11px; font-weight: 700; font-family: var(--mono); color: var(--ink-dim); }
.pk-val.traps { color: var(--danger); }
.pk-val.max { color: var(--gold); }
.picker-foot {
  margin: 8px 0 0; font-size: 10px; color: var(--ink-mute); text-align: center;
}

/* ===== Main stage: tile grid ===== */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  overflow: hidden;
  position: relative;
}

.grid-viewport {
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--line-bright) transparent;
}

.grid-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0 28px;
}

/* Each row: multiplier label + 5 tiles + row number */
.grid-row {
  display: flex;
  align-items: center;
  gap: 4px;
  transition: opacity 0.3s;
}

.row-mult {
  width: 50px;
  flex-shrink: 0;
  text-align: right;
  padding-right: 6px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-mute);
  transition: color 0.3s, font-size 0.3s;
}
.grid-row.reached .row-mult { color: var(--ir); }
.grid-row.active .row-mult { color: var(--gold); font-size: 13px; }

.row-tiles {
  display: flex;
  gap: 5px;
  flex: 1;
}

/* Row number badge */
.row-num {
  width: 22px;
  flex-shrink: 0;
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-mute);
  font-family: var(--mono);
}
.grid-row.active .row-num { color: var(--gold); }
.grid-row.reached .row-num { color: var(--ir-dim); }

/* ===== TILES ===== */
.tile {
  flex: 1;
  aspect-ratio: 1;
  max-width: 68px;
  border-radius: var(--radius);
  border: 2.5px solid var(--tile-border);
  background: var(--tile-bg);
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  transition: transform 0.15s, border-color 0.25s, background 0.3s, box-shadow 0.3s;
  position: relative;
  overflow: hidden;
}

/* Tile icon */
.tile .tile-icon {
  position: relative;
  z-index: 1;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

/* ---- Unrevealed tile (default): jungle leaf ---- */
.tile {
  background: linear-gradient(160deg, #1e4a16 0%, #163a10 50%, #1a4214 100%);
}

/* ---- Future rows: darker, more muted ---- */
.grid-row.future .tile {
  opacity: 0.45;
  background: linear-gradient(160deg, #142e10 0%, #0f240c 50%, #122a0e 100%);
  border-color: #1a3012;
}

/* ---- Active row: glowing, inviting ---- */
.grid-row.active .tile {
  cursor: pointer;
  border-color: var(--accent);
  background: linear-gradient(160deg, #2a5a1e 0%, #1e4a16 50%, #265218 100%);
  box-shadow:
    0 0 10px rgba(245,200,66,0.25),
    inset 0 0 20px rgba(245,200,66,0.06);
  animation: tile-glow 1.8s ease-in-out infinite;
}
.grid-row.active .tile:hover {
  transform: scale(1.06);
  border-color: #ffe066;
  box-shadow:
    0 0 20px rgba(245,200,66,0.4),
    inset 0 0 30px rgba(245,200,66,0.1);
}
.grid-row.active .tile:active {
  transform: scale(0.94);
}

@keyframes tile-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(245,200,66,0.2), inset 0 0 15px rgba(245,200,66,0.04); }
  50% { box-shadow: 0 0 16px rgba(245,200,66,0.35), inset 0 0 25px rgba(245,200,66,0.08); }
}

/* ---- Reached (past) rows ---- */
.grid-row.reached .tile {
  opacity: 0.7;
  border-color: #1a4a20;
}

/* ---- Revealed SAFE tile ---- */
.tile.revealed.safe {
  background: linear-gradient(145deg, #166534, #14532d);
  border-color: var(--safe-border);
  box-shadow: 0 0 8px rgba(74,222,128,0.25);
  animation: none;
}

/* ---- Revealed TRAP tile ---- */
.tile.revealed.trap {
  background: linear-gradient(145deg, #7f1d1d, #641414);
  border-color: var(--trap-border);
  box-shadow: 0 0 8px rgba(239,68,68,0.25);
  animation: none;
}

/* ---- Player's PICKED safe tile ---- */
.tile.picked.safe {
  border-color: #86efac;
  box-shadow: 0 0 16px rgba(74,222,128,0.5), 0 0 30px rgba(74,222,128,0.2);
  background: linear-gradient(145deg, #1a7a3a, #166534);
}

/* ---- Player's PICKED trap tile ---- */
.tile.picked.trap {
  border-color: #fca5a5;
  box-shadow: 0 0 16px rgba(239,68,68,0.5), 0 0 30px rgba(239,68,68,0.2);
  background: linear-gradient(145deg, #991b1b, #7f1d1d);
  animation: trap-shake 0.5s ease-out;
}

@keyframes trap-shake {
  0%   { transform: translateX(0) scale(1); }
  15%  { transform: translateX(-5px) scale(1.05); }
  30%  { transform: translateX(5px) scale(1.05); }
  45%  { transform: translateX(-4px) scale(1.02); }
  60%  { transform: translateX(3px) scale(1.02); }
  75%  { transform: translateX(-2px) scale(1); }
  100% { transform: translateX(0) scale(1); }
}

/* Tile reveal pop animation */
.tile.reveal-pop {
  animation: reveal-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes reveal-pop {
  0%   { transform: scale(0.8) rotateY(90deg); opacity: 0.5; }
  50%  { transform: scale(1.1) rotateY(0deg); opacity: 1; }
  100% { transform: scale(1) rotateY(0deg); opacity: 1; }
}

/* ===== Tap indicator on active row ===== */
.tap-indicator {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--gold);
  white-space: nowrap;
  animation: tap-bounce 1s ease-in-out infinite;
  pointer-events: none;
  text-shadow: 0 1px 6px rgba(0,0,0,0.8);
  z-index: 5;
}
@keyframes tap-bounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-4px); }
}
.row-tiles { position: relative; }

/* ===== Bet panel ===== */
.bet-panel {
  padding: 10px 14px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg1);
  flex-shrink: 0;
}
.stake-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.stake-btn {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--bg2); border: 1px solid var(--line-bright);
  color: var(--ink); font-size: 20px; font-weight: 600;
  cursor: pointer;
}
.stake-btn:active { background: var(--accent-dim); }
.stake-display {
  display: flex; flex-direction: column; align-items: center; min-width: 64px;
}
.stake-label { font-size: 9px; color: var(--ink-mute); letter-spacing: 1px; }
.stake-value { font-family: var(--mono); font-size: 18px; font-weight: 700; color: var(--accent); }
.stake-chips {
  display: flex; gap: 4px; margin-left: auto;
}
.chip {
  padding: 4px 10px; border-radius: 6px;
  background: var(--bg2); border: 1px solid var(--line-bright);
  color: var(--ink-dim); font-size: 12px; font-family: var(--mono);
  cursor: pointer; font-weight: 600;
}
.chip:active { background: var(--accent-dim); }

.action-row {
  display: flex; gap: 8px;
}
.action {
  flex: 1; padding: 14px; border: none; border-radius: 12px;
  font-size: 16px; font-weight: 800; letter-spacing: 1.5px;
  cursor: pointer; transition: opacity 0.2s, transform 0.1s;
}
.action:active:not(:disabled) { transform: scale(0.97); }
.action:disabled { opacity: 0.3; cursor: not-allowed; }
.action-advance {
  background: linear-gradient(135deg, #f5c842, #d4a017);
  color: #1a1a00;
  box-shadow: 0 4px 12px rgba(245,200,66,0.3);
}
.action-advance.commit {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
}
.action-cashout {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  box-shadow: 0 4px 12px rgba(34,197,94,0.3);
}

.hint-row {
  margin-top: 6px; text-align: center;
  font-size: 11px; color: var(--ink-mute);
}
.hint-row.ok { color: var(--ir); }
.hint-row.error { color: var(--danger); }

/* ===== Drawer ===== */
.drawer {
  position: fixed; top: 0; right: 0;
  width: min(360px, 85vw); height: 100%;
  background: var(--bg0); border-left: 1px solid var(--line);
  z-index: 100; overflow-y: auto;
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px; border-bottom: 1px solid var(--line);
}
.drawer-body { padding: 14px; font-size: 13px; line-height: 1.6; color: var(--ink-dim); }
.drawer-body dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.drawer-body dt { color: var(--ink-mute); font-weight: 600; }
.drawer-body dd { margin: 0; font-family: var(--mono); font-size: 11px; word-break: break-all; color: var(--ink); }
.small { font-size: 11px; color: var(--ink-mute); }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(6px);
}
.modal[hidden] { display: none; }
.modal-card {
  background: linear-gradient(160deg, var(--bg1), #0a1608);
  border: 2px solid var(--line-bright);
  border-radius: 20px; padding: 32px 36px; text-align: center;
  min-width: 280px; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: modal-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modal-pop {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.modal-title { font-size: 28px; font-weight: 900; letter-spacing: 2px; }
.modal-card.hit .modal-title { color: var(--danger); }
.modal-card.port .modal-title { color: var(--ir); }
.modal-sub { margin-top: 8px; font-size: 13px; color: var(--ink-dim); }
.modal-payout {
  margin-top: 14px; font-family: var(--mono); font-size: 24px; font-weight: 700;
}
.modal-card.hit .modal-payout { color: var(--danger); }
.modal-card.port .modal-payout { color: var(--ir); }
.modal-ok {
  margin-top: 20px; padding: 14px 36px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #d4a017);
  color: #1a1a00; font-size: 14px; font-weight: 800;
  letter-spacing: 1px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(245,200,66,0.3);
}
.modal-ok:active { opacity: 0.8; transform: scale(0.97); }

/* ===== Responsive ===== */
@media (max-width: 400px) {
  .tile { border-radius: 10px; font-size: 22px; }
  .row-mult { width: 38px; font-size: 9px; }
  .row-num { width: 16px; font-size: 8px; }
  .picker-card { padding: 8px 4px; }
  .picker-name { font-size: 10px; }
  .grid-container { gap: 4px; }
  .row-tiles { gap: 4px; }
}

@media (min-width: 600px) {
  .grid-viewport { max-width: 500px; }
  .tile { max-width: 84px; font-size: 32px; }
}
