@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Public+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  --felt: #0e3b2e;
  --felt-deep: #082419;
  --felt-line: rgba(244, 239, 225, 0.09);
  --ivory: #f4efe1;
  --ivory-dim: #b9c9be;
  --gold: #c7a24c;
  --gold-bright: #e3c476;
  --red: #c0463a;
  --red-dim: rgba(192, 70, 58, 0.18);
  --teal: #4fa98a;
  --teal-dim: rgba(79, 169, 138, 0.18);
  --radius: 14px;
  --display: 'Fraunces', serif;
  --body: 'Public Sans', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--felt);
  background-image:
    radial-gradient(circle at 15% 0%, rgba(244,239,225,0.05), transparent 45%),
    repeating-linear-gradient(135deg, rgba(0,0,0,0.03) 0px, rgba(0,0,0,0.03) 2px, transparent 2px, transparent 6px);
  color: var(--ivory);
  font-family: var(--body);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--gold); color: var(--felt-deep); }

button {
  font-family: var(--body);
  cursor: pointer;
}

input[type="number"], input[type="text"] {
  font-family: var(--mono);
}

.suit { font-family: var(--display); }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(to bottom, var(--felt-deep), rgba(8,36,25,0.85));
  border-bottom: 1px solid var(--felt-line);
  backdrop-filter: blur(6px);
}

.topbar h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.02em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar h1 .pip { color: var(--gold); font-size: 18px; }

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ivory-dim);
  box-shadow: 0 0 0 rgba(79,169,138,0.5);
}
.live-dot.connected {
  background: var(--teal);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(79,169,138,0.5); }
  70% { box-shadow: 0 0 0 7px rgba(79,169,138,0); }
  100% { box-shadow: 0 0 0 0 rgba(79,169,138,0); }
}

.mult-chip {
  font-family: var(--mono);
  font-size: 13px;
  background: rgba(199,162,76,0.12);
  border: 1px solid rgba(199,162,76,0.4);
  color: var(--gold-bright);
  padding: 5px 10px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.mult-chip button {
  background: none;
  border: none;
  color: var(--gold-bright);
  font-family: var(--mono);
  font-size: 12px;
  padding: 0 2px;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 14px 100px;
}

.section-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ivory-dim);
  margin: 22px 4px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--felt-line);
}

/* Add player row */
.add-player-row {
  display: flex;
  gap: 8px;
}
.add-player-row input {
  flex: 1;
  background: var(--felt-deep);
  border: 1px solid var(--felt-line);
  color: var(--ivory);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  font-family: var(--body);
}
.add-player-row input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.btn-gold {
  background: var(--gold);
  color: var(--felt-deep);
  border: none;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 15px;
}
.btn-gold:active { transform: scale(0.97); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--felt-line);
  color: var(--ivory-dim);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
}

/* Player entry card (round input) */
.entry-card {
  background: linear-gradient(160deg, rgba(244,239,225,0.06), rgba(244,239,225,0.02));
  border: 1px solid var(--felt-line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.entry-card .entry-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.entry-card .name {
  flex: 1;
  min-width: 0;
}
.entry-card .name .n {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry-card .name .eff {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--gold-bright);
  margin-top: 2px;
}
.card-value-input {
  width: 58px;
  text-align: center;
  background: var(--felt-deep);
  border: 1px solid var(--felt-line);
  color: var(--ivory);
  padding: 10px 4px;
  border-radius: 10px;
  font-size: 16px;
}
.add-card-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--gold);
  color: var(--felt-deep);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}
.add-card-btn:disabled { opacity: 0.35; }
.remove-x {
  background: none;
  border: none;
  color: var(--ivory-dim);
  font-size: 18px;
  padding: 4px;
  line-height: 1;
}
.hand-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.hand-chips .chip {
  background: rgba(199,162,76,0.14);
  border: 1px solid rgba(199,162,76,0.4);
  color: var(--gold-bright);
  font-family: var(--mono);
  font-size: 13px;
  padding: 5px 6px 5px 10px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.hand-chips .chip button {
  background: none;
  border: none;
  color: var(--gold-bright);
  opacity: 0.7;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
}
.hand-chips .chip-empty {
  font-size: 12px;
  color: var(--ivory-dim);
  font-style: italic;
}

.settle-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--felt-deep) 60%, rgba(8,36,25,0));
  z-index: 20;
}
.settle-bar .btn-gold {
  width: 100%;
  padding: 16px;
  font-size: 16px;
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}
.settle-bar .btn-gold:disabled {
  opacity: 0.4;
}

/* Standing tiles */
.standings-list { display: flex; flex-direction: column; gap: 8px; }
.card-tile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--ivory);
  color: var(--felt-deep);
  border-radius: 10px;
  padding: 12px 14px;
  overflow: hidden;
}
.card-tile.leader { box-shadow: 0 0 0 2px var(--gold) inset; }
.card-tile .pip-corner {
  font-family: var(--display);
  font-size: 13px;
  opacity: 0.55;
  width: 18px;
}
.card-tile .rank {
  font-family: var(--mono);
  font-size: 12px;
  color: rgba(8,36,25,0.45);
  width: 16px;
}
.card-tile .cname {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-tile .cbal {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
}
.card-tile .cbal.pos { color: #1f6e4f; }
.card-tile .cbal.neg { color: var(--red); }
.card-tile .cbal-edit {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  background: none;
  border: none;
  padding: 4px 2px;
  border-bottom: 1px dashed currentColor;
}
.card-tile .cbal-edit.pos { color: #1f6e4f; }
.card-tile .cbal-edit.neg { color: var(--red); }
.card-tile .deact-btn {
  background: none;
  border: none;
  color: rgba(8,36,25,0.4);
  font-size: 13px;
  padding: 4px 6px;
}
.inactive-list { opacity: 0.55; }
.inactive-list .card-tile { background: rgba(244,239,225,0.5); }

.empty-note {
  text-align: center;
  color: var(--ivory-dim);
  font-size: 13px;
  padding: 20px 10px;
  border: 1px dashed var(--felt-line);
  border-radius: var(--radius);
}

/* Tie modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4,18,12,0.75);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--felt-deep);
  border: 1px solid var(--felt-line);
  border-radius: 16px;
  padding: 22px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}
.modal h2 {
  font-family: var(--display);
  margin: 0 0 6px;
  font-size: 20px;
}
.modal p { color: var(--ivory-dim); font-size: 14px; margin: 0 0 16px; }
.tie-candidates {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 18px;
}
.tie-candidates span {
  background: rgba(199,162,76,0.15);
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
}
.spin-result {
  font-family: var(--display);
  font-size: 26px;
  color: var(--gold-bright);
  margin: 10px 0 18px;
  min-height: 32px;
}

/* Round result modal */
.result-flow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 14px 0 18px;
}
.result-flow .who { text-align: center; }
.result-flow .who .lbl { font-size: 11px; color: var(--ivory-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.result-flow .who .name { font-family: var(--display); font-size: 18px; margin-top: 2px; }
.result-flow .arrow { color: var(--gold); font-size: 20px; }
.result-payout {
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 700;
  color: var(--gold-bright);
  text-align: center;
  margin-bottom: 18px;
}
.modal-actions { display: flex; gap: 10px; }
.modal-actions button { flex: 1; }

@media (min-width: 640px) {
  .add-player-row { max-width: 420px; }
}
