/* ════════════════════════════════════════════════════════════
   SUB ALERT FULL SCREEN (Session 7)
   #subAlertScreen — replaces the old #subSheet bottom sheet for
   scheduled sub windows. Auto-opens subAutoOpen seconds before
   the window (or on Sub Now tap), stays open through the zero
   crossing with copy/colour updates, dismissed via Skip /
   Confirm Sub / ✕ close.

   #subAlertEditSheet — bottom sheet launched from the ✏ Edit
   buttons inside #subAlertScreen. Reshapes pendingSubs all at
   once.

   Layered above the in-game UI but below recovery / modals:
     #subAlertScreen      z-index 800
     #subAlertEditSheet   z-index 900
     #recoveryOverlay     z-index 10003
     setup modals         z-index 10005
   ════════════════════════════════════════════════════════════ */

/* Full-screen container — slide up from bottom on open, slide
   down on close. JS toggles .active to drive the transition. */
#subAlertScreen.sub-alert-screen {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: #080808;
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#subAlertScreen.sub-alert-screen.visible { display: flex; }
#subAlertScreen.sub-alert-screen.active { transform: translateY(0); }

/* Background glow — radial orange wash that pulses while the
   screen is open. Pointer-events:none so it doesn't catch taps. */
#subAlertScreen.sub-alert-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse at 50% 25%,
    rgba(255,92,26,0.10) 0%,
    rgba(255,92,26,0.03) 55%,
    transparent 75%
  );
  animation: saGlow 2.2s ease-in-out infinite;
  z-index: 0;
}
@keyframes saGlow {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

/* ── Top bar ──────────────────────────────────────────────── */
#subAlertScreen .sa-top-bar {
  position: relative;
  z-index: 1;
  padding: 14px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
}
#subAlertScreen .sa-top-left { min-width: 0; }
#subAlertScreen .sa-status-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--amber);                 /* JS swaps to orange when sub window opens */
  transition: color 0.25s;
}
#subAlertScreen .sa-status-label.sub-open { color: var(--orange); }
#subAlertScreen .sa-auto-label {
  font-size: 9px;
  color: var(--sub);
  margin-top: 1px;
}
#subAlertScreen .sa-top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#subAlertScreen .sa-clock {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 16px;
  color: var(--sub);
  transition: color 0.25s;
}
#subAlertScreen .sa-clock.sub-open { color: var(--orange); }
#subAlertScreen .sa-close-btn {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--mid);
  border: none;
  color: var(--sub);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-appearance: none;
  appearance: none;
}

/* ── Sub countdown ──────────────────────────────────────────
   Sits between the top bar and the pairs list. Big amber
   M:SS that flips to "NOW" + orange pulse on zero crossing.
   Updated every tick by updateSubAlertTopBar in js/subs.js. */
#subAlertScreen .sa-countdown-section {
  position: relative;
  z-index: 1;
  padding: 10px 16px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}
#subAlertScreen .sa-countdown-label {
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--amber, #FF9900);
  margin-bottom: 2px;
  font-family: 'Barlow Condensed', sans-serif;
}
#subAlertScreen .sa-countdown-value {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 48px;
  font-weight: 900;
  letter-spacing: -1px;
  line-height: 0.9;
  color: var(--amber, #FF9900);
}
#subAlertScreen .sa-countdown-section.sub-open .sa-countdown-label {
  color: var(--orange, #FF5C1A);
}
#subAlertScreen .sa-countdown-section.sub-open .sa-countdown-value {
  color: var(--orange, #FF5C1A);
  animation: saCountdownPulse 0.7s ease-in-out infinite;
}
@keyframes saCountdownPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

/* ── Content (pairs) ──────────────────────────────────────── */
#subAlertScreen .sa-content {
  position: relative;
  z-index: 1;
  padding: 12px 14px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#subAlertScreen .sa-pairs-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
