/* =============================================================================
   Loteria Juntos -- styles for the host window and the TV window
   ============================================================================= */

:root {
  --ink: #221018;
  --panel: #2E1424;
  --panel-2: #3A1A2D;
  --line: rgba(255, 216, 150, 0.18);
  --gold: #F7DB8E;
  --gold-dim: #C98A2A;
  --pink: #F26A8D;
  --pink-soft: #FFA8C8;
  --blue: #7FA8E0;        /* the blue in the TV bunting */
  --blue-soft: #A8C6EE;
  --cream: #F8F0DC;
  --good: #5FBFA5;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(120% 100% at 20% 0%, #4A1233 0%, #23091A 60%, #170611 100%);
  color: var(--cream);
  -webkit-font-smoothing: antialiased;
}

/* ============================================================ stage (shared) */

.stage-host {
  position: relative;
  overflow: hidden;
  background: #12040E;
}

.stage {
  position: absolute;
  left: 0;
  top: 0;
  overflow: hidden;
}

.stage-bg {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.slot {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-img {
  max-width: 100%;
  max-height: 100%;
  width: auto; height: auto;
  border-radius: 14px;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.55), 0 0 0 2px rgba(255, 216, 150, 0.35);
  user-select: none;
  -webkit-user-drag: none;
}

.slot-hist .card-img {
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5), 0 0 0 1.5px rgba(255, 216, 150, 0.25);
}

.slot.is-empty .card-img { display: none; }

.slot.is-empty::after {
  content: "";
  width: 62%;
  aspect-ratio: 5 / 8;
  border: 2px dashed rgba(255, 216, 150, 0.20);
  border-radius: 10px;
}

.slot-hero.is-empty::after { width: 82%; }

.hist-label {
  position: absolute;
  bottom: -1.6em;
  left: 0; right: 0;
  text-align: center;
  opacity: 0.7;
  letter-spacing: 0.08em;
}

/* Tip QR: a light card, because a code needs a quiet zone to scan and the
   stage behind it is dark. The card holds only the code -- the label sits
   under it on the stage, so nothing competes with the code for the box. */
.slot-tip {
  flex-direction: column;
  justify-content: flex-start;
  gap: 0;
  z-index: 12;
}

.tip-card {
  width: 100%;
  box-sizing: border-box;
  background: #FFFFFF;
  border-radius: 10px;
  /* Thin on purpose. The canvas already carries the quiet zone a scanner
     needs; this margin is only there so the code reads as a card rather than
     a black smudge, and every point of it comes off the code's own size. */
  padding: 1.5%;
  line-height: 0;               /* no stray baseline gap under the canvas */
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45), 0 0 0 2px rgba(255, 216, 150, 0.35);
}

.tip-qr {
  width: 100%;
  height: auto;
  image-rendering: pixelated;   /* keep module edges crisp when scaled */
  display: block;
}

.tip-label {
  font-family: Georgia, serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding-top: 5%;
  line-height: 1;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.7), 0 1px 2px rgba(0, 0, 0, 0.9);
}

/* History slots carry z-index 1..n so a fanned layout stacks newest-on-top;
   everything meant to sit above the cards has to clear that range. */
.stage-text {
  position: absolute;
  z-index: 10;
  display: flex;
  align-items: center;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
}

.stage-text.has-shadow {
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.7), 0 1px 2px rgba(0, 0, 0, 0.9);
}

.stage-fx {
  position: absolute;
  left: 0; top: 0;
  z-index: 20;
  pointer-events: none;
}

/* --- card entrance -------------------------------------------------------- */

@keyframes cardPop {
  0%   { transform: scale(0.62) rotate(-7deg); opacity: 0; filter: brightness(1.8); }
  45%  { transform: scale(1.06) rotate(1.5deg); opacity: 1; filter: brightness(1.25); }
  70%  { transform: scale(0.985) rotate(-0.6deg); filter: brightness(1.05); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; filter: brightness(1); }
}

.slot-hero.pop .card-img {
  animation: cardPop 620ms cubic-bezier(0.22, 1.2, 0.36, 1) both;
}

