:root {
  --bg: #f6f5fb;
  --card: #ffffff;
  --ink: #1a1530;
  --muted: #6b6580;
  --line: #ece9f5;
  --brand: #5e3bff;
  --brand-2: #7c5cff;
  --win: #1e9d56;
  --lose: #d6324d;
  --pending: #8a8398;
  --boost: #ffb547;
  --shadow: 0 4px 14px rgba(30, 18, 80, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--brand); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar .title { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--pending);
  box-shadow: 0 0 0 0 rgba(30, 157, 86, .6);
}
.dot.live { background: var(--win); animation: pulse 1.6s infinite; }
.dot.stale { background: var(--lose); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(30, 157, 86, .55); }
  70% { box-shadow: 0 0 0 8px rgba(30, 157, 86, 0); }
  100% { box-shadow: 0 0 0 0 rgba(30, 157, 86, 0); }
}
.iconbtn {
  background: var(--bg); border: 0; color: var(--ink);
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 18px; cursor: pointer;
}

.tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 56px; z-index: 9;
}
.tab {
  flex: 1; background: transparent; border: 0;
  padding: 12px 0; font: inherit; color: var(--muted); font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

main { padding: 14px 14px 40px; max-width: 640px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* live tab */
.t-header {
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.t-name { font-weight: 700; font-size: 16px; }
.t-status { color: var(--muted); font-size: 13px; margin-top: 2px; }
.t-updated { color: var(--muted); font-size: 12px; margin-top: 6px; }

.money-card {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  color: #fff;
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.money-card .mc-label { font-size: 12px; opacity: .85; text-transform: uppercase; letter-spacing: .05em; }
.money-card .mc-cells {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-top: 8px;
}
.money-card .mc-val { font-size: 22px; font-weight: 800; margin-top: 2px; }
.money-card .mc-sub { font-size: 12px; opacity: .8; margin-top: 2px; }
.money-card .mc-bar { display: flex; gap: 4px; margin-top: 12px; }
.money-card .mc-bar div { flex: 1; height: 6px; border-radius: 3px; background: rgba(255,255,255,.25); }
.money-card .mc-bar div.winning { background: #b6f5d0; }
.money-card .mc-bar div.losing  { background: #ffc4ce; }
.money-card .mc-bar div.lost    { background: #3a2848; }

.parlays-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.parlay-row {
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.parlay-row .pr-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 6px;
}
.parlay-row .pr-name { font-weight: 700; font-size: 15px; }
.parlay-row .pr-odds { color: var(--brand); font-weight: 700; font-size: 14px; }
.parlay-row .pr-money {
  display: flex; gap: 14px; font-size: 13px; color: var(--muted);
  margin-bottom: 8px;
}
.parlay-row .pr-money strong { color: var(--ink); font-weight: 700; }
.parlay-row .pr-legs { display: flex; gap: 4px; margin-bottom: 8px; }
.parlay-row .pr-legs div {
  flex: 1; height: 5px; border-radius: 3px; background: var(--line);
}
.parlay-row .pr-legs div.winning { background: var(--win); }
.parlay-row .pr-legs div.losing  { background: var(--lose); }
.parlay-row .pr-legs div.lost    { background: #2c1d3a; }
.parlay-row .pr-status-pill {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.parlay-row .pr-leg-detail {
  font-size: 12px; color: var(--muted); display: grid;
  grid-template-columns: 1fr auto; gap: 4px 8px; margin-top: 4px;
}
.parlay-row .pr-leg-detail .lg-status { font-weight: 700; }
.parlay-row .pr-leg-detail .lg-status.winning { color: var(--win); }
.parlay-row .pr-leg-detail .lg-status.losing  { color: var(--lose); }
.parlay-row .pr-leg-detail .lg-status.lost    { color: #2c1d3a; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 8px 4px 6px; }

.bets-list { display: flex; flex-direction: column; gap: 10px; }
.bet-row {
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 12px;
}
.bet-row .pos {
  font-weight: 800; font-size: 18px; text-align: center;
  color: var(--ink);
}
.bet-row .name { font-weight: 700; }
.bet-row .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bet-row .live-detail {
  font-size: 12px; margin-top: 6px; color: var(--ink);
  background: var(--bg); border-radius: 8px; padding: 6px 8px;
  display: inline-block;
}
.bet-row .live-detail .hole-num { font-weight: 800; color: var(--brand); }
.bet-row .live-detail.idle { color: var(--muted); background: transparent; padding: 0; }
.bet-row .targets {
  display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px;
}
.bet-row .targets .tag {
  font-size: 10px; padding: 2px 7px; border-radius: 999px;
  font-weight: 700; letter-spacing: .03em;
}
.status-winning { background: #d8f6e5; color: var(--win); }
.status-losing  { background: #fde0e5; color: var(--lose); }
.status-pending { background: #ecebf3; color: var(--muted); }
.status-lost    { background: #2c1d3a; color: #fff; }

.bet-row.winning { border-left: 4px solid var(--win); }
.bet-row.losing  { border-left: 4px solid var(--lose); }
.bet-row.pending { border-left: 4px solid var(--pending); }
.bet-row.lost    { border-left: 4px solid #2c1d3a; }

.leaderboard-wrap {
  margin-top: 18px;
  background: var(--card);
  border-radius: 14px;
  padding: 6px 14px;
  box-shadow: var(--shadow);
}
.leaderboard-wrap summary {
  padding: 10px 0;
  font-weight: 600;
  cursor: pointer;
}
.leaderboard { display: flex; flex-direction: column; gap: 4px; padding-bottom: 8px; }
.lb-row {
  display: grid; grid-template-columns: 36px 1fr 56px 48px;
  gap: 6px; font-size: 14px; padding: 6px 0;
  border-top: 1px solid var(--line);
}
.lb-row.tracked { font-weight: 700; color: var(--brand); }
.lb-pos { color: var(--muted); }
.lb-score { text-align: right; }
.lb-thru { text-align: right; color: var(--muted); }

/* chat */
.chat-log {
  display: flex; flex-direction: column; gap: 8px;
  min-height: 60vh;
  margin-bottom: 12px;
}
.msg {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.bot  { background: var(--card); box-shadow: var(--shadow); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.user { background: var(--brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.err  { background: #fde0e5; color: var(--lose); align-self: flex-start; }
.chat-form {
  display: flex; gap: 8px;
  position: sticky; bottom: 0;
  padding: 8px 0 calc(env(safe-area-inset-bottom) + 8px);
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}
.chat-form input {
  flex: 1; padding: 12px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card);
  font: inherit; color: var(--ink);
}
.chat-form button {
  background: var(--brand); color: #fff; border: 0;
  padding: 0 18px; border-radius: 999px; font-weight: 700;
}

/* settings */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-weight: 600; font-size: 14px; }
.field input {
  padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font: inherit; color: var(--ink);
}
.field small { color: var(--muted); font-size: 12px; }
.btn-row { display: flex; gap: 8px; margin: 6px 0 20px; }
button.primary {
  background: var(--brand); color: #fff; border: 0;
  padding: 12px 16px; border-radius: 10px; font-weight: 700;
}
button.secondary {
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  padding: 12px 16px; border-radius: 10px; font-weight: 600;
}
.bets-config { list-style: none; padding: 0; margin: 0; }
.bets-config li {
  background: var(--card); padding: 10px 14px; border-radius: 10px;
  margin-bottom: 6px; display: flex; justify-content: space-between;
  box-shadow: var(--shadow);
}
.bets-config .odds { color: var(--brand); font-weight: 700; }

h2 { font-size: 18px; margin: 4px 0 14px; }
h3 { font-size: 15px; margin: 18px 0 8px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0a1f;
    --card: #1a1432;
    --ink: #f3f0ff;
    --muted: #a39bbe;
    --line: #2a2348;
    --shadow: 0 4px 14px rgba(0, 0, 0, .3);
  }
  .status-winning { background: rgba(30, 157, 86, .2); color: #5fd68a; }
  .status-losing  { background: rgba(214, 50, 77, .2); color: #ff7a92; }
  .status-pending { background: rgba(255,255,255,.08); color: var(--muted); }
  .chat-form input { background: var(--card); color: var(--ink); }
  .field input { background: var(--card); color: var(--ink); }
}
