/* ============================================================
   HIGHLOW LADDER — late-night high-limit room.

   Phone first. Everything self-contained: no images, no web fonts,
   no CDNs, no network requests of any kind. Cards are CSS and Unicode.

   Every palette colour in this file comes from the :root block below,
   so a re-skin is a re-declaration of those properties and nothing else.
   ============================================================ */

:root {
  /* ---- house palette ---- */
  --felt-900: #0b2818;
  --felt-700: #14402a;
  --felt-500: #1d5738;
  --rail-900: #1a1210;
  --rail-700: #2b1f1a;
  --gold-500: #d4af37;
  --gold-300: #f0d878;
  --ivory:    #f5f0e1;
  --red-500:  #a8322d;
  --teal-500: #2e6f6a;
  --win-glow: rgba(240, 216, 120, .55);

  /* channel forms so every rgba() below stays themeable */
  --gold-rgb:  212, 175, 55;
  --gold3-rgb: 240, 216, 120;
  --ivory-rgb: 245, 240, 225;
  --red-rgb:   168, 50, 45;
  --teal-rgb:  46, 111, 106;

  /* ---- derived ---- */
  --gold-line:  rgba(var(--gold-rgb), .30);
  --gold-hair:  rgba(var(--gold-rgb), .16);
  --gold-wash:  rgba(var(--gold-rgb), .09);
  --gold-deep:  #a8842a;
  --ivory-dim:  rgba(var(--ivory-rgb), .62);
  /* .52, not .32: this tint carries 8.5-10px microcopy (slot captions, readout
     keys, unlit rungs, the EV line), and at .32 that text sat near 2.8:1 on the
     felt — under WCAG AA, and unreadable under glare. */
  --ivory-faint:rgba(var(--ivory-rgb), .52);
  --pip:        #171012;
  --ink:        rgba(0, 0, 0, .55);

  /* ---- type ---- */
  --serif: Georgia, 'Times New Roman', 'Nimbus Roman', serif;
  --mono:  Consolas, 'SF Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
  --sans:  system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  /* ---- metrics ---- */
  --card-w: clamp(80px, 24vw, 104px);
  --radius: 6px;
  --tap: 44px;
  --flip: 350ms;
}

/* turbo shortens the flip everywhere at once */
html[data-turbo="1"] { --flip: 130ms; }

*, *::before, *::after { box-sizing: border-box; }

/* Several elements below are display:flex, which would otherwise beat the UA's
   [hidden] { display: none } on specificity. The game toggles .hidden a lot. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

/* No double-tap zoom to wait on: this is a tap-fast game and the 300ms delay
   lands squarely between a player's two calls. */
html, body, button { touch-action: manipulation; }

body {
  background: var(--felt-900);
  color: var(--ivory);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }

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

/* ============================================================
   Room shell
   ============================================================ */

.room {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  position: relative;
  /* Fast repeated tapping on the felt would otherwise raise selection handles
     and the copy callout over the cards. The sheets opt back in below. */
  user-select: none;
  -webkit-user-select: none;
}

.rail {
  background:
    linear-gradient(180deg, var(--rail-700), var(--rail-900));
  flex: none;
  position: relative;
  z-index: 2;
}

.rail-top {
  padding: max(6px, env(safe-area-inset-top)) 12px 7px;
  border-bottom: 1px solid var(--gold-line);
  box-shadow: 0 3px 14px rgba(0, 0, 0, .55);
}

.rail-bottom {
  padding: 9px 12px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--gold-line);
  box-shadow: 0 -3px 14px rgba(0, 0, 0, .55);
}

.rail-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* ---- wordmark ---- */

.wordmark {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 17px;
  line-height: 1.1;
  letter-spacing: .16em;
  color: var(--gold-300);
  display: flex;
  align-items: baseline;
  gap: .45em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .6);
}
.wordmark .w2 {
  color: var(--ivory);
  font-size: .82em;
  letter-spacing: .22em;
  opacity: .82;
}