@keyframes histSlide {
  0%   { transform: translateX(14px) scale(0.9); opacity: 0.15; }
  100% { transform: translateX(0) scale(1); opacity: 1; }
}

.slot-hist.slide .card-img {
  animation: histSlide 420ms cubic-bezier(0.2, 0.9, 0.3, 1) both;
}

/* --- design guides -------------------------------------------------------- */

.stage-guides { position: absolute; inset: 0; z-index: 30; pointer-events: none; }

.guide {
  position: absolute;
  border: 2px solid rgba(95, 255, 220, 0.85);
  background: rgba(95, 255, 220, 0.07);
}

.guide span {
  position: absolute;
  left: 0; top: 0;
  font: 600 18px/1.2 ui-monospace, "SF Mono", Menlo, monospace;
  color: #061E1A;
  background: rgba(95, 255, 220, 0.9);
  padding: 3px 7px;
  white-space: nowrap;
}

/* ================================================================ TV window */

body.tv { overflow: hidden; background: #12040E; }

body.tv .stage-host {
  position: fixed;
  inset: 0;
  cursor: none;
}

.tv-hint {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  font: 500 14px/1 system-ui, sans-serif;
  color: rgba(255, 233, 168, 0.7);
  background: rgba(0, 0, 0, 0.55);
  padding: 9px 16px;
  border-radius: 999px;
  z-index: 50;
  transition: opacity 400ms;
  pointer-events: none;
}

.tv-hint.gone { opacity: 0; }

/* ============================================================== host window */

.host-wrap {
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px 22px 60px;
}

header.host-head {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}

.brand {
  font-family: Georgia, serif;
  font-size: 30px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.02em;
  margin: 0;
}

.brand .ver {
  display: block;
  margin-top: 3px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--pink-soft);
  opacity: 0.55;
}

.brand small {
  display: block;
  font-family: system-ui, sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--pink-soft);
  opacity: 0.85;
}

.game-chip {
  display: flex;
  align-items: baseline;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
}

.game-chip .name {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 18px;
  color: var(--gold);
}

.game-chip .count {
  font-size: 14px;
  color: var(--pink-soft);
}

.spacer { flex: 1; }

.tv-state {
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
}

.tv-state.on { color: var(--good); border-color: rgba(95, 191, 165, 0.5); }
.tv-state.off { color: var(--pink-soft); }

/* --- layout --------------------------------------------------------------- */

.cols {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 20px;
  align-items: start;
}

@media (max-width: 1080px) {
  .cols { grid-template-columns: 1fr; }
}

/* Deck and Theme live inside the TV panel, side by side below the preview. */
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .pair { grid-template-columns: 1fr; }
}

.pair.subs {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.sub h3 {
  margin: 0 0 10px;
  font-family: Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sub h3 .tag {
  font: 500 10px/1 system-ui, sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--pink-soft);
  background: rgba(242, 106, 141, 0.15);
  border: 1px solid rgba(242, 106, 141, 0.3);
  padding: 3px 7px;
  border-radius: 999px;
}

.card-panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card-panel h2 {
  margin: 0 0 12px;
  font-family: Georgia, serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-panel h2 .tag {
  font: 500 11px/1 system-ui, sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--pink-soft);
  background: rgba(242, 106, 141, 0.15);
  border: 1px solid rgba(242, 106, 141, 0.3);
  padding: 4px 8px;
  border-radius: 999px;
}

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

.btn {
  font: 600 15px/1 system-ui, sans-serif;
  color: var(--cream);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 90ms, background 140ms, border-color 140ms;
}

.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.13); border-color: rgba(255, 216, 150, 0.4); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(180deg, #F7C948, #E08A1E);
  color: #3A1A02;
  border-color: #F7DB8E;
  font-size: 19px;
  font-weight: 800;
  padding: 18px 26px;
  box-shadow: 0 8px 22px rgba(224, 138, 30, 0.35);
  transition: background 140ms, border-color 140ms, color 140ms, box-shadow 140ms;
}

/* Goes green on hover: the draw button is pressed dozens of times a night,
   often without looking, so it should confirm it is under the cursor. */