#subAlertScreen .sa-pairs-label {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--sub);
}
#subAlertScreen .sa-pairs-list {
  background: var(--card, #161616);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

/* Pair rows — JS injects the markup; row height + name size
   scale with pair count (5 sizes for 1-5 pairs). The .sa-pair-*
   inline elements are styled here so JS only has to set the
   text + scaling vars. */
#subAlertScreen .sa-pair-row {
  display: grid;
  grid-template-columns: 1fr 28px 1fr;
  align-items: center;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
}
#subAlertScreen .sa-pair-row:last-child { border-bottom: none; }
#subAlertScreen .sa-pair-row.dimmed { opacity: 0.3; transition: opacity 0.3s; }
/* Tappable row — opens the edit sheet pre-expanded on this pair.
   Subtle background tint on press so the tap registers visually
   without cluttering the row in its idle state. position:relative
   anchors the absolute-positioned ✕ cancel button. */
#subAlertScreen .sa-pair-row.tappable {
  cursor: pointer;
  transition: background 0.12s;
  -webkit-tap-highlight-color: rgba(255, 92, 26, 0.08);
  position: relative;
}
#subAlertScreen .sa-pair-row.tappable:active {
  background: rgba(255, 255, 255, 0.04);
}
/* Cancel-pair ✕ — top-right of each row. Larger hit target
   (28px) than visible glyph; muted by default so it doesn't
   compete with the OFF/ON dots. Reds up on press. */
#subAlertScreen .sa-pair-cancel {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border, #242424);
  border-radius: 6px;
  color: var(--muted, #888);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: rgba(239, 68, 68, 0.2);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  z-index: 2;
}
#subAlertScreen .sa-pair-cancel:active {
  background: rgba(239, 68, 68, 0.12);
  color: var(--red, #EF4444);
  border-color: rgba(239, 68, 68, 0.4);
}

#subAlertScreen .sa-pair-off,
#subAlertScreen .sa-pair-on {
  display: flex;
  align-items: center;
  gap: 7px;
  border-radius: 8px;
  padding: 7px 8px;
  height: calc(100% - 12px);
  box-sizing: border-box;
  min-width: 0;
}
#subAlertScreen .sa-pair-off {
  background: rgba(239,68,68,0.07);
  border: 1px solid rgba(239,68,68,0.18);
  margin-right: 4px;
}
#subAlertScreen .sa-pair-on {
  background: rgba(61,191,108,0.07);
  border: 1px solid rgba(61,191,108,0.18);
  justify-content: flex-end;
  margin-left: 4px;
}

#subAlertScreen .sa-pair-name {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  color: var(--white);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.1;
  /* font-size set inline by JS based on pair count */
}
#subAlertScreen .sa-pair-time {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#subAlertScreen .sa-pair-time.off { color: rgba(239,68,68,0.55); }
#subAlertScreen .sa-pair-time.on  { color: rgba(61,191,108,0.55); }

#subAlertScreen .sa-pair-text-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#subAlertScreen .sa-pair-text-col.right {
  align-items: flex-end;
  text-align: right;
}

#subAlertScreen .sa-pair-arrow-dot {
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  /* width/height + font-size set inline by JS based on pair count */
}
#subAlertScreen .sa-pair-arrow-dot.off {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.25);
  color: var(--red);
}
#subAlertScreen .sa-pair-arrow-dot.on {
  background: rgba(61,191,108,0.12);
  border: 1px solid rgba(61,191,108,0.25);
  color: var(--green);
}
#subAlertScreen .sa-arrow {
  text-align: center;
  font-size: 12px;
  color: var(--mid);
}

/* ── Bottom button block ──────────────────────────────────── */
/* Sits DIRECTLY below the pairs list rather than pinned to
   the screen bottom. Matches the mockup ("BUTTONS — directly
   below pairs, no gap") and avoids iOS home-indicator overlap
   making the labels hard to read. The screen's own
   safe-area-inset-bottom padding handles the gesture region. */
