/* KATAPULT play client — portrait-first board.
   Phone is the design target; the desktop layout is the same board with side
   rails. Every rule here assumes touch: no hover is ever load-bearing. */

:root {
  --k-safe-top: env(safe-area-inset-top, 0px);
  --k-safe-bottom: env(safe-area-inset-bottom, 0px);
  --k-rail: 0px;
  --lane-gap: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
  background: var(--k-bg, #12101f);
  color: var(--k-parchment, #ece2c6);
  font-family: var(--k-font-ui, system-ui, sans-serif);
  /* no double-tap zoom, no pinch, no 300ms tap delay */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* 100dvh, never 100vh: the mobile URL bar must not clip the hand */
#app {
  position: relative;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--k-safe-top);
  padding-bottom: var(--k-safe-bottom);
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  /* every tappable control clears the 44px target floor */
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

/* the stage is the flex child that must absorb the height at every width */
.stage { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.screen { display: none; flex: 1; min-width: 0; min-height: 0; flex-direction: column; }
.screen[data-active] { display: flex; }
/* the board is a grid, but only once it is the active screen */
.screen.board { display: none; }
.screen.board[data-active] { display: grid; }

/* ── HOME ─────────────────────────────────────────────────────────── */
.home {
  width: 100%;
  min-width: 0;
  justify-content: center;
  align-items: center;
  gap: 18px;
  padding: 24px 20px calc(24px + var(--k-safe-bottom));
  text-align: center;
  background:
    radial-gradient(ellipse 80% 50% at 50% 8%, rgba(201, 164, 92, .13), transparent 70%),
    var(--k-bg, #12101f);
}
.brand {
  font-family: var(--k-font-brand, Cinzel, serif);
  font-size: clamp(1.7rem, 8.6vw, 3.2rem);
  letter-spacing: .1em;
  max-width: 100%;
  color: var(--k-gold-bright, #e8c477);
  margin: 0;
}
.tagline {
  margin: 0 0 6px;
  font-size: .82rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--k-parchment-dim, #d8cba9);
  opacity: .8;
}
.cta {
  width: min(420px, 100%);
  padding: 16px 20px;
  font-family: var(--k-font-brand, Cinzel, serif);
  font-size: 1.05rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  border: 1px solid var(--k-gold-dim, #8a713f);
  background: linear-gradient(180deg, rgba(232, 196, 119, .16), rgba(201, 164, 92, .06));
  color: var(--k-gold-bright, #e8c477);
  transition: transform .12s var(--k-ease), background .18s var(--k-ease);
}
.cta--primary {
  background: linear-gradient(180deg, #e8c477, #c9a45c 60%, #a2803f);
  color: #241f38;
  border-color: #ffe6a8;
  font-weight: 700;
}
.cta:active { transform: translateY(1px) scale(.99); }
.cta[disabled] { opacity: .45; pointer-events: none; }
.stats {
  display: flex;
  gap: 18px;
  font-size: .78rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--k-parchment-dim, #d8cba9);
  opacity: .75;
}
.stats b { color: var(--k-gold-bright, #e8c477); }

/* ── BOARD ────────────────────────────────────────────────────────── */
.board {
  /* one column that can never exceed the viewport: without minmax(0,1fr) a
     crowded hand widens the whole grid and pushes lane 5 off screen */
  grid-template-columns: minmax(0, 1fr);
  /* opponent realm · lanes · battle · hud · katapults · realm · hand · hud · actions
     the battle keeps a bounded share; the slack goes to the hand, where the
     thumb lives */
  grid-template-rows: auto auto minmax(56px, 22dvh) auto auto auto 1fr auto auto;
  gap: 3px;
  padding: 4px var(--k-rail);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* five lanes always fit: grid children default to min-width:auto, which is what
   pushed the fifth lane off a 390px screen */
.row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--lane-gap);
  padding: 0 6px;
  min-width: 0;
}
.row > * { min-width: 0; }

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 12px;
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--k-parchment-dim, #d8cba9);
}
.hud b { color: var(--k-gold-bright, #e8c477); }

/* the clock is always legible; it warns, then goes critical */
.clock {
  font-family: var(--k-font-brand, Cinzel, serif);
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  color: var(--k-gold-bright, #e8c477);
  min-width: 2.6ch;
  text-align: center;
}
.clock[data-state="warn"] { color: var(--k-element, #d9a933); }
.clock[data-state="critical"] { color: var(--k-danger, #d64541); animation: pulse .8s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* Realm tile: architectural, not a card */
.tile {
  position: relative;
  min-width: 0;
  aspect-ratio: 1 / 0.82;
  border: 1px solid var(--k-line, #3a3458);
  background: linear-gradient(180deg, #221d3c, #14111f);
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 3px;
  text-align: center;
  overflow: hidden;
}
.tile img { width: 44%; image-rendering: auto; }
.tile .name {
  font-size: clamp(6px, 2.1vw, 9px);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--k-gold, #c9a45c);
}
.tile .hp { font-size: 9px; letter-spacing: 1px; color: var(--k-hp, #cf3f3f); }
.tile .hp .lost { opacity: .22; }
.tile[data-hidden] { background: repeating-linear-gradient(135deg, #1a1730 0 5px, #15121f 5px 10px); }
.tile[data-hidden] .name { color: var(--k-line, #3a3458); }
.tile[data-destroyed] { filter: grayscale(1) brightness(.45); }
.tile[data-hit] { animation: tile-hit .42s var(--k-ease); }
@keyframes tile-hit {
  0% { transform: none; }
  22% { transform: translateY(3px) scale(.96); box-shadow: 0 0 22px rgba(214, 69, 65, .8) inset; }
  100% { transform: none; }
}

/* Katapult slot: the drop target */
.slot {
  position: relative;
  min-width: 0;
  min-height: 54px;
  aspect-ratio: 1 / 1.35;   /* closer to a card, so it reads less squat */
  overflow: hidden;
  border: 1px dashed var(--k-line, #3a3458);
  display: grid;
  place-items: center;
  color: var(--k-line, #3a3458);
  font-size: 9px;
  letter-spacing: .12em;
  text-transform: uppercase;
  transition: border-color .16s var(--k-ease), box-shadow .16s var(--k-ease), transform .16s var(--k-ease);
}
/* magnetic snap target while a card is picked up */
.slot[data-droppable] {
  border-color: var(--k-gold-bright, #e8c477);
  color: var(--k-gold-bright, #e8c477);
  box-shadow: 0 0 14px rgba(232, 196, 119, .28) inset;
}
.slot[data-magnet] { transform: scale(1.06); box-shadow: 0 0 20px rgba(232, 196, 119, .5) inset; }
.slot[data-filled] { border-style: solid; border-color: var(--k-gold-dim, #8a713f); }
/* a rival lane whose contents the rules keep secret — not a face-down card */
.slot[data-veiled] {
  border-style: solid;
  border-color: rgba(58, 52, 88, .9);
  background: repeating-linear-gradient(135deg, #1a1730 0 6px, #15121f 6px 12px);
  color: rgba(201, 164, 92, .45);
  font-size: 8px;
}
/* A card keeps its 1:1.946 canon proportion, always. Sizing by height lets the
   aspect-ratio decide the width; the old width:100% + max-height:100% fought
   the ratio and squashed the art. A lane is wider than a card is — the card
   sits centred in it rather than being stretched to fill it. */
.slot > .k-hexcard, .slot > .k-cardback {
  height: 100%;
  width: auto;
  max-width: 100%;
  align-self: center;
  justify-self: center;
}

/* Pick a lane card up to read it: it grows from its own centre, rises above
   its neighbours, and the lane stops clipping for as long as it is lifted.
   Pointer devices only — touch already has long-press inspect. */
@media (hover: hover) and (pointer: fine) {
  .slot:has(> .k-hexcard:hover),
  .slot:has(> .k-cardback:hover) {
    overflow: visible;
    z-index: 40;
  }
  .slot > .k-hexcard, .slot > .k-cardback {
    transition: transform .18s var(--k-ease, cubic-bezier(.25,.46,.45,.94)), filter .18s var(--k-ease, cubic-bezier(.25,.46,.45,.94));
    /* your lane grows UP into the empty battle space, so a lifted card never
       hides the Realm tile it is aimed at */
    transform-origin: center bottom;
  }
  /* the rival row hangs from the top, so its cards grow downward instead */
  #oppSlots .slot > .k-hexcard, #oppSlots .slot > .k-cardback { transform-origin: center top; }
  .slot > .k-hexcard:hover, .slot > .k-cardback:hover {
    transform: scale(1.85);
    filter: drop-shadow(0 14px 26px rgba(0, 0, 0, .6)) drop-shadow(0 0 14px rgba(232, 196, 119, .3));
    z-index: 41;
    cursor: zoom-in;
  }
}
.slot .fused {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 8px;
  padding: 1px 4px;
  border-radius: 2px;
  background: var(--k-element, #d9a933);
  color: #241f38;
  font-weight: 700;
}

/* Battle space: the reveal beat owns this area and nothing may cover it */
.battle {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
}
.battle .banner {
  font-family: var(--k-font-brand, Cinzel, serif);
  font-size: clamp(.8rem, 3.6vw, 1.2rem);
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--k-gold-bright, #e8c477);
  text-align: center;
  padding: 0 14px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .8);
}
.battle .banner[data-flash] { animation: flash .5s var(--k-ease); }
@keyframes flash {
  0% { transform: scale(.9); opacity: 0; }
  40% { transform: scale(1.06); opacity: 1; }
  100% { transform: none; opacity: 1; }
}
/* a projectile is a Timeline event made visible; it never decides anything */
.shot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff, var(--k-gold-bright, #e8c477) 45%, transparent 70%);
  filter: drop-shadow(0 0 8px rgba(232, 196, 119, .9));
  pointer-events: none;
}
.spark {
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--k-fire, #e8722c) 35%, transparent 70%);
  pointer-events: none;
  animation: spark .42s ease-out forwards;
}
@keyframes spark {
  from { transform: scale(.2); opacity: 1; }
  to { transform: scale(1.6); opacity: 0; }
}

/* Hand: thumb zone, fanned, tap or drag */
.hand {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0;
  min-width: 0;
  min-height: 0;
  max-height: 26dvh;
  padding: 2px 8px 0;
}
.hand > * {
  width: clamp(62px, 23vw, 104px);
  max-height: 26dvh;
  margin: 0 -6px;
  /* a crowded hand overlaps harder instead of overflowing */
  flex: 0 1 auto;
  min-width: 34px;
  transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), filter .2s var(--k-ease);
  transform-origin: 50% 120%;
  cursor: grab;
}
.hand > *[data-selected] {
  transform: translateY(-14px) scale(1.12);
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .6)) drop-shadow(0 0 10px rgba(232, 196, 119, .5));
  z-index: 3;
}
.hand > *[data-dragging] { opacity: .35; }
.hand > *[data-element][data-selected] { filter: drop-shadow(0 0 12px rgba(217, 169, 51, .8)); }

.actions {
  display: flex;
  gap: 8px;
  padding: 6px 12px calc(8px + var(--k-safe-bottom));
}
.actions .cta { flex: 1; padding: 14px 12px; font-size: .92rem; }

/* the card that follows the finger while dragging */
#ghost {
  position: fixed;
  z-index: 60;
  width: 84px;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.1);
  filter: drop-shadow(0 12px 20px rgba(0, 0, 0, .7));
}

/* ── OVERLAYS ─────────────────────────────────────────────────────── */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 6, 16, .82);
  backdrop-filter: blur(3px);
}
.sheet[data-open] { display: flex; }
.sheet-inner {
  width: min(460px, 100%);
  max-height: 88dvh;
  overflow: auto;
  padding: 22px 20px calc(22px + var(--k-safe-bottom));
  border: 1px solid var(--k-gold-dim, #8a713f);
  background: linear-gradient(180deg, #1c1930, #12101f);
  text-align: center;
}
.sheet h2 {
  font-family: var(--k-font-brand, Cinzel, serif);
  letter-spacing: .12em;
  text-transform: uppercase;
  margin: 0 0 8px;
  color: var(--k-gold-bright, #e8c477);
}
.sheet p { margin: 0 0 14px; font-size: .9rem; color: var(--k-parchment-dim, #d8cba9); }
.sheet .cta { margin-top: 8px; }
.sheet .grab {
  width: 42px;
  height: 4px;
  border-radius: 2px;
  background: var(--k-line, #3a3458);
  margin: -8px auto 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--k-safe-bottom));
  transform: translateX(-50%);
  z-index: 50;
  padding: 10px 16px;
  font-size: .82rem;
  border: 1px solid var(--k-gold-dim, #8a713f);
  background: rgba(18, 16, 31, .96);
  color: var(--k-parchment, #ece2c6);
  opacity: 0;
  transition: opacity .2s var(--k-ease);
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast[data-show] { opacity: 1; }

/* first-match coaching: at most three contextual hints, never a tutorial wall */
.hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 13px;
  font-size: .76rem;
  border: 1px solid var(--k-gold-dim, #8a713f);
  background: rgba(18, 16, 31, .95);
  color: var(--k-gold-bright, #e8c477);
  z-index: 20;
  pointer-events: none;
  white-space: nowrap;
}

/* ── ADS ──────────────────────────────────────────────────────────────
   Side rails on desktop, exactly ONE banner under the board on phones.
   The rules of this surface, in order of authority:

   1. An ad never overlaps the board. Rails and banner are flow siblings of
      the stage — never positioned over it, never given a positive z-index.
   2. An ad never appears during the reveal/clash beat. `body[data-reveal]`
      (set by timeline.mjs) blanks the whole surface with `visibility`, which
      costs no reflow and keeps the box reserved.
   3. An ad never shifts the layout. Every slot's box is reserved here at
      first paint AND is already full — the house ad ships in the markup, so
      there is no empty hole to fill later and nothing moves when (if) a real
      AdSense unit arrives in its place. CLS contribution: zero, by shape.
   4. An ad never costs a frame. `contain` walls each slot off from the
      board's layout, paint and style, so no third-party DOM inside it can
      reflow or repaint the game. ────────────────────────────────────── */

:root {
  /* the reserved boxes. Changing these is the only way to resize the surface. */
  --k-ad-banner-h: 56px;   /* 50px creative + 3px breathing room, top and bottom */
  --k-ad-rail-w: 176px;    /* 160px creative + 8px gutters */
}

.ad {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* the wall: nothing inside a slot can reflow, repaint or restyle the board */
  contain: layout paint style;
  isolation: isolate;
  z-index: 0;
  color: var(--k-parchment-dim, #d8cba9);
  background: linear-gradient(180deg, rgba(201, 164, 92, .05), transparent);
}

.ad--banner {
  flex: 0 0 var(--k-ad-banner-h);
  height: var(--k-ad-banner-h);
  padding: 3px 8px;
  border-top: 1px solid rgba(58, 52, 88, .5);
}
/* rails are desktop-only; on a phone they do not exist at all */
.ad--rail { display: none; }

/* The real AdSense unit. It is ALWAYS laid out, never `display:none`: an
   empty <ins> paints nothing, but a display:none container has no width for
   Google to measure, so it would never fill in the first place. It is stacked
   underneath the house creative, in the same reserved box — which is also why
   swapping one for the other cannot shift anything. Fixed pixel sizes on
   purpose: a "responsive" unit measures and resizes itself after load, and
   that is a layout shift. */
.ad-slot {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 0;
}
.ad[data-mode="adsense"] .house { display: none; }

/* House ad — the default, and the fallback whenever AdSense is absent,
   unapproved or blocked. It must read as part of the frame: quiet, gold on
   navy, never louder than the board. */
.house {
  position: relative;
  z-index: 1;   /* on top of the empty ad slot until a real ad reports filled */
  display: flex;
  text-decoration: none;
  color: inherit;
  opacity: .72;
  transition: opacity .18s var(--k-ease);
}
.house:hover, .house:focus-visible { opacity: 1; }
.house:active { opacity: 1; transform: translateY(1px); }
.house-eyebrow {
  font-size: 8.5px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--k-gold, #c9a45c);
}
.house-line {
  font-size: .72rem;
  line-height: 1.35;
  color: var(--k-parchment-dim, #d8cba9);
}
.house-cta {
  font-size: 8.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--k-gold-bright, #e8c477);
  border-bottom: 1px solid var(--k-gold-dim, #8a713f);
  align-self: center;
  padding-bottom: 2px;
}

.ad--banner .house {
  width: 100%;
  height: 100%;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 6px;
}
/* one line, always: the banner truncates its middle rather than growing a
   second row, because a second row would resize a box the board depends on */
.ad--banner .house-eyebrow,
.ad--banner .house-cta { flex: 0 0 auto; white-space: nowrap; }
.ad--banner .house-line { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* On the narrowest phones the pitch survives and the CTA goes: the whole
   banner is the link, so the CTA was the redundant half. */
@media (max-width: 430px) {
  .ad--banner .house-cta { display: none; }
}

.ad--rail .house {
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 22px 14px;
  text-align: center;
}

/* the reveal beat blanks the whole surface: nothing competes with the hero
   moment, and no stray tap can land on an ad while the clash plays */
body[data-reveal] .ad,
body[data-ads-paused] .ad {
  visibility: hidden;
  pointer-events: none;
}

/* ── CONSENT ──────────────────────────────────────────────────────────
   One line, dismissible, remembered. Opened by ads.mjs only when real
   third-party ads are on, and only while the home screen is up — so it is
   physically impossible for it to sit over a match. Fixed, therefore out of
   flow, therefore it cannot shift anything either. */
.consent {
  display: none;
  position: fixed;
  left: 50%;
  bottom: calc(var(--k-ad-banner-h) + 10px + var(--k-safe-bottom));
  transform: translateX(-50%);
  z-index: 30;
  align-items: center;
  gap: 12px;
  width: min(460px, calc(100vw - 24px));
  padding: 8px 10px 8px 14px;
  border: 1px solid var(--k-gold-dim, #8a713f);
  background: rgba(18, 16, 31, .97);
}
.consent[data-open] { display: flex; }
body[data-reveal] .consent { display: none; }
.consent p {
  margin: 0;
  flex: 1;
  font-size: .7rem;
  line-height: 1.4;
  color: var(--k-parchment-dim, #d8cba9);
}
.consent-link {
  flex: 0 0 auto;
  font-size: .66rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--k-gold, #c9a45c);
}
.consent-ok {
  flex: 0 0 auto;
  min-width: 56px;
  min-height: 36px;
  padding: 6px 14px;
  font-family: var(--k-font-brand, Cinzel, serif);
  font-size: .74rem;
  letter-spacing: .14em;
  border: 1px solid var(--k-gold-dim, #8a713f);
  color: var(--k-gold-bright, #e8c477);
}

/* A short viewport is a landscape phone: the board needs every pixel, so the
   banner is removed outright rather than squeezed. Static, so still no CLS. */
@media (max-height: 620px) and (max-width: 1099px) {
  :root { --k-ad-banner-h: 0px; }
  .ad--banner { display: none; }
}

@media (min-width: 900px) {
  .board { max-width: 720px; margin: 0 auto; width: 100%; }
}

/* Rails only once the desktop rails are genuinely empty space: 1100px leaves
   the 720px board untouched after two 176px rails. Below that, the phone
   banner keeps the surface (never both, never neither). */
@media (min-width: 1100px) {
  :root { --k-ad-banner-h: 0px; }
  #app { flex-direction: row; }
  .ad--rail {
    display: flex;
    flex: 0 0 var(--k-ad-rail-w);
    width: var(--k-ad-rail-w);
    border-left: 1px solid rgba(58, 52, 88, .5);
  }
  .ad--rail:first-child { border-left: 0; border-right: 1px solid rgba(58, 52, 88, .5); }
  .ad--banner { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── ACCOUNT ROW ───────────────────────────────────────────────────────────
   Present on the home screen from the first paint. It states who you are and
   offers the one action that changes it. Quiet by default: identity should
   never shout louder than QUICK MATCH. */
.account {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  font-size: .7rem;
  letter-spacing: .06em;
}
.account-who { color: var(--k-parchment-dim, #9c93b8); }
.account-who[data-linked] { color: var(--k-gold-bright, #e8c477); }
.account-act {
  background: transparent;
  border: 1px solid var(--k-gold-dim, #8a713f);
  color: var(--k-gold, #c9a45c);
  font-family: inherit;
  font-size: .66rem;
  letter-spacing: .1em;
  padding: 7px 14px;
  min-height: 34px;
  cursor: pointer;
  border-radius: 2px;
}
.account-act:hover, .account-act:focus-visible {
  color: var(--k-gold-bright, #e8c477);
  border-color: var(--k-gold-bright, #e8c477);
}
.account-act[hidden] { display: none; }