.btn.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #6FD08C, #35A05E);
  border-color: #A8E8BE;
  color: #06301A;
  box-shadow: 0 8px 22px rgba(53, 160, 94, 0.38);
}

.btn.pink {
  background: linear-gradient(180deg, #F26A8D, #C43A66);
  color: #fff;
  border-color: var(--pink-soft);
}

.btn.green {
  background: linear-gradient(180deg, var(--good), #3E8F7B);
  color: #06231D;
  border-color: #A8E8D8;
}

.btn.blue {
  background: linear-gradient(180deg, var(--blue), #4A72B0);
  color: #fff;
  border-color: var(--blue-soft);
}

.btn.ghost { background: transparent; }

.btn.sm { font-size: 13px; padding: 8px 12px; border-radius: 9px; }

/* A pressed-in look for buttons that toggle something on. */
.btn.is-on {
  background: rgba(95, 255, 220, 0.16);
  border-color: rgba(95, 255, 220, 0.6);
  color: #BFFFF0;
}

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.controls .grow { flex: 1 1 240px; }

/* Secondary toggles: smaller and quieter than the main control row. */
.controls.fine { gap: 10px; }
.controls.fine .toggle { font-size: 12px; color: rgba(248, 240, 220, 0.7); }

.kbd {
  font: 600 11px/1 ui-monospace, Menlo, monospace;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 3px 6px;
  color: var(--pink-soft);
  background: rgba(0, 0, 0, 0.3);
}

.hint { font-size: 12.5px; color: rgba(248, 240, 220, 0.55); margin: 10px 0 0; }

/* --- preview -------------------------------------------------------------- */

.preview {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #12040E;
}

/* --- drawn list ----------------------------------------------------------- */

.draw-list {
  list-style: none;
  margin: 0;
  padding: 0;
  /* No cap: the list grows down the page rather than scrolling in a window.
     The panel is last in its column, so nothing gets pushed out of reach. */
  font-size: 14px;
}

/* Every line is a jump target: click one and the game moves there. Lines above
   the current position are cards already shown tonight that the host has
   stepped back past -- kept listed, and dimmed, so there is a way forward. */
.draw-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, opacity 120ms;
}

.draw-list li:nth-child(even) { background: rgba(255, 255, 255, 0.035); }

.draw-list li:hover {
  background: rgba(127, 168, 224, 0.18);
  border-color: rgba(168, 198, 238, 0.5);
}

.draw-list li:focus-visible {
  outline: 2px solid var(--blue-soft);
  outline-offset: 1px;
}

.draw-list li.current {
  background: rgba(247, 201, 72, 0.18);
  border-color: rgba(247, 219, 142, 0.45);
}

.draw-list li.current:hover { background: rgba(247, 201, 72, 0.26); }

.draw-list li.current .nm { font-weight: 700; }

.draw-list li.ahead { opacity: 0.42; }
.draw-list li.ahead:hover { opacity: 0.85; }

.draw-list .ord {
  font: 600 12px/1 ui-monospace, Menlo, monospace;
  color: var(--pink-soft);
  min-width: 30px;
}

.draw-list .num {
  font: 700 13px/1 ui-monospace, Menlo, monospace;
  color: var(--gold);
  min-width: 26px;
  text-align: right;
}

/* --- board (all 54) ------------------------------------------------------- */

/* Sits in the left column at the same width as the TV preview, so it never runs
   under the lists on the right. Fixed at 7 across rather than auto-fill: the
   host is reading this at a glance mid-game, so bigger cards beat more columns. */
.board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
}

.board .cell {
  position: relative;
  border-radius: 9px;
  overflow: hidden;
  border: 2px solid transparent;
  background: rgba(0, 0, 0, 0.3);
  transition: border-color 160ms, filter 160ms, transform 160ms;
}

.board .cell img { width: 100%; display: block; }

.board .cell:not(.drawn) img { filter: grayscale(0.85) brightness(0.5) contrast(0.9); }

.board .cell.drawn {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(247, 219, 142, 0.3), 0 6px 18px rgba(0, 0, 0, 0.4);
}

.board .cell.current {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(242, 106, 141, 0.35), 0 6px 20px rgba(0, 0, 0, 0.5);
  transform: translateY(-2px);
}

.board .cell .check {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--good);
  color: #06231D;
  font: 800 14px/22px system-ui, sans-serif;
  text-align: center;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 180ms, transform 180ms;
}