#subAlertScreen .sa-bottom {
  position: relative;
  z-index: 1;
  padding: 12px 14px 16px;
  background: #080808;
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
}
#subAlertScreen .sa-secondary-row {
  display: flex;
  gap: 7px;
}
#subAlertScreen .sa-edit-subs-btn {
  flex: 1;
  padding: 10px 0;
  border-radius: 9px;
  background: rgba(255,153,0,0.07);
  border: 1px solid rgba(255,153,0,0.20);
  color: var(--amber);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 1px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
#subAlertScreen .sa-skip-btn {
  flex: 1;
  padding: 10px 0;
  border-radius: 9px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--sub);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 1px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
#subAlertScreen .sa-confirm-btn {
  width: 100%;
  padding: 18px 0;
  border-radius: 13px;
  border: none;
  background: var(--orange);
  color: var(--white);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 1.5px;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(255,92,26,0.18);
  transition: background 0.3s, transform 0.15s, box-shadow 0.3s;
  -webkit-appearance: none;
  appearance: none;
}
#subAlertScreen .sa-confirm-btn:disabled { cursor: default; }
#subAlertScreen .sa-confirm-btn.sub-open {
  box-shadow: 0 0 28px rgba(255,92,26,0.50);
  animation: saConfirmPulse 1.6s ease-in-out infinite;
}
@keyframes saConfirmPulse {
  0%, 100% { box-shadow: 0 0 22px rgba(255,92,26,0.40); }
  50%      { box-shadow: 0 0 42px rgba(255,92,26,0.72); }
}
#subAlertScreen .sa-confirm-btn.confirming { transform: scale(0.97); }
#subAlertScreen .sa-confirm-btn.confirmed {
  background: var(--green);
  box-shadow: 0 0 40px rgba(61,191,108,0.50);
  animation: none;
}

/* ════════════════════════════════════════════════════════════
   EDIT SHEET — bottom sheet launched from the ✏ Edit buttons.
   ════════════════════════════════════════════════════════════ */
#subAlertEditSheet.sa-edit-sheet {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
}
#subAlertEditSheet.sa-edit-sheet.visible { display: flex; }
#subAlertEditSheet .sa-edit-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
}
#subAlertEditSheet .sa-edit-panel {
  position: relative;
  background: #131313;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  max-height: 72dvh;
  display: flex;
  flex-direction: column;
}
#subAlertEditSheet .sa-edit-handle {
  width: 32px;
  height: 4px;
  margin: 10px auto 4px;
  border-radius: 2px;
  background: var(--border);
  flex-shrink: 0;
}
#subAlertEditSheet .sa-edit-title {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--sub);
  text-align: center;
  margin-bottom: 12px;
  flex-shrink: 0;
}
#subAlertEditSheet .sa-edit-pairs {
  overflow-y: auto;
  flex: 1;
  padding: 0 14px;
}

/* Edit-sheet pair rows — collapsible. JS toggles .expanded
   to reveal the per-pair player picker grid. */
#subAlertEditSheet .sa-edit-pair {
  margin-bottom: 8px;
}
#subAlertEditSheet .sa-edit-pair-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card, #161616);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}
#subAlertEditSheet .sa-edit-pair.expanded .sa-edit-pair-row {
  background: rgba(255,92,26,0.06);
  border-color: rgba(255,92,26,0.25);
  border-radius: 10px 10px 0 0;
}
#subAlertEditSheet .sa-edit-pair-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  flex-shrink: 0;
}
#subAlertEditSheet .sa-edit-pair-dot.off {
  background: rgba(239,68,68,0.10);
  border: 1px solid rgba(239,68,68,0.22);
  color: var(--red);
}
#subAlertEditSheet .sa-edit-pair-dot.on {
  background: rgba(61,191,108,0.10);
  border: 1px solid rgba(61,191,108,0.22);
  color: var(--green);
}
#subAlertEditSheet .sa-edit-pair-name {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 16px;
  font-weight: 900;
  color: var(--white);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#subAlertEditSheet .sa-edit-pair-name.right { text-align: right; }
