/* Balatro-style table: flat felt, cream playing cards, chunky ink borders, hard offset shadows.
   No gradients, no blur, no glow. */
:root {
  color-scheme: dark;
  --felt: #2d5a4c;
  --felt-deep: #244a3e;
  --plank: #1b2f29;
  --ink: #141f1c;
  --cream: #f3e9d2;
  --cream-dim: #d9ccae;
  --text: #f3e9d2;
  --muted: #9fbfaf;
  --line: #14211d;
  --red: #e8503f;
  --blue: #2f9bf0;
  --blue-deep: #1d6db3;
  --gold: #f0c24b;
  --green: #7bd88f;
  --ember: #e8503f;
  --moss: #2f8f46;
  --tide: #2f7fd0;
  --volt: #c98f00;
  --stone: #7d7060;
  --shade: #7a4fc9;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--mono);
  font-weight: 600;
  background: var(--felt);
  color: var(--text);
  line-height: 1.4;
}

button, input, select { font: inherit; }

button {
  border: 2px solid var(--ink);
  background: var(--plank);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 3px 0 var(--ink);
}
button:hover:not(:disabled) { background: #28463d; }
button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
button:disabled { cursor: not-allowed; opacity: 0.45; box-shadow: none; }
button.primary { background: var(--blue); color: #fff; box-shadow: 0 3px 0 var(--blue-deep); border-color: var(--ink); }
button.primary:hover:not(:disabled) { background: #4aa9f4; }
button.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--muted); padding: 0.35rem 0.6rem; font-size: 0.85rem; }
button.ghost:hover:not(:disabled) { color: var(--text); background: var(--felt-deep); }

input, select {
  min-width: 0;
  width: 100%;
  border: 2px solid var(--ink);
  background: var(--plank);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-weight: 600;
}

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link { position: absolute; left: 8px; top: -48px; z-index: 20; background: var(--gold); color: var(--ink); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { top: 8px; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.7rem; line-height: 1.15; text-transform: uppercase; letter-spacing: 0.02em; }
h2 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.06em; }
h2.sub { margin-bottom: 10px; }
.muted { color: var(--muted); font-size: 0.85rem; font-weight: 600; text-transform: none; letter-spacing: 0; }
.eyebrow { color: var(--gold); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 6px; }

/* header */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 10px 24px; background: var(--ink); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--cream); text-decoration: none; font-weight: 800; font-size: 1.1rem; text-transform: uppercase; letter-spacing: 0.04em; }
.brand-mark { color: var(--red); font-size: 1.3rem; }
nav { display: flex; gap: 6px; }
nav a { color: var(--muted); text-decoration: none; padding: 6px 14px; border-radius: 8px; text-transform: uppercase; font-size: 0.85rem; letter-spacing: 0.06em; }
nav a:hover { color: var(--text); }
nav a.active { color: var(--ink); background: var(--gold); }
.header-tools { display: flex; align-items: center; gap: 8px; }
.whoami { color: var(--muted); font-size: 0.82rem; }

.shell { width: min(1240px, calc(100vw - 32px)); margin: 0 auto; padding: 22px 0 48px; display: grid; gap: 16px; }
.view { display: grid; gap: 16px; }
[hidden] { display: none !important; }

/* a bar is a heading row, not a box */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 14px 20px; flex-wrap: wrap; padding-bottom: 10px; border-bottom: 2px solid var(--felt-deep); }