.tools { display: flex; gap: 6px; }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  min-height: var(--tap);
  border: 1px solid var(--gold-line);
  background: rgba(0, 0, 0, .28);
  color: var(--gold-300);
  border-radius: var(--radius);
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: var(--gold-wash); }

/* ---- readouts ---- */

.readouts { margin-top: 5px; }

.readout { display: flex; align-items: baseline; gap: 7px; }
.readout .k {
  font-family: var(--serif);
  font-size: 9.5px;
  letter-spacing: .19em;
  color: var(--ivory-faint);
}
.readout .v {
  font-family: var(--mono);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  color: var(--ivory);
}
.r-pot .v { color: var(--gold-300); }
.r-pot.is-live .v { text-shadow: 0 0 12px var(--win-glow); }

/* ============================================================
   Felt
   ============================================================ */

.felt {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 8px 10px 6px;
  background:
    radial-gradient(120% 76% at 50% 12%, var(--felt-500), var(--felt-700) 54%, var(--felt-900) 100%);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, .5);
}

/* ---- the ladder rail ---- */

.ladder {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: none;
  width: 30px;
  display: flex;
  flex-direction: column-reverse; /* rung 1 at the bottom */
  justify-content: space-between;
  gap: 3px;
}

.ladder li {
  flex: 1 1 0;
  min-height: 0;
  border: 1px solid var(--gold-hair);
  border-radius: 3px;
  background: rgba(0, 0, 0, .22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ivory-faint);
  transition: background var(--flip) ease, color var(--flip) ease,
              box-shadow var(--flip) ease, border-color var(--flip) ease;
}
.ladder li.is-lit {
  background: linear-gradient(180deg, var(--gold-300), var(--gold-deep));
  border-color: var(--gold-300);
  color: var(--rail-900);
  font-weight: 700;
  box-shadow: 0 0 10px var(--win-glow);
}
.ladder li.is-top {
  border-style: dashed;
  border-color: var(--gold-line);
}
.ladder li.is-top.is-lit { border-style: solid; }

/* ---- centre column ---- */

.centre {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.cards {
  display: flex;
  gap: clamp(10px, 4vw, 22px);
  align-items: flex-start;
  justify-content: center;
  padding-top: 4px;
}

.slot { display: flex; flex-direction: column; align-items: center; gap: 5px; }

.slot-cap {
  margin: 0;
  font-family: var(--serif);
  font-size: 9px;
  letter-spacing: .2em;
  color: var(--ivory-faint);
}

/* ---- the card ---- */

.card {
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  max-width: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--flip) cubic-bezier(.3, .7, .35, 1);
  border-radius: 7px;
}
.card[data-face="down"] { transform: rotateY(180deg); }

.cface {
  position: absolute;
  inset: 0;
  border-radius: 7px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  box-shadow: 0 5px 14px rgba(0, 0, 0, .55);
}

