/* =========================================================
   BOARD (lámina + hitboxes)
========================================================= */
.board {
  grid-area: board;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 30%, #1d3a56 0%, var(--brand-navy) 60%, #0a1b2c 100%);
  display: grid;
  place-items: center;
  padding: var(--space-4);
}
.board__frame {
  position: relative;
  /* Fit within available space — constrained by BOTH width and height */
  width: min(100%, calc((100vh - 72px - 32px) * (1920 / 1080)));
  height: auto;
  aspect-ratio: 1920 / 1080;
  overflow: hidden;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(208, 224, 16, 0.18),
    0 30px 80px rgba(0,0,0,0.5),
    0 0 120px rgba(32, 176, 208, 0.08);
  image-rendering: pixelated;
  cursor: crosshair;
}
.board.intro .board__frame,
.board.countdown .board__frame,
.board.end .board__frame {
  cursor: default;
}

.board__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
  image-rendering: pixelated;
}

.board__overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Hitboxes */
.hit {
  fill: transparent;
  stroke: transparent;
  stroke-width: 0.15;
  pointer-events: all;
  cursor: pointer;
  transition: fill var(--dur-fast) var(--ease-standard),
              stroke var(--dur-fast) var(--ease-standard);
  vector-effect: non-scaling-stroke;
}
.hit--hover {
  fill: rgba(208, 224, 16, 0.22);
  stroke: var(--brand-lime);
  stroke-width: 2;
  filter: drop-shadow(0 0 6px rgba(208, 224, 16, 0.6));
  animation: hit-pulse 1.2s ease-in-out infinite;
}
@keyframes hit-pulse {
  50% { fill: rgba(208, 224, 16, 0.36); }
}
.hit--found {
  fill: rgba(10, 74, 94, 0.65);
  stroke: var(--brand-lime);
  stroke-width: 1;
  cursor: default;
  pointer-events: none;
}
.hit--edit {
  fill: rgba(32, 176, 208, 0.12);
  stroke: var(--brand-teal-bright);
  stroke-width: 1;
  pointer-events: all; /* overridden by appended styles below in edit mode */
}

/* Labels on found / reveal */
.hit__label-txt {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.6px;
  font-weight: 600;
  letter-spacing: 0.02em;
  paint-order: stroke;
  stroke: rgba(10, 30, 50, 0.85);
  stroke-width: 0.5;
  stroke-linejoin: round;
}
.hit__label-txt--found { fill: var(--brand-lime); }
.hit__label-txt--reveal { fill: rgba(255, 255, 255, 0.85); }

.hit__edit-label {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.3px;
  font-weight: 500;
  fill: var(--brand-teal-bright);
  paint-order: stroke;
  stroke: rgba(10, 30, 50, 0.8);
  stroke-width: 0.4;
  pointer-events: none;
}

/* Floating input */
.floater {
  position: absolute;
  min-width: 240px;
  background: rgba(10, 22, 36, 0.96);
  border: 1px solid var(--brand-lime);
  border-radius: var(--radius-md);
  box-shadow:
    0 12px 32px rgba(0,0,0,0.5),
    0 0 24px rgba(208, 224, 16, 0.2);
  padding: 10px 12px;
  z-index: 10;
  animation: floater-in 160ms var(--ease-out) both;
}
@keyframes floater-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.floater--shake {
  animation: floater-shake 360ms;
  border-color: #ff6060;
  box-shadow: 0 0 24px rgba(255, 96, 96, 0.5);
}
@keyframes floater-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.floater__caret {
  position: absolute;
  top: -6px;
  left: 18px;
  width: 10px; height: 10px;
  background: rgba(10, 22, 36, 0.96);
  border-left: 1px solid var(--brand-lime);
  border-top: 1px solid var(--brand-lime);
  transform: rotate(45deg);
}
.floater__input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--white);
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  padding: 4px 0;
  letter-spacing: -0.01em;
}
.floater__input::placeholder { color: rgba(255,255,255,0.35); }
.floater__hint {
  font-family: var(--font-mono);
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  margin-top: 6px;
  letter-spacing: 0.05em;
}
.floater__esc {
  color: var(--brand-teal-bright);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(32, 176, 208, 0.3);
}
.floater__esc:hover { color: var(--brand-lime); }

/* Edit handles */
.edit-handles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.edit-handle {
  position: absolute;
  pointer-events: all;
}
.edit-handle--move {
  cursor: move;
  background: rgba(32, 176, 208, 0.05);
}
.edit-handle--move:hover { background: rgba(32, 176, 208, 0.18); }
.edit-handle--resize {
  width: 14px; height: 14px;
  background: var(--brand-lime);
  border: 2px solid rgba(10, 22, 36, 0.9);
  border-radius: 3px;
  cursor: nwse-resize;
}

