/* Design tokens + theme palettes live in /css/themes.css (shared site-wide). */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 80% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent 55%),
    var(--bg);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#app { height: 100%; position: relative; }

.screen {
  position: absolute;
  inset: 0;
  padding: calc(var(--safe-top) + 14px) 18px calc(var(--safe-bottom) + 14px);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  animation: fadeIn 0.28s ease both;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------- Buttons ---------------- */

button { font-family: inherit; cursor: pointer; border: none; color: var(--text); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 16px;
  border-radius: 14px;
  width: 100%;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform 0.12s ease, filter 0.15s ease, opacity 0.15s ease;
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.4; box-shadow: none; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--muted);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
}
.btn-ghost:disabled { opacity: 0.35; }
.btn-ghost:active { background: rgba(255,255,255,0.05); }

.btn-icon {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  width: 52px; height: 52px;
  border-radius: 14px;
  font-size: 1.8rem; font-weight: 300; color: #fff;
  flex: 0 0 auto;
  display: grid; place-items: center;
}
.btn-icon:active { transform: scale(0.94); }

/* ---------------- Setup ---------------- */

.setup-wrap { max-width: 560px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

.back-link { align-self: flex-start; color: var(--muted); text-decoration: none; font-size: 0.9rem; font-weight: 600; padding: 4px 2px; }
.back-link:active { color: var(--text); }

.brand { text-align: center; padding: 4px 0; }
.brand-mark { font-size: 3rem; line-height: 1; filter: drop-shadow(0 6px 14px color-mix(in srgb, var(--accent) 50%, transparent)); }
.brand h1 { font-size: 2.6rem; margin: 6px 0 0; letter-spacing: -1px; font-weight: 800;
  background: linear-gradient(135deg, var(--text), var(--accent)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.tagline { color: var(--muted); margin: 2px 0 0; font-size: 0.95rem; }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.card h2 { margin: 0 0 12px; font-size: 1.05rem; display: flex; justify-content: space-between; align-items: baseline; }
.muted { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 10px 2px 0; line-height: 1.4; }

.add-row { display: flex; gap: 10px; }
.add-row input {
  flex: 1; background: rgba(255,255,255,0.06); border: 1px solid var(--card-border);
  color: var(--text); font-size: 1.05rem; padding: 14px; border-radius: 14px; min-width: 0;
}
.add-row input:focus { outline: none; border-color: var(--accent); }
.add-row input:disabled { opacity: 0.5; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  background: color-mix(in srgb, var(--accent) 16%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
  color: var(--text); padding: 8px 12px; border-radius: 999px; font-size: 0.85rem; font-weight: 600;
}
.chip:active { transform: scale(0.95); }

.player-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-row {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--card-border);
  border-radius: 14px; padding: 10px 12px; animation: fadeIn 0.2s ease both;
}
.p-order { width: 26px; height: 26px; flex: 0 0 auto; display: grid; place-items: center;
  background: rgba(255,255,255,0.08); border-radius: 8px; font-size: 0.8rem; color: var(--muted); font-weight: 700; }
.p-name { flex: 1; font-size: 1.05rem; font-weight: 600; }
.p-remove { background: transparent; color: var(--muted); font-size: 1rem; padding: 6px 8px; }

.rounds-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 8px; }
.rounds-value { text-align: center; }
.rounds-value span { font-size: 2.6rem; font-weight: 800; }
.rounds-value small { display: block; color: var(--muted); font-size: 0.8rem; }
.btn-step {
  width: 54px; height: 54px; border-radius: 16px; font-size: 1.8rem; font-weight: 400;
  background: rgba(255,255,255,0.07); border: 1px solid var(--card-border); color: var(--text);
}
.btn-step:active { transform: scale(0.94); background: rgba(255,255,255,0.12); }
input[type=range] { width: 100%; accent-color: var(--accent); height: 30px; }

/* ---------------- Game ---------------- */

#screen-game { justify-content: flex-start; }
.game-top { display: flex; align-items: center; justify-content: space-between; }
.round-pill { font-size: 1rem; color: var(--text); }
.round-pill strong { font-size: 1.15rem; }
.round-pill .dim { color: var(--muted); }

.pot-block { text-align: center; margin: 14px 0 2px; flex: 0 0 auto; }
.pot-value {
  font-size: clamp(4.5rem, 26vw, 8rem); font-weight: 800; line-height: 1; letter-spacing: -3px;
  background: linear-gradient(135deg, var(--text), var(--accent) 75%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 8px 30px color-mix(in srgb, var(--accent) 35%, transparent));
}
.pot-value.pulse { animation: potPulse 0.5s ease; }
@keyframes potPulse { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }

.roller-prompt { text-align: center; font-size: 2.3rem; font-weight: 800; letter-spacing: -0.5px; margin: 0 0 10px; }
.roller-prompt #roller-name { color: var(--accent); }

.leaderboard { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.lb-item { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--card-border);
  border-radius: 12px; padding: 8px 12px; }
.lb-medal { font-size: 1.1rem; }
.lb-name { flex: 1; font-weight: 600; }
.lb-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.lb-empty { text-align: center; color: var(--muted); font-size: 0.9rem; padding: 8px; }

.pad-area { margin-top: auto; }
.pad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.pad-key {
  aspect-ratio: 1 / 1; border-radius: 16px; font-size: 1.7rem; font-weight: 700;
  background: rgba(255,255,255,0.06); border: 1px solid var(--card-border); color: var(--text);
  transition: transform 0.1s ease, background 0.15s ease;
}
.pad-key:active, .pad-key.tapped { transform: scale(0.9); background: color-mix(in srgb, var(--accent) 25%, transparent); }
.pad-key.key-good { background: linear-gradient(135deg, var(--good), var(--good-2)); color: #062; border-color: transparent;
  box-shadow: 0 6px 20px rgba(56,225,154,0.4); animation: goodGlow 1.6s ease-in-out infinite; }
@keyframes goodGlow { 0%,100% { box-shadow: 0 6px 20px rgba(56,225,154,0.35); } 50% { box-shadow: 0 6px 30px rgba(56,225,154,0.7); } }
.pad-key.key-bad { background: rgba(255,93,108,0.16); border-color: rgba(255,93,108,0.55); color: #ffb0b7; }

.pad-actions { display: flex; gap: 10px; margin-top: 12px; }
.btn-doubles {
  aspect-ratio: 1 / 1; border-radius: 16px; font-size: 0.82rem; font-weight: 800; letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--gold), #ff9d3c); color: #3a2400;
  box-shadow: 0 6px 22px rgba(255,210,74,0.4); animation: goldGlow 1.8s ease-in-out infinite;
}
@keyframes goldGlow { 0%,100% { box-shadow: 0 6px 18px rgba(255,210,74,0.35); } 50% { box-shadow: 0 6px 30px rgba(255,157,60,0.7); } }
.btn-doubles:active { transform: scale(0.9); }
.btn-bank {
  flex: 1; padding: 16px; border-radius: 16px; font-size: 1.15rem; font-weight: 800;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 24%, var(--bg-2)), var(--bg-2));
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
}
.btn-bank:active { transform: scale(0.96); background: color-mix(in srgb, var(--accent) 32%, var(--bg-2)); }