.cfront {
  background: linear-gradient(170deg, #fffdf5, var(--ivory) 58%, #e6dfcb);
  border: 1px solid rgba(0, 0, 0, .3);
  color: var(--pip);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cback {
  transform: rotateY(180deg);
  background:
    repeating-linear-gradient(45deg, var(--rail-700) 0 5px, var(--rail-900) 5px 10px);
  border: 1px solid var(--gold-line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold-500);
}
.cb-mark { font-size: 20px; opacity: .55; }

/* card face internals, drawn by ui.js */
.cf-corner {
  position: absolute;
  left: 5px;
  top: 3px;
  font-family: var(--serif);
  font-size: clamp(12px, 3.4vw, 15px);
  line-height: 1.02;
  text-align: center;
  font-weight: 700;
}
.cf-corner.br {
  left: auto; top: auto;
  right: 5px; bottom: 3px;
  transform: rotate(180deg);
}
.cf-corner .cf-suit { display: block; font-size: .86em; font-weight: 400; }
.cf-big {
  font-size: clamp(30px, 9.5vw, 44px);
  line-height: 1;
  opacity: .9;
}
.cf-red { color: var(--red-500); }
.cf-black { color: var(--pip); }

/* result feedback */
.card.is-win .cfront { box-shadow: 0 0 0 2px var(--gold-300), 0 0 22px var(--win-glow); }
.card.is-bust .cfront { box-shadow: 0 0 0 2px var(--red-500), 0 0 20px rgba(var(--red-rgb), .6); }
.slot.is-empty { opacity: .34; }

/* ---- status line ---- */

.status {
  margin: 0;
  min-height: 2.6em;
  text-align: center;
  font-family: var(--serif);
  font-size: 13px;
  line-height: 1.3;
  color: var(--ivory-dim);
  padding: 0 2px;
}
.status b { color: var(--gold-300); font-weight: 400; }
.status .neg { color: #e4a7a2; }

/* ---- deck info ---- */

.deckinfo {
  display: flex;
  gap: 16px;
  align-items: baseline;
  justify-content: center;
}
.di { display: flex; align-items: baseline; gap: 6px; }
.di em {
  font-style: normal;
  font-family: var(--serif);
  font-size: 8.5px;
  letter-spacing: .18em;
  color: var(--ivory-faint);
}
.di b {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 400;
  color: var(--ivory);
  font-variant-numeric: tabular-nums;
}
.di .dim { color: var(--ivory-faint); }

/* ---- counting strip ---- */

.strip {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 2px;
  padding: 5px 2px 3px;
  border-top: 1px solid var(--gold-hair);
}

.st {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  border-radius: 3px;
  padding: 2px 0 1px;
  background: rgba(0, 0, 0, .2);
  transition: opacity 160ms ease, background 160ms ease;
}
.st-r {
  font-family: var(--serif);
  font-size: 10px;
  line-height: 1.1;
  color: var(--ivory-dim);
}
.st-n {
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1.2;
  color: var(--gold-300);
}
.st[data-left="0"] { opacity: .26; }
.st[data-left="0"] .st-n { color: var(--ivory-faint); }
.st.is-ref {
  background: var(--gold-wash);
  box-shadow: inset 0 0 0 1px var(--gold-line);
}
.st.is-ref .st-r { color: var(--gold-300); }

/* ============================================================
   Bottom rail — controls
   ============================================================ */

.pane { display: flex; flex-direction: column; gap: 7px; }
.pane[hidden] { display: none; }

/* ---- chips ---- */

.chiprow { display: flex; gap: 7px; }

.chip {
  flex: 1 1 0;
  min-width: 0;
  height: 46px;
  border-radius: 50% / 36%;
  border: 2px dashed rgba(var(--ivory-rgb), .28);
  background:
    radial-gradient(circle at 50% 42%, var(--rail-700), var(--rail-900));
  color: var(--ivory-dim);
  font-family: var(--mono);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms ease, border-color 120ms ease, color 120ms ease;
}
.chip.is-on {
  border-color: var(--gold-300);
  border-style: solid;
  color: var(--gold-300);
  box-shadow: 0 0 12px rgba(var(--gold-rgb), .3);
  transform: translateY(-1px);
}
.chip:disabled { opacity: .34; }

/* ---- unit multiplier ---- */

.unitrow { display: flex; gap: 6px; align-items: center; }
.unitlabel {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ivory-faint);
  width: 12px;
  text-align: center;
}
.unit {
  flex: 1 1 0;
  min-width: 0;
  height: var(--tap);
  border: 1px solid var(--gold-hair);
  background: rgba(0, 0, 0, .25);
  color: var(--ivory-dim);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 14px;
}
.unit.is-on {
  border-color: var(--gold-300);
  color: var(--gold-300);
  background: var(--gold-wash);
}
.unit:disabled { opacity: .3; }

/* ---- big buttons ---- */

.big {
  position: relative;
  width: 100%;
  min-height: 52px;
  border-radius: var(--radius);
  border: 1px solid var(--gold-line);
  background: linear-gradient(180deg, rgba(var(--gold-rgb), .16), rgba(0, 0, 0, .35));
  color: var(--ivory);
  font-family: var(--serif);
  letter-spacing: .16em;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 12px;
  transition: filter 120ms ease, box-shadow 160ms ease, opacity 160ms ease;
}
.big:active:not(:disabled) { filter: brightness(1.22); }
.big:disabled { opacity: .35; }

.big .bl { font-family: var(--serif); letter-spacing: .17em; }
.big .br,
.big .bm {
  font-family: var(--mono);
  letter-spacing: 0;
  font-size: 15px;
  color: var(--gold-300);
  font-variant-numeric: tabular-nums;
}

.deal {
  border-color: var(--gold-300);
  background: linear-gradient(180deg, rgba(var(--gold-rgb), .3), rgba(var(--gold-rgb), .08));
}
.rebuy { border-color: var(--gold-300); color: var(--gold-300); }

/* ---- call buttons ---- */

.calls { display: flex; gap: 8px; }

.call {
  flex: 1 1 0;
  min-width: 0;
  min-height: 62px;
  flex-direction: column;
  gap: 1px;
  padding: 6px 6px 5px;
}
.call .bl { font-size: 13px; }
.call .bm { font-size: 16px; }

.hi {
  border-color: rgba(var(--red-rgb), .85);
  background: linear-gradient(180deg, rgba(var(--red-rgb), .62), rgba(var(--red-rgb), .2));
}
.lo {
  border-color: rgba(var(--teal-rgb), .85);
  background: linear-gradient(180deg, rgba(var(--teal-rgb), .62), rgba(var(--teal-rgb), .2));
}
.bankbtn {
  min-height: var(--tap);
  flex-wrap: wrap;
  row-gap: 0;
  border-color: var(--gold-300);
  background: linear-gradient(180deg, rgba(var(--gold-rgb), .26), rgba(var(--gold-rgb), .06));
}

/* EV trainer lines */
.bev {
  display: none;
  flex-basis: 100%;
  text-align: center;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0;
  color: var(--ivory-faint);
  font-variant-numeric: tabular-nums;
}
html[data-ev="1"] .bev { display: block; }
html[data-ev="1"] .bankbtn { min-height: 54px; }
html[data-ev="1"] .call { min-height: 74px; }
.big.is-best { box-shadow: 0 0 0 1px var(--gold-300), 0 0 14px rgba(var(--gold-rgb), .34); }
.big.is-best .bev { color: var(--gold-300); }

/* ---- switches ---- */

.switches { display: flex; gap: 7px; margin-top: 7px; }

.tog {
  flex: 1 1 0;
  min-height: var(--tap);
  border: 1px solid var(--gold-hair);
  background: rgba(0, 0, 0, .25);
  color: var(--ivory-faint);
  border-radius: var(--radius);
  font-family: var(--serif);
  font-size: 10.5px;
  letter-spacing: .18em;
}
.tog[aria-pressed="true"] {
  border-color: var(--gold-300);
  color: var(--gold-300);
  background: var(--gold-wash);
}

.promise {
  margin: 7px 0 0;
  text-align: center;
  font-size: 9.5px;
  letter-spacing: .03em;
  color: var(--ivory-faint);
  line-height: 1.3;
}

/* ============================================================
   Sheets (rules / ledger)
   ============================================================ */

.sheet {
  border: none;
  padding: 0;
  background: transparent;
  color: var(--ivory);
  inset: 0;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  /* The rules and the ledger are prose and numbers; they are meant to be
     selected and copied. */
  user-select: text;
  -webkit-user-select: text;
}
.sheet::backdrop { background: rgba(0, 0, 0, .74); }

/* Heading on the left, a real 44px dismiss target on the right. The heading
   takes tabindex="-1" so ui.js can park focus there on open. */
.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.sheet-head h2 { flex: 1 1 auto; min-width: 0; }
.sheet-x { flex: 0 0 auto; font-size: 13px; }

.sheet-in {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, var(--rail-700), var(--rail-900) 30%);
  border-top: 2px solid var(--gold-500);
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}

.sheet h2 {
  margin: 2px 0 14px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 19px;
  letter-spacing: .2em;
  color: var(--gold-300);
}
.sheet h3 {
  margin: 18px 0 5px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 12px;
  letter-spacing: .2em;
  color: var(--gold-500);
  text-transform: uppercase;
}
.sheet p { margin: 0 0 9px; font-size: 13.5px; line-height: 1.55; color: var(--ivory-dim); }
.sheet p b { color: var(--ivory); font-weight: 600; }
.sheet .c-hi { color: #e08a84; }
.sheet .c-lo { color: #74c0ba; }

.formula {
  font-family: var(--mono) !important;
  font-size: 12px !important;
  text-align: center;
  color: var(--gold-300) !important;
  background: rgba(0, 0, 0, .3);
  border: 1px solid var(--gold-hair);
  border-radius: var(--radius);
  padding: 9px 6px;
}

.callout {
  border-left: 2px solid var(--gold-500);
  padding: 8px 0 8px 11px;
  background: var(--gold-wash);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.keys {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 12.5px;
  color: var(--ivory-dim);
}
kbd {
  font-family: var(--mono);
  font-size: 11px;
  border: 1px solid var(--gold-hair);
  background: rgba(0, 0, 0, .35);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--gold-300);
}

.fineprint { font-size: 11.5px !important; color: var(--ivory-faint) !important; margin-top: 14px !important; }

.close { margin-top: 18px; }
.ghost {
  width: 100%;
  min-height: var(--tap);
  margin-top: 14px;
  border: 1px solid rgba(var(--red-rgb), .55);
  background: rgba(var(--red-rgb), .12);
  color: #e4a7a2;
  border-radius: var(--radius);
  font-family: var(--serif);
  font-size: 11px;
  letter-spacing: .17em;
}

/* ---- ledger ---- */

.ledger { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; }
.ledger dt {
  font-family: var(--serif);
  font-size: 10.5px;
  letter-spacing: .15em;
  color: var(--ivory-faint);
  align-self: center;
  text-transform: uppercase;
}
.ledger dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 14px;
  text-align: right;
  color: var(--ivory);
  font-variant-numeric: tabular-nums;
}
.ledger dd.good { color: var(--gold-300); }
.ledger dd.bad { color: #e4a7a2; }

.histo { display: flex; flex-direction: column; gap: 3px; }
.hrow { display: grid; grid-template-columns: 22px 1fr 44px; gap: 7px; align-items: center; }
.hrow .hk { font-family: var(--mono); font-size: 11px; color: var(--ivory-faint); }
.hrow .hb {
  height: 11px;
  border-radius: 2px;
  background: rgba(0, 0, 0, .32);
  overflow: hidden;
}
.hrow .hb i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold-300));
  border-radius: 2px;
}
.hrow .hv { font-family: var(--mono); font-size: 11px; color: var(--ivory-dim); text-align: right; }

/* ============================================================
   Wide / tall screens — the phone layout just gets more air
   ============================================================ */

@media (min-width: 480px) {
  :root { --card-w: 118px; }
  .wordmark { font-size: 20px; }
  .status { font-size: 14px; }
  .ladder { width: 34px; }
  .ladder li { font-size: 11px; }
  .st-r { font-size: 11px; }
  .st-n { font-size: 10px; }
}

@media (min-height: 760px) {
  .cards { padding-top: 12px; }
  .status { min-height: 3.2em; font-size: 14px; }
}

/* Very short viewports (landscape phone): shed the optional furniture. */
@media (max-height: 560px) {
  :root { --card-w: 66px; }
  .slot-cap, .promise, .switches { display: none; }
  .status { min-height: 1.6em; font-size: 12px; }
  .call { min-height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}