/* =========================================================
   SIDE BINGO
========================================================= */
.bingo {
  grid-area: side;
  background: #0c1f33;
  border-left: 1px solid rgba(208, 224, 16, 0.12);
  padding: var(--space-5) var(--space-4);
  overflow-y: auto;
  color: var(--white);
}
.bingo__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.bingo__count {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--brand-lime);
  font-variant-numeric: tabular-nums;
}
.bingo__count-sep { color: rgba(255,255,255,0.3); margin: 0 2px; font-weight: 400; }

.bingo__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bingo__item {
  display: grid;
  grid-template-columns: 28px 1fr 20px;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.02);
  font-size: 13px;
  transition: all var(--dur-fast) var(--ease-standard);
}
.bingo__num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  font-variant-numeric: tabular-nums;
}
.bingo__name {
  font-family: var(--font-display);
  font-weight: 500;
  color: rgba(255,255,255,0.55);
  letter-spacing: -0.005em;
}
.bingo__blanks {
  font-family: var(--font-mono);
  color: rgba(255,255,255,0.18);
  letter-spacing: 0.15em;
}
.bingo__tick { color: transparent; font-size: 14px; }

.bingo__item.is-found {
  background: rgba(208, 224, 16, 0.08);
  border-color: rgba(208, 224, 16, 0.28);
  animation: bingo-pop 400ms var(--ease-out);
}
.bingo__item.is-found .bingo__num { color: var(--brand-lime); }
.bingo__item.is-found .bingo__name { color: var(--white); }
.bingo__item.is-found .bingo__tick { color: var(--brand-lime); }

.bingo__item.is-reveal .bingo__name { color: rgba(255,255,255,0.5); font-style: italic; }
.bingo__item.is-reveal { background: rgba(255,255,255,0.03); }

@keyframes bingo-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.04); background: rgba(208, 224, 16, 0.28); }
  100% { transform: scale(1); }
}


/* ---- Edit mode: larger & clearer labels + selection + vertex/pin tools ---- */
.board.is-edit .board__img { filter: saturate(0.75) brightness(0.78); }
.board.edit-tool--pin .board__frame { cursor: crosshair; }

.hit--edit {
  fill: rgba(32, 176, 208, 0.14);
  stroke: rgba(32, 176, 208, 0.9);
  stroke-width: 0.35;
  stroke-dasharray: 0.8 0.6;
  pointer-events: all;
  cursor: pointer;
  transition: fill 120ms ease, stroke 120ms ease;
}
.hit--edit:hover {
  fill: rgba(32, 176, 208, 0.28);
  stroke: var(--brand-teal-bright);
}
.hit--selected {
  fill: rgba(208, 224, 16, 0.32) !important;
  stroke: var(--brand-lime) !important;
  stroke-width: 0.6 !important;
  stroke-dasharray: none !important;
  filter: drop-shadow(0 0 2px rgba(208, 224, 16, 0.6));
}

.hit__edit-num {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 2.4px;
  font-weight: 700;
  fill: #fff;
  paint-order: stroke;
  stroke: rgba(0,0,0,0.85);
  stroke-width: 0.7;
  stroke-linejoin: round;
  pointer-events: none;
}
.hit__edit-num--sel { fill: var(--brand-lime); }

.hit__edit-label {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5px;
  font-weight: 600;
  fill: rgba(255,255,255,0.92);
  paint-order: stroke;
  stroke: rgba(0,0,0,0.85);
  stroke-width: 0.5;
  stroke-linejoin: round;
  pointer-events: none;
}
.hit__edit-label--sel { fill: var(--brand-lime); }

/* Move-tool handles */
.edit-handle--move {
  cursor: move;
  background: rgba(32, 176, 208, 0.0);
  outline: 1px dashed rgba(32, 176, 208, 0);
  transition: background 120ms ease, outline-color 120ms ease;
}
.edit-handle--move:hover {
  background: rgba(32, 176, 208, 0.18);
  outline-color: rgba(32, 176, 208, 0.6);
}
.edit-handle--move.is-selected {
  background: rgba(208, 224, 16, 0.14);
  outline: 1px dashed var(--brand-lime);
}

