:root {
  --bg: #0a0608;
  --felt: #1a0f14;
  --felt2: #24141c;
  --gold: #f5d07a;
  --gold2: #c9a227;
  --text: #f8f0e6;
  --muted: #a89890;
  --border: rgba(245, 208, 122, 0.16);
  --cash: #34d399;
  --muscle: #f87171;
  --charm: #f472b6;
  --fear: #a78bfa;
  --wild: #fbbf24;
  --heat: #ef4444;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}
.back-link {
  position: fixed; z-index: 60;
  top: max(10px, var(--safe-t)); left: 12px;
  color: rgba(248,240,230,0.75);
  font: 700 12px system-ui; text-decoration: none;
  padding: 8px 12px; border-radius: 999px;
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--border);
}
#app { height: 100%; height: 100dvh; position: relative; }
.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  opacity: 0; pointer-events: none;
  transition: opacity 0.28s ease;
}
.screen.active {
  display: flex; opacity: 1; pointer-events: auto;
}

/* Title */
#screen-title {
  align-items: center; justify-content: center;
  text-align: center; padding: 24px;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(122,31,61,0.4), transparent 55%),
    radial-gradient(ellipse 50% 40% at 80% 100%, rgba(201,162,39,0.1), transparent),
    var(--bg);
}
.vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.55) 100%);
}
.title-inner { position: relative; z-index: 1; max-width: 420px; }
.eyebrow {
  display: inline-block;
  font-size: 11px; font-weight: 700; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--gold);
  border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px;
  background: rgba(245,208,122,0.08);
  margin-bottom: 14px;
}
h1 {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400;
  font-size: clamp(2.8rem, 11vw, 4rem);
}
h1 em {
  font-style: italic;
  background: linear-gradient(135deg, var(--gold), #fff3d0, var(--gold2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lede {
  color: var(--muted); margin: 12px 0 20px;
  font-size: 1.02rem; line-height: 1.5;
}
.lede strong { color: var(--text); }
.title-stats-preview {
  display: flex; justify-content: center; gap: 10px;
  margin-bottom: 22px;
}
.chip {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.2rem;
  border: 1px solid var(--border);
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
}
.chip.cash { background: rgba(52,211,153,0.15); }
.chip.muscle { background: rgba(248,113,113,0.15); }
.chip.charm { background: rgba(244,114,182,0.15); }
.chip.fear { background: rgba(167,139,250,0.15); }

.btn {
  appearance: none; border: none; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: 1rem;
  padding: 16px 20px; border-radius: 14px; min-height: 52px;
  width: 100%; margin-top: 10px;
  transition: transform 0.1s, filter 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold2));
  color: #1a1005;
  box-shadow: 0 10px 28px rgba(201,162,39,0.3);
}
.btn-ghost {
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-sm {
  min-height: 46px; padding: 10px 12px; font-size: 0.88rem;
  width: auto; flex: 1; margin-top: 0;
}
.btn-slam {
  flex: 1.6; margin-top: 0;
  min-height: 52px;
  border: none; border-radius: 14px;
  font-family: inherit; font-weight: 800; font-size: 1.05rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  background: linear-gradient(135deg, #f472b6, #c9a227 55%, #f5d07a);
  color: #1a0a08;
  box-shadow: 0 8px 28px rgba(201,162,39,0.35);
}
.btn-slam:disabled {
  opacity: 0.4; cursor: not-allowed; filter: grayscale(0.4);
}

/* HUD */
.hud {
  flex-shrink: 0;
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; flex-wrap: wrap;
  /* Leave a lane for the fixed ← Games chip */
  padding: calc(8px + var(--safe-t)) 12px 8px 108px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,6,8,0.92);
  z-index: 5;
}
.hud-left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#hud-round { font-weight: 800; font-size: 0.85rem; color: var(--gold); }
#hud-capo { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.hud-right { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  font-size: 12px; font-weight: 700;
  padding: 5px 9px; border-radius: 999px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--muted);
}
.pill b { color: var(--text); }
.pill.heat b { color: #fca5a5; }

/* Table */
.table {
  flex: 1; min-height: 0;
  position: relative;
  margin: 8px 10px;
  border-radius: 20px;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(245,208,122,0.08), transparent 50%),
    linear-gradient(180deg, var(--felt2), var(--felt));
  border: 1px solid var(--border);
  box-shadow: inset 0 0 60px rgba(0,0,0,0.45);
  padding: 12px 12px 10px;
  display: flex; flex-direction: column; gap: 10px;
  overflow: hidden;
}
.lamp {
  position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
  width: 180px; height: 100px;
  background: radial-gradient(ellipse, rgba(245,208,122,0.2), transparent 70%);
  pointer-events: none;
}
.capo-block {
  display: flex; align-items: center; gap: 12px;
  position: relative; z-index: 1;
}
.capo-face {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.6rem;
  background: radial-gradient(circle at 35% 30%, #4a2838, #120a10);
  border: 2px solid rgba(245,208,122,0.4);
  box-shadow: 0 0 24px rgba(122,31,61,0.4);
  flex-shrink: 0;
}
.capo-name {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.25rem;
}
.capo-line {
  font-size: 12px; color: var(--muted); line-height: 1.35;
  margin-top: 2px;
}

.demand-wrap { position: relative; z-index: 1; }
.demand-label {
  font-size: 10px; font-weight: 800; letter-spacing: 0.14em;
  color: var(--gold2); margin-bottom: 6px;
}
.demand-bar {
  height: 12px; border-radius: 999px;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  overflow: hidden;
}
.demand-bar i {
  display: block; height: 100%; width: 40%;
  background: linear-gradient(90deg, #7a1f3d, #f5d07a);
  transition: width 0.4s ease;
}
.demand-num {
  margin-top: 6px; font-size: 1.4rem; font-weight: 800;
}
.demand-num small { font-size: 12px; font-weight: 600; color: var(--muted); }

.offer-zone {
  flex: 1; min-height: 90px;
  border: 1px dashed rgba(245,208,122,0.25);
  border-radius: 14px;
  padding: 8px 10px;
  background: rgba(0,0,0,0.2);
  position: relative; z-index: 1;
}
.offer-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
  color: var(--muted); margin-bottom: 8px; text-transform: uppercase;
}
.offer-slots {
  display: flex; gap: 8px; justify-content: center; min-height: 72px;
  align-items: center;
}
.offer-total {
  text-align: center; margin-top: 6px;
  font-size: 13px; color: var(--muted);
}
.offer-total b {
  color: var(--gold); font-size: 1.2rem; font-weight: 800;
}
#offer-bonus { color: #6ee7b7; font-weight: 700; }

.timer-wrap { position: relative; z-index: 1; }
.timer-bar {
  height: 4px; border-radius: 2px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}
.timer-bar i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, #34d399, #f5d07a, #ef4444);
  transform-origin: left center;
  transition: transform 0.05s linear;
}