/* ---------------- Bank overlay ---------------- */

.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end;
  background: rgba(4,7,15,0); transition: background 0.22s ease; }
.overlay.open { background: rgba(4,7,15,0.6); backdrop-filter: blur(3px); }
.sheet {
  width: 100%; max-height: 88%; background: var(--bg-2); border-top-left-radius: 24px; border-top-right-radius: 24px;
  padding: 8px 18px calc(var(--safe-bottom) + 18px); border-top: 1px solid var(--card-border);
  transform: translateY(100%); transition: transform 0.24s cubic-bezier(0.2,0.8,0.2,1);
  display: flex; flex-direction: column; overflow: hidden;
}
.overlay.open .sheet { transform: translateY(0); }
.sheet::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 3px; background: var(--muted);
  opacity: 0.5; margin: 6px auto 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; }
.sheet-head h2 { margin: 0; font-size: 1.3rem; }
.sheet-pot strong { color: var(--gold); font-size: 1.2rem; }

.bank-list { list-style: none; margin: 12px 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.bank-item {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 12px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--card-border); border-radius: 14px; padding: 12px;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}
.bank-item .check { width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--muted); display: grid; place-items: center; }
.bank-item.selected { background: rgba(56,225,154,0.14); border-color: var(--good); }
.bank-item.selected .check { background: var(--good); border-color: var(--good); }
.bank-item.selected .check::after { content: '✓'; color: #052; font-weight: 900; font-size: 0.9rem; }
.bank-item:active:not(.disabled) { transform: scale(0.98); }
.bank-item.disabled { opacity: 0.45; }
.bank-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bank-name { font-weight: 700; font-size: 1.05rem; }
.bank-sub { font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bank-reason { font-size: 0.85rem; color: var(--muted); text-align: right; white-space: nowrap; }
.bank-reason.ok { color: var(--good); font-weight: 700; }

.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn-ghost, .sheet-actions .btn-primary { width: auto; flex: 1; }

/* ---------------- Event screens ---------------- */

.screen-event { justify-content: center; align-items: center; text-align: center; }
.event-wrap { max-width: 480px; width: 100%; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.event-emoji { font-size: 5rem; animation: pop 0.5s cubic-bezier(0.2,1.4,0.4,1) both; }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
.screen-event h1 { font-size: 2.6rem; margin: 0; font-weight: 800; letter-spacing: -1px; }
.event-sub { color: var(--text); font-size: 1.15rem; margin: 0; line-height: 1.4; }
.event-sub strong { color: var(--bad); }

.event-summary { width: 100%; background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 8px 14px; margin: 6px 0; }
.sum-head, .sum-row { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; padding: 9px 0; align-items: center; }
.sum-head { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid var(--card-border); }
.sum-row { border-bottom: 1px solid rgba(255,255,255,0.05); font-weight: 600; }
.sum-row:last-child { border-bottom: none; }
.sum-row span:first-child { text-align: left; }
.sum-got.pos { color: var(--good); } .sum-got.zero { color: var(--muted); }
.sum-total { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }
.sum-row.winner { color: var(--gold); }
#screen-gameover .sum-row { grid-template-columns: 1fr auto; }

/* ---------------- Effects ---------------- */

.flash { position: fixed; inset: 0; z-index: 15; pointer-events: none; animation: flashFade 0.65s ease-out forwards; }
.flash-gold { background: radial-gradient(circle at 50% 45%, rgba(255,210,74,0.55), transparent 60%); }
.flash-green { background: radial-gradient(circle at 50% 45%, rgba(56,225,154,0.5), transparent 60%); }
@keyframes flashFade { from { opacity: 1; } to { opacity: 0; } }

#confetti { position: fixed; inset: 0; z-index: 30; pointer-events: none; width: 100%; height: 100%; }

.shake { animation: shake 0.5s cubic-bezier(0.36,0.07,0.19,0.97) both; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); } 40%, 60% { transform: translateX(8px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