/* Vertex tool */
.vertex-layer { pointer-events: none; }
.vertex-edge {
  stroke: var(--brand-lime);
  stroke-width: 0.4;
  opacity: 0.7;
  pointer-events: stroke;
  cursor: copy;
}
.vertex-edge:hover { stroke-width: 0.8; opacity: 1; }
.vertex-dot {
  fill: var(--brand-lime);
  stroke: #0a1624;
  stroke-width: 0.25;
  pointer-events: all;
  cursor: grab;
}
.vertex-dot:hover { r: 1.3; fill: #fff; }
.vertex-dot:active { cursor: grabbing; }


/* =============================================
   INTERACTION v2: hover glow + click-to-open
   ============================================= */

/* Active (clicked) state */
.hit--active {
  fill: rgba(208, 224, 16, 0.28);
  stroke: var(--brand-lime);
  stroke-width: 0.6;
  filter: drop-shadow(0 0 4px rgba(208, 224, 16, 0.7));
  animation: hit-pulse 1.2s ease-in-out infinite;
  cursor: pointer;
}

/* Hover: subtle glow + pointer cursor */
.hit--hover {
  fill: rgba(208, 224, 16, 0.16);
  stroke: rgba(208, 224, 16, 0.7);
  stroke-width: 0.4;
  cursor: pointer;
  transition: fill 120ms ease, stroke 120ms ease;
}

/* Hover tooltip */
.hover-tip {
  position: absolute;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(10, 22, 36, 0.88);
  border: 1px solid rgba(208, 224, 16, 0.35);
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,0.9);
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: floater-in 120ms var(--ease-out) both;
  z-index: 8;
}
.hover-tip__icon { font-size: 14px; }

/* Floater — redesigned */
.floater {
  position: absolute;
  min-width: 260px;
  background: rgba(8, 20, 34, 0.97);
  border: 1.5px solid var(--brand-lime);
  border-radius: var(--radius-md);
  box-shadow:
    0 16px 40px rgba(0,0,0,0.55),
    0 0 30px rgba(208, 224, 16, 0.25);
  padding: 14px 16px 12px;
  z-index: 10;
  animation: floater-in 180ms var(--ease-out) both;
}
.floater__lm-name {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
  margin-bottom: 8px;
}
.floater__input {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  outline: none;
  color: var(--white);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
  padding: 8px 10px;
  letter-spacing: -0.01em;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.floater__input:focus {
  border-color: var(--brand-lime);
  box-shadow: 0 0 0 3px rgba(208, 224, 16, 0.18);
}
.floater__input::placeholder { color: rgba(255,255,255,0.3); }
.floater__actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}
.floater__hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(255,255,255,0.45);
}
.floater__esc {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  transition: color 120ms ease;
}
.floater__esc:hover { color: var(--brand-lime); }
.floater--shake {
  animation: floater-shake 360ms both;
  border-color: #ff6060;
  box-shadow: 0 0 24px rgba(255, 96, 96, 0.45);
}


/* =============================================
   HTML Labels over the board (no SVG distortion)
   ============================================= */
.board__labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.lbl {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: 'Space Grotesk', var(--font-display), sans-serif;
  font-size: clamp(8px, 1.1vw, 13px);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
  padding: 2px 5px;
  border-radius: 3px;
  pointer-events: none;
}
.lbl--found {
  color: var(--brand-lime);
  background: rgba(10, 26, 44, 0.75);
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.lbl--reveal {
  color: rgba(255,255,255,0.85);
  background: rgba(10, 26, 44, 0.65);
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.lbl--edit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  color: rgba(255,255,255,0.9);
  background: rgba(10, 26, 44, 0.72);
}
.lbl--edit-sel {
  color: var(--brand-lime);
  background: rgba(10, 26, 44, 0.88);
}
.lbl__num {
  font-family: var(--font-mono, monospace);
  font-size: 0.85em;
  opacity: 0.85;
  display: block;
}
.lbl__name {
  font-size: 0.9em;
  display: block;
}
/* =============================================
   MOBILE BOARD & LAYOUT
   ============================================= */

/* Mobile app layout — full portrait */
@media (max-width: 767px) {
  html, body { overflow: hidden; height: 100dvh; }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr;
    grid-template-areas: "top" "board";
    height: 100dvh;
  }

  /* Hide desktop board on mobile */
  .board { display: none; }
  .bingo { display: none !important; }

  .topbar {
    padding: 0 12px;
    grid-template-columns: 1fr auto 1fr;
  }
  .topbar__title { display: none; }
  .topbar__logo { height: 22px; }
  .timer { width: 56px; height: 56px; margin-top: 4px; }
  .timer__num { font-size: 20px; }
  .timer__label { font-size: 8px; }
  .score__num { font-size: 20px; }
  .score__label { font-size: 9px; }
}

/* Mobile board container */
.board-mobile {
  grid-area: board;
  position: relative;
  display: none; /* hidden on desktop */
  flex-direction: column;
  overflow: hidden;
  background: var(--brand-navy);
}

@media (max-width: 767px) {
  .board-mobile { display: flex; }
  /* Hide desktop board */
  .board { display: none !important; }
}