#subAlertEditSheet .sa-edit-pair-arrow {
  font-size: 11px;
  color: var(--border);
  flex-shrink: 0;
}
#subAlertEditSheet .sa-edit-pair-chev {
  font-size: 10px;
  color: var(--sub);
  margin-left: 4px;
  flex-shrink: 0;
}
#subAlertEditSheet .sa-edit-pair-remove {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--mid);
  border: none;
  color: var(--sub);
  font-size: 9px;
  cursor: pointer;
  margin-left: 4px;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
}

/* Expanded player-picker — two columns (off candidates / on
   candidates). JS injects the player buttons. */
#subAlertEditSheet .sa-edit-picker {
  display: none;
  background: #0F0F0F;
  border: 1px solid rgba(255,92,26,0.20);
  border-top: none;
  border-radius: 0 0 10px 10px;
  padding: 10px 12px 12px;
}
#subAlertEditSheet .sa-edit-pair.expanded .sa-edit-picker { display: block; }
#subAlertEditSheet .sa-edit-picker-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: start;
}
#subAlertEditSheet .sa-edit-picker-col-label {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
#subAlertEditSheet .sa-edit-picker-col-label.off {
  color: rgba(239,68,68,0.55);
}
#subAlertEditSheet .sa-edit-picker-col-label.on {
  color: rgba(61,191,108,0.55);
}
#subAlertEditSheet .sa-edit-picker-arrow {
  padding-top: 20px;
  color: var(--border);
  font-size: 14px;
  text-align: center;
}
#subAlertEditSheet .sa-edit-picker-btn {
  display: block;
  width: 100%;
  padding: 7px 8px;
  border-radius: 7px;
  margin-bottom: 4px;
  background: var(--raised, #1C1C1C);
  border: 1px solid var(--border);
  color: var(--sub);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 800;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
#subAlertEditSheet .sa-edit-picker-btn.selected.off {
  background: rgba(239,68,68,0.12);
  border-color: rgba(239,68,68,0.30);
  color: var(--red);
}
#subAlertEditSheet .sa-edit-picker-btn.selected.on {
  background: rgba(61,191,108,0.10);
  border-color: rgba(61,191,108,0.28);
  color: var(--green);
}
/* In-use guard — player already chosen on this side in another
   pair. Greyed + untappable; "(in use)" tag rendered inline. */
#subAlertEditSheet .sa-edit-picker-btn.disabled,
#subAlertEditSheet .sa-edit-picker-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* Self-sub inline warning. Hidden by default; .show fades it in
   for ~2s before _flashSelfSubWarn timer clears the state and
   triggers a re-render. */
#subAlertEditSheet .sa-edit-self-warn {
  display: none;
  font-size: 10px;
  color: var(--red);
  margin: 0 0 8px;
  padding: 4px 8px;
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: 5px;
  letter-spacing: 0.2px;
  animation: sa-self-warn-fade 2s ease forwards;
}
#subAlertEditSheet .sa-edit-self-warn.show { display: block; }
@keyframes sa-self-warn-fade {
  0%   { opacity: 0; transform: translateY(-2px); }
  10%  { opacity: 1; transform: translateY(0); }
  85%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Edit sheet actions — Add Another Sub + Save. Sits OUTSIDE
   the scrollable .sa-edit-pairs region (flex-shrink:0) so the
   Save button is always visible regardless of pair count.
   Background colour matches the panel so the row reads as a
   pinned footer over the scroll edge. */
#subAlertEditSheet .sa-edit-actions {
  flex-shrink: 0;
  padding: 10px 14px 28px;
  border-top: 1px solid #242424;
  background: #131313;
}
#subAlertEditSheet .sa-add-pair-btn {
  width: 100%;
  padding: 10px 0;
  border-radius: 10px;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--sub);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 1px;
  cursor: pointer;
  margin-bottom: 12px;
  -webkit-appearance: none;
  appearance: none;
}
#subAlertEditSheet .sa-save-btn {
  width: 100%;
  padding: 14px 0;
  border-radius: 12px;
  background: var(--orange);
  border: none;
  color: var(--white);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 1px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