.login { max-width: 600px; margin: 40px auto; display: grid; gap: 14px; }
.join-form { display: grid; gap: 12px; }
.join-status { min-height: 1.2em; color: #ffb3a8; font-size: 0.9rem; }
.field { display: grid; gap: 4px; font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.field.inline { display: flex; align-items: center; gap: 10px; }
.field.inline select { width: auto; }

.deck-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
/* Joining the ladder is the deliberate step after saving, so it reads as its own action. */
.queue { background: var(--green); }
.queue.in { background: transparent; color: var(--cream); border-color: var(--gold); }

/* ---------- playing cards ---------- */
.pcard {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 5 / 7;
  padding: 0;
  text-align: left;
  color: var(--ink);
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 5px 0 var(--ink);
  overflow: hidden;
}
.pcard::before { /* suit colour band along the top edge */
  content: ""; position: absolute; inset: 0 0 auto 0; height: 8px; background: var(--el, var(--stone));
}
.pcard .corner { position: absolute; top: 14px; left: 10px; display: grid; justify-items: center; line-height: 1; color: var(--el); font-weight: 800; }
.pcard .corner b { font-size: 1.5rem; color: var(--ink); }
.pcard .corner i { font-style: normal; font-size: 1.15rem; margin-top: 2px; }
.pcard .art { position: absolute; left: 0; right: 0; top: 28%; text-align: center; font-size: 3.2rem; line-height: 1; color: var(--el); }
.pcard .nm { position: absolute; left: 8px; right: 8px; bottom: 34px; text-align: center; font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.03em; line-height: 1.1; }
.pcard .st { position: absolute; left: 0; right: 0; bottom: 0; padding: 5px 4px; text-align: center; font-size: 0.72rem; background: var(--ink); color: var(--cream); }

button.pcard { cursor: pointer; transition: transform 0.12s; }
button.pcard:hover:not(:disabled), button.pcard:focus-visible { transform: translateY(-5px) rotate(-1.5deg); background: var(--cream); }
button.pcard[aria-pressed="true"] { transform: translateY(-12px); border-color: var(--gold); box-shadow: 0 5px 0 var(--ink); background: #fbf1c9; }
button.pcard.blocked { opacity: 0.4; }

[data-el="ember"] { --el: var(--ember); } [data-el="moss"] { --el: var(--moss); } [data-el="tide"] { --el: var(--tide); }
[data-el="volt"] { --el: var(--volt); } [data-el="stone"] { --el: var(--stone); } [data-el="shade"] { --el: var(--shade); }

/* hand */
.slots { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; padding: 14px 0 6px; }
.slot { display: grid; gap: 8px; align-content: start; min-width: 0; }
.slot .pcard { max-width: 210px; margin: 0 auto; }
.slot-empty {
  width: 100%; max-width: 210px; margin: 0 auto; aspect-ratio: 5 / 7; border: 3px dashed var(--felt-deep); border-radius: 12px;
  display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 0.82rem; padding: 10px;
}
.slot-tools { display: flex; justify-content: space-between; align-items: center; gap: 6px; max-width: 210px; width: 100%; margin: 0 auto; }

/* collection */
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button { padding: 0.25rem 0.7rem; font-size: 0.8rem; box-shadow: none; background: var(--felt-deep); }
.filters button[aria-pressed="true"] { background: var(--gold); color: var(--ink); }
/* Joker description, pinned to the pointer rather than to a bar above the shelf, so it is
   readable no matter how far down the grid you are. JS places it in viewport coordinates. */
.tip {
  position: fixed; z-index: 60; max-width: min(300px, calc(100vw - 16px));
  padding: 8px 12px; background: var(--ink); border: 2px solid var(--gold); border-radius: 8px;
  font-size: 0.82rem; color: var(--cream-dim); box-shadow: 0 6px 18px rgb(0 0 0 / 0.45);
  pointer-events: none; /* never let the tip swallow the hover that spawned it */
}
.tip[hidden] { display: none; }
.tip b { color: var(--gold); }
.tip .el { font-weight: 800; }
.shelf-hint { font-size: 0.82rem; margin: 0 0 4px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 18px 14px; padding: 12px 6px 8px; }
.card-grid .pcard { max-width: 170px; }
.card-grid .pcard .art { font-size: 2.4rem; top: 30%; }
.card-grid .pcard .nm { font-size: 0.8rem; bottom: 30px; }
.card-grid .pcard .corner b { font-size: 1.25rem; }

/* jokers */

/* ---------- ladder ---------- */
.cycle-info { text-align: right; display: grid; gap: 2px; }
/* The countdown is the page's clock, so it is set large. Tabular figures stop the digits
   shifting width as it ticks. */
#cycleInfo {
  font-size: clamp(2.25rem, 7vw, 3.5rem); font-weight: 800; color: var(--gold);
  line-height: 1; letter-spacing: -0.01em; font-variant-numeric: tabular-nums;
}
#cycleInfo.live { color: var(--green); }
.score-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; align-items: start; }
.king-card { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px; padding: 10px 14px; background: var(--gold); color: var(--ink); border: 3px solid var(--ink); border-radius: 10px; box-shadow: 0 4px 0 var(--ink); }
.king-card .eyebrow { color: var(--ink); margin: 0; }
.king-card strong { font-size: 1.4rem; text-transform: uppercase; }
.king-card .muted { color: #4a3b0a; }
#ladderRows { background: var(--plank); border-radius: 10px; padding: 4px 14px 8px; border: 3px solid var(--ink); }
.lrow { display: grid; grid-template-columns: 56px minmax(0, 1fr) 70px 90px 60px; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 2px solid var(--ink); }
.lrow:last-child { border-bottom: 0; }
.lrow.head { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 8px 0; }
.lrow.me { background: var(--felt-deep); margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.lrow.king { color: var(--gold); }
.lrow small { display: block; color: var(--muted); }
.lrow small.prov { color: #8fd0ff; }
.crown { color: var(--ink); background: var(--gold); border-radius: 4px; padding: 0 6px; font-size: 0.7rem; font-weight: 800; margin-right: 6px; }
.up { color: var(--green); } .down { color: #ff9a8c; }
aside h2 { margin: 0 0 8px; color: var(--gold); }
aside h2:not(:first-child) { margin-top: 22px; }
#roundTeams div, #ticks div { padding: 6px 0; border-bottom: 2px solid var(--felt-deep); font-size: 0.85rem; }
#ticks { color: var(--muted); }

/* ---------- battles ---------- */
.practice { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.battle-layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 28px; align-items: start; }
/* Rows are buttons now (they open a replay), so the button chrome has to be reset. */
.battle {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; width: 100%; text-align: left; margin-bottom: 8px;
  font: inherit; color: inherit; cursor: pointer;
  background: var(--plank); border: 2px solid var(--ink); border-radius: 8px; padding: 8px 10px;
}
.battle:hover:not(:disabled), .battle:focus-visible { border-color: var(--gold); }
.battle:disabled { cursor: default; opacity: 0.65; }
.battle .res { font-weight: 800; }
.battle .res.win { color: var(--green); } .battle .res.loss { color: #ff9a8c; }
.practice-result details { border: 2px solid var(--ink); border-radius: 8px; margin-bottom: 8px; background: var(--plank); }
.practice-result summary { cursor: pointer; padding: 8px 10px; font-weight: 700; }
.log { padding: 4px 10px 10px; display: grid; gap: 3px; font-size: 0.84rem; }
.score { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.score .chips, .score .fx, .score .total { padding: 1px 7px; border-radius: 4px; font-size: 0.78rem; font-weight: 800; }
.score .chips { background: var(--blue); color: #fff; }
.score .fx { background: var(--red); color: #fff; }
.score .eq { color: var(--muted); }
.score .total { background: var(--cream); color: var(--ink); }
.log .pending { display: none; }
.play-log { justify-self: start; }
.practice-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: baseline; margin-bottom: 8px; }
.deckline { font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30; background: var(--ink); color: var(--cream); border: 2px solid var(--gold); border-radius: 8px; padding: 10px 16px; max-width: min(90vw, 460px); }
.help-dialog { max-width: min(92vw, 580px); border: 3px solid var(--ink); border-radius: 12px; background: var(--felt-deep); color: var(--text); padding: 22px 24px; box-shadow: 0 6px 0 var(--ink); }
.help-dialog::backdrop { background: rgb(10 18 15 / 0.75); }
.help-dialog h2 { margin-bottom: 10px; color: var(--gold); }
.help-dialog ol { padding-left: 20px; line-height: 1.5; font-size: 0.9rem; }
.help-dialog li { margin-bottom: 8px; }
.help-dialog form { margin-top: 14px; }

@media (max-width: 1100px) { .slots { gap: 10px; } .slot .pcard .art { font-size: 2.4rem; } .slot .pcard .nm { font-size: 0.8rem; } }

@media (max-width: 980px) {
  .score-layout, .battle-layout { grid-template-columns: 1fr; }
  .slots { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .app-header { padding: 10px 14px; }
  h1 { font-size: 1.35rem; }
  .slots { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lrow { grid-template-columns: 44px minmax(0, 1fr) 60px 56px; }
  .lrow > :nth-child(4) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  button.pcard:hover:not(:disabled), button.pcard:focus-visible { transform: none; }
}

/* joker lineup and scoring replay */
.plan { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.plan select { min-width: 190px; }
.slot-tools .order { display: inline-flex; gap: 2px; }
.slot-tools .order button { padding: 0.3rem 0.5rem; }
.pcard .corner i, .pcard .art { font-style: normal; }
.card-grid .pcard .st { font-size: 0.64rem; }
.hand-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 0.8rem; }
.hand-table th { text-align: left; color: var(--gold); text-transform: uppercase; font-size: 0.7rem; letter-spacing: 0.06em; }
.hand-table td, .hand-table th { padding: 3px 6px 3px 0; border-bottom: 2px solid var(--ink); }
.plan-tag { background: var(--ink); color: var(--gold); border-radius: 4px; padding: 0 6px; font-size: 0.72rem; margin-left: 4px; }

.log { gap: 8px; }
.rhead, .rrow { display: grid; grid-template-columns: 70px minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: start; }
.rhead { align-items: center; font-size: 0.82rem; }
.rhead .play-log { justify-self: start; padding: 0.25rem 0.4rem; font-size: 0.72rem; }
.rrow { padding-top: 8px; border-top: 2px solid var(--ink); }
.rlabel { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; padding-top: 3px; }
.cell { display: grid; gap: 6px; min-width: 0; }
.cellhead { display: flex; justify-content: space-between; gap: 8px; font-size: 0.82rem; }
.cellhead .dim { color: var(--muted); }
.run { color: var(--gold); font-size: 0.75rem; }
.mini-row { display: flex; gap: 4px; flex-wrap: wrap; }
.mini { display: inline-flex; align-items: center; gap: 1px; min-width: 30px; justify-content: center; padding: 3px 4px; background: var(--cream); color: var(--ink); border: 2px solid var(--ink); border-radius: 5px; font-size: 0.78rem; font-weight: 800; opacity: 0.55; }
.mini i { font-style: normal; }
/* four-colour suits, like Balatro's high-contrast option, so suits read at a glance */
.mini.s-H { color: var(--red); } .mini.s-D { color: #d9772b; } .mini.s-C { color: var(--tide); }
.mini.on { opacity: 1; transform: translateY(-3px); box-shadow: 0 3px 0 var(--ink); }
.steps { display: flex; flex-wrap: wrap; gap: 4px; }
.step { display: inline-flex; align-items: center; gap: 3px; font-size: 0.72rem; }
.slabel { color: var(--cream-dim); }
.hidden-steps { color: var(--cream-dim); font-style: italic; opacity: 0.75; }
.fx { padding: 0 6px; border-radius: 4px; font-weight: 800; color: #fff; }
.fx.chip { background: var(--blue); }
.fx.mult { background: var(--red); }
.fx.x { background: var(--gold); color: var(--ink); }
.score { display: flex; align-items: center; gap: 6px; }
.score .chips, .score .multbox, .score .total { padding: 1px 8px; border-radius: 5px; font-weight: 800; }
.score .chips { background: var(--blue); color: #fff; }
.score .multbox { background: var(--red); color: #fff; }
.score .total { background: var(--cream); color: var(--ink); }
.score .eq { color: var(--muted); }
@media (max-width: 640px) { .rhead, .rrow { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .rlabel, .rhead .play-log { grid-column: 1 / -1; } }

/* joker card text, in Balatro's colours: chips blue, mult red, x mult white on red */
.pcard .nm { font-size: 0.82rem; }
.tx-c { color: #7cc4ff; font-weight: 800; }
.tx-m { color: #ff8a7d; font-weight: 800; }
.tx-x { background: var(--red); color: #fff; padding: 0 5px; border-radius: 4px; font-weight: 800; }
.tip { display: grid; gap: 6px; }
.tip .ins-name { font-size: 0.95rem; }
.ins-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.ins-hint { color: var(--cream-dim); font-style: italic; }
.ins-name { color: var(--cream); font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.04em; }
.ins-text { line-height: 1.45; }
.rarity { background: var(--el); color: #fff; padding: 1px 10px; border-radius: 99px; font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.ins-cost { color: var(--gold); font-weight: 800; }

/* joker art: flat diamond-lattice pattern in the rarity colour, initials on top, optional image */
.pcard .art {
  position: absolute; left: 22%; right: 10%; top: 17%; bottom: 36%; font-size: 1rem; text-align: initial;
  display: grid; place-items: center; overflow: hidden; border: 2px solid var(--ink); border-radius: 6px;
  background-color: var(--el);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath d='M8 1 15 8 8 15 1 8Z' fill='%23ffffff' fill-opacity='.22'/%3E%3C/svg%3E");
  background-size: 16px 16px;
}
.pcard .art .mono { font-style: normal; font-size: 2rem; font-weight: 800; color: #fff; text-shadow: 2px 2px 0 var(--ink); }
.card-grid .pcard .art .mono { font-size: 1.5rem; }
.pcard .art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }
.pcard::after { /* vertical JOKER label, like the playing-card layout */
  content: "JOKER"; position: absolute; left: 4px; top: 38%; writing-mode: vertical-rl; transform: rotate(180deg);
  font-size: 0.6rem; letter-spacing: 0.12em; font-weight: 800; color: var(--el);
}
.slot-empty + .pcard::after { content: none; }

/* joker pictures: the PNG is the whole card face; cost badge and name/rarity strip sit on top */
.pcard .face { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }
.pcard.has-img { aspect-ratio: 142 / 190; background: var(--ink); }
.pcard.has-img::before, .pcard.has-img::after, .pcard.has-img .art { display: none; }
.pcard.has-img .corner { top: 6px; left: auto; right: 6px; padding: 1px 7px; border-radius: 99px; background: var(--ink); }
.pcard.has-img .corner b { font-size: 0.95rem; color: var(--gold); }
.pcard.has-img .nm, .pcard.has-img .st { left: 0; right: 0; background: rgba(0, 0, 0, 0.78); color: #fff; }
.pcard.has-img .nm { bottom: 22px; padding: 3px 4px 2px; font-size: 0.74rem; }
.pcard.has-img .st { padding: 3px 4px; font-size: 0.62rem; background: var(--el, var(--ink)); }


/* budget meter */
.budget { display: flex; align-items: center; gap: 10px; flex: 1 1 220px; max-width: 360px; }
.budget-label { color: var(--gold); text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.08em; }
.budget-bar { flex: 1; height: 12px; background: var(--ink); border-radius: 4px; overflow: hidden; }
.budget-bar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width 0.2s; }
.budget.over .budget-bar i { background: var(--red); }
.budget.over strong { color: #ff9a8c; }

/* Theme music toggle: quiet by default, lit when actually playing. */
.sound.on { color: var(--gold); border-color: var(--gold); }

/* Per-cycle rotation notices: the shelf, the prices and sometimes the plan change each cycle. */