.board-mobile {
  justify-content: center;
  align-items: center;
}
.board-mobile__frame {
  position: relative;
  /* Fit the whole 1080×1920 image inside the available viewport
     (topbar ~56px). aspect-ratio keeps it exact; min() ensures it
     never overflows height or width. */
  width: min(100vw, calc((100vh - 56px) * (1080 / 1920)));
  aspect-ratio: 1080 / 1920;
  max-height: calc(100vh - 56px);
  overflow: hidden;
  background: var(--brand-navy);
}

.board-mobile__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
}

.board-mobile__overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.board-mobile__overlay .hit {
  pointer-events: all;
  cursor: pointer;
  touch-action: manipulation;
}

/* Bottom sheet */
.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(8, 20, 34, 0.97);
  border-top: 2px solid var(--brand-lime);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  z-index: 200;
  animation: sheet-up 200ms var(--ease-out) both;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
}
@keyframes sheet-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.bottom-sheet--shake {
  animation: floater-shake 360ms both;
  border-top-color: #ff6060;
}
.bottom-sheet__lm {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
  margin-bottom: 10px;
}
.bottom-sheet__form {
  display: flex;
  gap: 10px;
  align-items: center;
}
.bottom-sheet__input {
  flex: 1;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 10px;
  padding: 13px 14px;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  color: var(--white);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.bottom-sheet__input:focus {
  border-color: var(--brand-lime);
  box-shadow: 0 0 0 3px rgba(208,224,16,0.18);
}
.bottom-sheet__input::placeholder { color: rgba(255,255,255,0.3); }
.bottom-sheet__btn {
  width: 52px; height: 52px;
  border-radius: 12px;
  background: var(--brand-lime);
  color: #0a1b2c;
  font-size: 22px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: background 120ms ease;
}
.bottom-sheet__btn:active { background: #e8f830; }
.bottom-sheet__cancel {
  width: 100%;
  margin-top: 10px;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.45);
  font-family: var(--font-display);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
  display: block;
  text-align: center;
}
.bottom-sheet__cancel:active { color: var(--brand-lime); }

/* Mobile tap hint */
.mobile-hint {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(8,20,34,0.88);
  border: 1px solid rgba(208,224,16,0.4);
  border-radius: 20px;
  padding: 6px 14px;
  font-family: var(--font-display);
  font-size: 12px;
  color: rgba(255,255,255,0.9);
  pointer-events: none;
  white-space: nowrap;
  z-index: 50;
}

/* Mobile overlays — full screen */
@media (max-width: 767px) {
  .intro {
    padding: 28px 20px;
    border-radius: 0;
    max-width: 100%;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border: none;
  }
  .intro__title { font-size: 28px; }
  .intro__rules { grid-template-columns: 1fr; }
  .intro__row { flex-direction: column; }
  .intro__input { font-size: 16px; }

  .end {
    border-radius: 0;
    max-width: 100%;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border: none;
    padding: 24px 20px;
  }
  .end__hero-num { font-size: 64px; }
  .end__hero-sep { font-size: 36px; }
  .end__hero-total { font-size: 36px; }
  .end__rank-badge { padding: 12px 16px; min-width: 80px; }
  .end__rank-num { font-size: 36px; }

  .share-bar__btns { gap: 6px; }
  .share-btn { padding: 8px 10px; font-size: 12px; }
  .share-btn span { display: none; } /* icon only on mobile */
  .share-btn svg { width: 20px; height: 20px; }

  .perfect {
    border-radius: 0;
    max-width: 100%;
    width: 100%;
    max-height: 100dvh;
    padding: 32px 20px 24px;
  }
  .perfect__title { font-size: 44px; }
}

/* Force mobile board visible on desktop when editing mobile layout
   — MUST match the real mobile frame exactly (aspect-ratio 1080/1920
   + object-fit: fill) so calibration coords translate 1:1 to real mobile. */
.app.force-mobile-preview .board { display: none !important; }
.app.force-mobile-preview .bingo { display: none !important; }

.force-mobile-preview.app {
  grid-template-columns: 1fr 360px !important;
}

.force-mobile-preview .board-mobile {
  grid-area: board;
  display: flex !important;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: calc(100vh - 72px);
  border-left: 2px solid rgba(32,176,208,0.3);
  border-right: 2px solid rgba(32,176,208,0.3);
}
.force-mobile-preview .board-mobile__frame {
  /* Identical sizing rule to real-mobile (@media max-width:767) */
  width: min(414px, calc((100vh - 72px) * (1080 / 1920)));
  height: auto;
  aspect-ratio: 1080 / 1920;
  max-height: calc(100vh - 72px);
  flex: none;
}
.force-mobile-preview .board-mobile__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  object-position: center;
}