.board .cell.drawn .check { opacity: 1; transform: scale(1); }
.board .cell.current .check { background: var(--pink); color: #3A0A1C; }

.board .cell .ordinal {
  position: absolute;
  bottom: 4px; left: 4px;
  font: 700 11px/1 ui-monospace, Menlo, monospace;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.7);
  padding: 3px 5px;
  border-radius: 5px;
  opacity: 0;
}

.board .cell.drawn .ordinal { opacity: 1; }

/* --- saved games ---------------------------------------------------------- */

.games {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  /* 6 rows before it scrolls -- see --row-game. */
  --row-game: 39px;
  max-height: calc(var(--row-game) * 6);
  overflow-y: auto;
  scrollbar-gutter: stable;
}

/* Rows are the control -- click one to load that game. Numbering is permanent
   and the list is ordered by it, so a game never moves under the cursor. */
.games li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}

.games li:hover {
  background: rgba(127, 168, 224, 0.18);
  border-color: rgba(168, 198, 238, 0.5);
}

.games li:focus-visible {
  outline: 2px solid var(--blue-soft);
  outline-offset: 1px;
}

.games .ord {
  font: 600 12px/1 ui-monospace, Menlo, monospace;
  color: var(--pink-soft);
  min-width: 26px;
}

.games .g-name {
  font: 600 14px/1.3 ui-monospace, Menlo, monospace;
  color: var(--gold);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.games .g-meta { font-size: 12px; color: rgba(248, 240, 220, 0.55); white-space: nowrap; }

.games li.current {
  background: rgba(247, 201, 72, 0.18);
  border-color: rgba(247, 219, 142, 0.45);
}

.games li.current:hover { background: rgba(247, 201, 72, 0.26); }
.games li.current .g-name { font-weight: 700; }

/* Native disclosure: keyboard accessible and needs no script. */
.fold { margin-top: 12px; }

.fold > summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: 500 12.5px/1 system-ui, sans-serif;
  color: rgba(248, 240, 220, 0.6);
  padding: 5px 2px;
  user-select: none;
}

.fold > summary::-webkit-details-marker { display: none; }

.fold > summary::before {
  content: "";
  width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 140ms;
}

.fold[open] > summary::before { transform: rotate(90deg); }

.fold > summary:hover { color: var(--blue-soft); }

.empty { font-size: 13px; color: rgba(248, 240, 220, 0.45); font-style: italic; padding: 6px 2px; }

/* --- inputs --------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: rgba(248, 240, 220, 0.7);
}

.field input, .field select {
  font: 500 14px/1 ui-monospace, Menlo, monospace;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 11px;
  width: 100%;
}

.field input:focus, .field select:focus { outline: 2px solid rgba(247, 219, 142, 0.5); outline-offset: 1px; }

.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > * { min-width: 0; }
.row .flex { flex: 1 1 160px; }

.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }

.msg {
  margin-top: 10px;
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 9px;
  display: none;
}

.msg.show { display: block; }
.msg.ok { background: rgba(95, 191, 165, 0.15); border: 1px solid rgba(95, 191, 165, 0.4); color: #A8E8D8; }
.msg.err { background: rgba(242, 106, 141, 0.15); border: 1px solid rgba(242, 106, 141, 0.45); color: #FFC8D8; }

/* --- modal confirm -------------------------------------------------------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(8, 2, 6, 0.72);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.scrim.show { display: flex; }

.modal {
  background: linear-gradient(180deg, #3A1A2D, #2A1020);
  border: 1px solid rgba(255, 216, 150, 0.3);
  border-radius: 16px;
  padding: 24px;
  max-width: 440px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6);
}

.modal h3 { margin: 0 0 10px; font-family: Georgia, serif; color: var(--gold); font-size: 20px; }
.modal p { margin: 0 0 18px; font-size: 14px; line-height: 1.5; color: rgba(248, 240, 220, 0.8); }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; }
