:root {
  --bg: #0f0d15;
  --panel: #1a1724;
  --panel-2: #231f31;
  --line: #322c45;
  --text: #ece8f6;
  --muted: #9b93b3;
  --accent: #ff3d7f;
  --accent-2: #7c5cff;
  --gold: #ffc94d;
  --good: #3ddc97;
  --bad: #ff6b6b;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Georgia", "Palatino Linotype", "Book Antiqua", "Times New Roman", serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 500px at 10% -10%, rgba(255, 61, 127, .14), transparent 60%),
    radial-gradient(800px 500px at 110% 10%, rgba(124, 92, 255, .12), transparent 60%),
    url("/art/bg-suits.svg");
  background-attachment: fixed, fixed, scroll;
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.4rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 12px; }
.loading { padding: 40px; color: var(--muted); text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .8rem; word-break: break-all; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.gold { color: var(--gold); }
.hidden { display: none !important; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
button:hover:not(:disabled), .btn:hover { border-color: var(--accent-2); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.1); border-color: var(--accent); }
button.good { background: #17382b; border-color: #23604a; color: var(--good); }
button.danger { background: #3a1b22; border-color: #6a2a37; color: var(--bad); }
button.ghost { background: transparent; }
button.sm { padding: 4px 10px; font-size: .85rem; }

input, select {
  font: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card { border-color: rgba(255, 201, 77, .35); box-shadow: 0 20px 60px rgba(0, 0, 0, .45), 0 0 0 1px rgba(255, 61, 127, .12) inset; }
.auth-card .tagline { text-align: center; margin: 0 0 20px; }
.auth-card form { display: grid; gap: 12px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 16px; background: var(--bg); padding: 4px; border-radius: 10px; }
.auth-tabs button { flex: 1; justify-content: center; border: 0; background: transparent; }
.auth-tabs button.active { background: var(--panel-2); }

/* ---------- shell ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.brand .logo { width: 34px; height: 34px; filter: drop-shadow(0 0 8px rgba(255, 61, 127, .45)); transition: transform .4s ease; }
.brand:hover .logo { transform: rotate(30deg); }
.wordmark {
  font-family: var(--display);
  font-weight: 800; font-size: 1.3rem; letter-spacing: .01em; line-height: 1;
  background: linear-gradient(180deg, #fff3c4, var(--gold) 55%, #d8941a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .5));
}
.wordmark em {
  font-style: italic;
  background: linear-gradient(180deg, #ffb3cc, var(--accent) 60%, #c2185b);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand.big { display: flex; justify-content: center; margin: 4px 0 2px; }
.brand.big .wordmark { font-size: 2.1rem; }

/* Sign-in hero: fanned card backs and chips */
.hero { position: relative; height: 128px; margin: -4px auto 6px; width: 220px; }
.hero .hc {
  position: absolute; bottom: 6px; left: 50%; width: 70px; height: 93px; margin-left: -35px;
  transform-origin: 50% 120%; filter: drop-shadow(0 8px 12px rgba(0, 0, 0, .5));
  animation: fan .7s cubic-bezier(.2, .9, .3, 1.2) both;
}
.hero .hc1 { --r: -18deg; }
.hero .hc2 { --r: 18deg; animation-delay: .05s; }
.hero .hc3 { --r: 0deg; animation-delay: .1s; }
.hero .hc { transform: rotate(var(--r)); }
@keyframes fan { from { transform: rotate(0deg) translateY(10px); opacity: 0; } to { transform: rotate(var(--r)); opacity: 1; } }
.hero .hchip { position: absolute; width: 40px; height: 40px; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .5)); }
.hero .hchip1 { left: 18px; bottom: 0; transform: rotate(-20deg); }
.hero .hchip2 { right: 16px; bottom: 4px; width: 46px; height: 46px; transform: rotate(15deg); }
.empty-art { width: 64px; height: 85px; margin-bottom: 10px; opacity: .85; transform: rotate(-6deg); }
.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.top nav { display: flex; gap: 4px; }
.top nav a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); }
.top nav a.active, .top nav a:hover { color: var(--text); background: var(--panel-2); }
.top .who { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip-credits {
  background: linear-gradient(135deg, #3a2a08, #2a1d05);
  border: 1px solid #6b5216; color: var(--gold);
  padding: 4px 12px; border-radius: 999px; font-weight: 600;
}
.chip-credits b { font-size: 1.05rem; }
.chip-credits.bump { animation: bump .5s ease; }
@keyframes bump { 40% { transform: scale(1.12); } }
.uname { color: var(--muted); }
main.view { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
footer.disclaimer { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 16px 24px; }

/* ---------- play ---------- */
.play { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.boxlist { display: grid; gap: 8px; }
.boxlist .section { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 8px 0 0; }
.boxitem {
  display: block; width: 100%; text-align: left; padding: 12px 14px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); white-space: normal;
}
.boxitem.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.boxitem .name { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.boxitem .meta { font-size: .8rem; color: var(--muted); }
.boxitem .bar { margin-top: 8px; }
.empty { padding: 24px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

.badge { font-size: .7rem; font-weight: 700; letter-spacing: .06em; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; }
.badge.live { background: var(--accent); color: #fff; }
.badge.live::before { content: "● "; }
.badge.closed { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.admin { background: #2a2150; color: #b9a8ff; }
.badge.off { background: #3a1b22; color: var(--bad); }

.bar { height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar > div { height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .4s; }

.boxpanel { display: grid; gap: 16px; }
.box-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.box-head .sub { color: var(--muted); margin-top: 4px; }
.stats { display: flex; gap: 20px; flex-wrap: wrap; }
.stat .k { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1.3fr; gap: 16px; align-items: start; }

.tiers { display: grid; gap: 6px; }
.tier { display: grid; grid-template-columns: 80px 1fr auto; gap: 10px; align-items: center; }
.tier .amt { font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
.tier .pips { display: flex; flex-wrap: wrap; gap: 3px; }
.pip { width: 10px; height: 10px; border-radius: 3px; background: var(--gold); }
.pip.gone { background: var(--line); }
.tier .cnt { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.pull-controls { display: grid; gap: 12px; }
.qty { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.qty button.sel { border-color: var(--accent); color: var(--accent); }
.qty input { width: 80px; }
.rip-btn { width: 100%; justify-content: center; padding: 14px; font-size: 1.05rem; }
.cost-line { font-size: .85rem; color: var(--muted); }

.results { margin-top: 14px; }
.results-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.results .summary { font-weight: 600; min-height: 1.5em; }
.results .summary.win { color: var(--gold); }
.tabs { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 8px; perspective: 600px; }

.tab {
  aspect-ratio: 3 / 4; border-radius: 8px; display: grid; place-items: center; position: relative;
  padding: 0; font: inherit; font-weight: 800; overflow: hidden; white-space: normal;
}
/* Face-down tab: a branded Kenzie's Kasino card back. */
.tab.closed {
  background: url("/art/card-back.svg") center / 100% 100% no-repeat;
  border: 0; color: #fff; cursor: pointer;
  box-shadow: 0 3px 0 #5c0a2b, 0 6px 14px rgba(0, 0, 0, .4);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.tab.closed:hover { transform: translateY(-4px) rotate(-1.5deg); filter: brightness(1.08); box-shadow: 0 7px 0 #5c0a2b, 0 12px 20px rgba(0, 0, 0, .45); }
.tab.closed:active { transform: translateY(1px); box-shadow: 0 1px 0 #5c0a2b; }
.tab.closed .pull {
  position: absolute; left: 50%; bottom: 7%; transform: translateX(-50%);
  font-size: .5rem; font-weight: 800; letter-spacing: .12em; white-space: nowrap;
  padding: 2px 6px; border-radius: 999px; background: rgba(20, 6, 16, .72); color: #ffe3ee;
}
.tab.closed.deal { opacity: 0; animation: deal .35s ease forwards; }
@keyframes deal { from { opacity: 0; transform: translateY(-14px) rotate(-6deg) scale(.9); } to { opacity: 1; transform: none; } }

/* Opened tab */
.tab.opened { border: 1px solid var(--line); text-align: center; }
.tab.opened.lose { background: repeating-linear-gradient(135deg, #2b2540 0 6px, #251f37 6px 12px); color: var(--muted); }
.tab.opened.win {
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 250, 225, .95), rgba(255, 233, 160, .55) 38%, transparent 70%),
    repeating-conic-gradient(from 0deg at 50% 42%, #ffd76a 0 9deg, #f5b52a 9deg 18deg);
  color: #3a2600; border-color: #ffe08a; box-shadow: 0 0 16px rgba(255, 201, 77, .5);
}
.tab .face { display: grid; gap: 2px; justify-items: center; }
.tab .face b { font-size: 1.25rem; line-height: 1; }
.tab small { display: block; font-size: .6rem; font-weight: 800; letter-spacing: .08em; }
.tab.tearing { animation: tear .4s ease; }
.tab.tearing.win { animation: tear .4s ease, glow 1.2s ease .4s; }
@keyframes tear {
  0% { transform: rotateX(70deg) scale(.9); opacity: .4; }
  60% { transform: rotateX(-10deg) scale(1.05); opacity: 1; }
  100% { transform: none; }
}
@keyframes glow { 50% { box-shadow: 0 0 28px rgba(255, 201, 77, .9); transform: scale(1.06); } }
/* Free bonus tab: teal card back */
.tab.closed.k-bonus { background-image: url("/art/card-back-bonus.svg"); box-shadow: 0 3px 0 #04362c, 0 6px 14px rgba(0, 0, 0, .4); }
.tab.closed.k-bonus:hover { box-shadow: 0 7px 0 #04362c, 0 12px 20px rgba(0, 0, 0, .45); }
.tab.closed.k-bonus .pull { background: rgba(4, 40, 31, .78); color: #c9fff0; }
/* Last-sale prize: gold card back */
.tab.closed.k-last { background-image: url("/art/card-back-last.svg"); box-shadow: 0 3px 0 #6b4a05, 0 6px 14px rgba(0, 0, 0, .4); }
.tab.closed.k-last:hover { box-shadow: 0 7px 0 #6b4a05, 0 12px 20px rgba(0, 0, 0, .45); }
.tab.closed.k-last .pull { background: rgba(42, 27, 0, .85); color: var(--gold); }
/* Corner ribbon on opened bonus and last-sale cards */
.tab.is-bonus::before, .tab.is-last::before {
  position: absolute; top: 4px; right: 4px; font-size: .5rem; font-weight: 800; letter-spacing: .06em;
  padding: 1px 4px; border-radius: 4px;
}
.tab.is-bonus::before { content: "FREE"; background: #17b897; color: #04281f; }
.tab.is-last::before { content: "FINAL"; background: #3a2600; color: var(--gold); }

/* Prize-board extras */
.extra-art { width: 40px; height: 40px; justify-self: center; }
.extra.bonus.on .extra-art { animation: spin 6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.extra {
  display: grid; grid-template-columns: 80px 1fr; gap: 10px; align-items: center;
  margin-top: 10px; padding: 10px; border-radius: 8px; background: var(--panel-2); font-size: .85rem;
}
.extra .amt { font-weight: 800; font-variant-numeric: tabular-nums; }
.extra.last .amt { color: var(--gold); }
.extra.bonus .amt { color: #4ff0c8; }
.extra.bonus.on { border: 1px solid #17b897; box-shadow: 0 0 14px rgba(79, 240, 200, .25); }
.bonus-tag { color: #4ff0c8; font-weight: 700; font-size: .8rem; }
.bonus-line { color: #4ff0c8; margin-top: 4px; }

@media (prefers-reduced-motion: reduce) {
  .tab.closed.deal, .tab.tearing, .tab.tearing.win, .hero .hc, .extra.bonus.on .extra-art { animation: none; opacity: 1; }
}

.feed { display: grid; gap: 6px; max-height: 360px; overflow: auto; }
.feed-row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--panel-2); font-size: .9rem; }
.feed-row.win { border-left: 3px solid var(--gold); }
.feed-row .when { color: var(--muted); font-size: .78rem; }

.fair p { margin: 6px 0; }
.verify-out { margin-top: 10px; display: grid; gap: 4px; font-size: .9rem; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
td.r, th.r { text-align: right; }
tr.disabled td { opacity: .55; }

/* ---------- admin ---------- */
.subnav { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.subnav a { text-decoration: none; padding: 6px 14px; border-radius: 8px; border: 1px solid var(--line); color: var(--muted); }
.subnav a.active { color: var(--text); border-color: var(--accent-2); background: var(--panel-2); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .k { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .v { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.adjust { display: flex; gap: 6px; flex-wrap: nowrap; align-items: center; }
.adjust input[name=amount] { width: 80px; }
.adjust input[name=note] { width: 150px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; }
.tier-editor { display: grid; gap: 8px; }
.tier-editor .tier-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.design-sum { display: flex; gap: 20px; flex-wrap: wrap; padding: 12px; background: var(--bg); border-radius: 10px; }
.warn { color: var(--gold); font-size: .85rem; }
.err { color: var(--bad); font-size: .85rem; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }

/* ---------- toasts & dialog ---------- */
#toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--accent-2); padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: slide .2s ease; }
.toast.error { border-left-color: var(--bad); }
.toast.success { border-left-color: var(--good); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog form { display: grid; gap: 12px; }

@media (max-width: 900px) {
  .play, .grid2, .split { grid-template-columns: 1fr; }
  .boxlist { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}
@media (max-width: 560px) {
  .top { padding: 10px 16px; }
  .top .who { margin-left: 0; width: 100%; }
  .tier { grid-template-columns: 60px 1fr auto; }
  .adjust { flex-wrap: wrap; }
}

/* ---------- Climb the ladder ---------- */
.tab.opened.ladder {
  background: radial-gradient(circle at 50% 40%, #c4a5ff, #7c3aed 55%, #3b0f80);
  color: var(--gold); border-color: #c4a5ff; box-shadow: 0 0 16px rgba(167, 139, 250, .6);
}
.tab .ladder-icon { width: 24px; height: 28px; }
.extra.ladder { border: 1px solid #7c3aed; }
.ladder-tag { color: #c4a5ff; font-weight: 700; font-size: .8rem; }
.ladder-game {
  display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: start;
  margin-top: 14px; padding: 14px; border-radius: 10px;
  background: linear-gradient(160deg, #2a1650, #1a1230); border: 1px solid #7c3aed;
  box-shadow: 0 0 18px rgba(124, 58, 237, .3);
}
.ladder-game h4 { margin: 0 0 6px; display: flex; align-items: center; gap: 8px; font-family: var(--display); font-size: 1.15rem; color: #e9ddff; }
.ladder-chip { width: 30px; height: 30px; }
.ladder-game.open .ladder-chip { animation: spin 6s linear infinite; }
.ladder-game.climbing .ladder-chip { animation: spin .5s linear infinite; }
.ladder-game.climbing .rungs li.here { animation: climb .7s ease infinite; }
@keyframes climb { 50% { transform: translateY(-4px); } }
.ladder-game.fell { border-color: var(--line); box-shadow: none; opacity: .85; }
.ladder-game.collected { border-color: var(--gold); box-shadow: 0 0 18px rgba(255, 201, 77, .3); }
.rungs { list-style: none; margin: 0; padding: 0 6px; display: grid; gap: 4px; min-width: 120px; border-left: 3px solid #7c3aed; border-right: 3px solid #7c3aed; }
.rungs li {
  display: grid; grid-template-columns: 18px 1fr auto; gap: 6px; align-items: center;
  padding: 3px 8px; border-radius: 6px; font-size: .85rem; font-variant-numeric: tabular-nums; background: rgba(255, 255, 255, .04);
}
.rungs .n { color: var(--muted); font-size: .7rem; }
.rungs .v { font-weight: 700; }
.rungs .me { font-size: .62rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 1px 5px; border-radius: 4px; }
.rungs li.above .v { color: #c4a5ff; }
.rungs li.below { opacity: .45; }
.rungs li.here { background: #7c3aed; color: #fff; }
.rungs li.here .me { background: #fff; color: #3b0f80; }
.rungs li.won { background: var(--gold); color: #3a2600; }
.rungs li.won .me { background: #3a2600; color: var(--gold); }
.rungs li.slip { background: rgba(255, 107, 107, .2); color: var(--bad); }
.rungs li.slip .me { background: var(--bad); color: #2a0000; }
@media (max-width: 520px) { .ladder-game { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) {
  .ladder-game.open .ladder-chip, .ladder-game.climbing .ladder-chip, .ladder-game.climbing .rungs li.here { animation: none; }
}