/* Hand */
.hand {
  flex-shrink: 0;
  display: flex; gap: 8px; justify-content: center;
  padding: 8px 10px 4px;
  overflow-x: auto;
  min-height: 108px;
  -webkit-overflow-scrolling: touch;
}
.card {
  flex: 0 0 auto;
  width: 72px; height: 96px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.12);
  background: linear-gradient(160deg, #2a1a22, #120a10);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
  position: relative;
}
.card:active { transform: scale(0.95); }
.card.selected {
  transform: translateY(-10px);
  border-color: var(--gold);
  box-shadow: 0 12px 28px rgba(245,208,122,0.25);
}
.card.disabled { opacity: 0.35; pointer-events: none; }
.card .ico { font-size: 1.5rem; line-height: 1; }
.card .val { font-weight: 800; font-size: 1.1rem; }
.card .tag {
  font-size: 9px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
}
.card.type-cash { border-color: rgba(52,211,153,0.45); }
.card.type-muscle { border-color: rgba(248,113,113,0.45); }
.card.type-charm { border-color: rgba(244,114,182,0.45); }
.card.type-fear { border-color: rgba(167,139,250,0.45); }
.card.type-wild { border-color: rgba(251,191,36,0.55); box-shadow: 0 0 16px rgba(251,191,36,0.15); }

.card.mini {
  width: 56px; height: 74px;
  pointer-events: none;
}
.card.mini .ico { font-size: 1.2rem; }
.card.mini .val { font-size: 0.95rem; }

.action-bar {
  flex-shrink: 0;
  display: flex; gap: 8px; align-items: stretch;
  padding: 8px 12px calc(12px + var(--safe-b));
  border-top: 1px solid var(--border);
  background: rgba(10,6,8,0.95);
}

/* Result */
#screen-result {
  align-items: center; justify-content: center;
  text-align: center; padding: 24px;
  background:
    radial-gradient(ellipse 70% 50% at 50% 30%, rgba(122,31,61,0.35), transparent),
    var(--bg);
}
.result-inner { max-width: 400px; width: 100%; }
.result-pills {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  margin: 16px 0 24px;
}
.result-pills span {
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 13px; font-weight: 700;
  background: rgba(255,255,255,0.04);
}
#screen-result .btn { max-width: 320px; margin-left: auto; margin-right: auto; }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(5,3,4,0.8);
  backdrop-filter: blur(8px);
}
.modal.hidden { display: none; }
.modal-card {
  position: relative; width: min(400px, 100%);
  background: #140e12; border: 1px solid var(--border);
  border-radius: 20px; padding: 26px 20px 20px;
}
.modal-x {
  position: absolute; top: 10px; right: 12px;
  border: none; background: transparent; color: var(--muted);
  font-size: 28px; cursor: pointer;
}
.modal-card h2 {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400; font-size: 1.5rem; text-align: center; margin-bottom: 12px;
}
.modal-card ol {
  color: var(--muted); font-size: 0.92rem; line-height: 1.55;
  padding-left: 18px; margin-bottom: 12px; text-align: left;
}
.modal-card strong { color: var(--text); }
.tip {
  font-size: 0.85rem; color: var(--muted); margin-bottom: 16px; line-height: 1.45;
}
.shake { animation: shake 0.35s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.float-fx {
  position: fixed; inset: 0; pointer-events: none; z-index: 40;
}
.float-fx span {
  position: absolute; font-weight: 800; font-size: 1.4rem;
  animation: rise 0.9s ease forwards;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
@keyframes rise {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-60px) scale(1.2); }
}
.flash-win {
  animation: flashWin 0.5s ease;
}
@keyframes flashWin {
  0% { box-shadow: inset 0 0 0 rgba(245,208,122,0); }
  40% { box-shadow: inset 0 0 80px rgba(245,208,122,0.25); }
  100% { box-shadow: inset 0 0 0 rgba(245,208,122,0); }
}
.flash-lose {
  animation: flashLose 0.45s ease;
}
@keyframes flashLose {
  0% { box-shadow: inset 0 0 0 rgba(239,68,68,0); }
  40% { box-shadow: inset 0 0 80px rgba(239,68,68,0.3); }
  100% { box-shadow: inset 0 0 0 rgba(239,68,68,0); }
}
