/* ==========================================================================
   Sky News TV — mobile UI layer.
   Owned by mobile-ui.

   Contents:
     1. controls bar (2x2 portrait, one row landscape, safe areas)
     2. status card / retry sizing
     3. "Watch on TV" sheet (two honest paths)
     4. "Add it to your home screen" bottom sheet

   Base layout, tokens and the .btn primitive live in css/mobile.css.
   ========================================================================== */

/* ------------------------------- 1. controls ---------------------------- */

.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px calc(16px + var(--safe-right)) calc(14px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: linear-gradient(to top, rgba(2, 5, 9, 0.95) 0%, rgba(2, 5, 9, 0.74) 52%, rgba(2, 5, 9, 0) 100%);
  transform: translateY(16px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 240ms ease, transform 240ms ease, visibility 0s linear 240ms;
}

body.controls-visible .controls {
  opacity: 1;
  transform: none;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 240ms ease, transform 240ms ease, visibility 0s;
}

.controls-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 24px;
  padding: 0 4px;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  padding: 5px 11px 6px;
  border-radius: 999px;
  background: var(--live);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(225, 29, 46, 0.38);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  animation: live-pulse 2.2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.82); }
}

.now-playing {
  min-width: 0;
  max-width: 100%;
  color: var(--ink-dim);
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ctrl-btn {
  min-height: 54px;
  padding: 10px 12px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.ctrl-btn.is-off { color: var(--muted); }

/* "Back to live" is the one loud action in video mode: full width, accent. */
.ctrl-btn-accent {
  grid-column: 1 / -1;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* Landscape: controls sit in a single row and take less vertical space. */
@media (orientation: landscape) {
  .controls {
    gap: 8px;
    padding: 10px calc(16px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(16px + var(--safe-left));
  }

  .controls-status { min-height: 20px; }
  .now-playing { font-size: 14px; }

  .controls-buttons {
    display: flex;
    align-items: stretch;
    gap: 10px;
  }

  .ctrl-btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 52px;
    padding: 8px 10px;
  }

  .ctrl-btn-accent { flex: 1 1 0; }
}

/* Tiny landscape phones (iPhone SE on its side, 568x320): wrapping two rows
   is better than squeezing labels past the edge of the screen. */
@media (orientation: landscape) and (max-width: 660px) {
  .controls-buttons { flex-wrap: wrap; }
  .ctrl-btn { flex: 1 1 calc(50% - 5px); }
}

@media (orientation: landscape) and (max-height: 420px) {
  .controls { gap: 6px; padding-top: 8px; padding-bottom: calc(8px + var(--safe-bottom)); }
  .controls-status { min-height: 18px; }
  .live-badge { font-size: 12px; padding: 4px 9px 5px; }
  .now-playing { font-size: 13px; }
}

/* --------------------------- 2. status overlay -------------------------- */

.status-overlay .btn {
  min-width: 200px;
  min-height: 54px;
  font-size: 18px;
  font-weight: 700;
}

.status-overlay h2 { text-wrap: balance; }
.status-overlay p { text-wrap: pretty; }

/* --------------------------- 3. Watch on TV ----------------------------- */

.cast-guide {
  display: flex;
  flex-direction: column;
  padding: calc(10px + var(--safe-top)) calc(10px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(10px + var(--safe-left));
  background: var(--bg-deep);
}

.cg-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 5, 9, 0.92);
}

.cg-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 14px;
  gap: 10px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--panel-strong);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.cg-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.cg-back {
  flex: 0 0 auto;
  min-height: 48px;
  min-width: 96px;
  padding: 0 14px;
  border-radius: 12px;
  background: rgba(20, 34, 50, 0.92);
  font-size: 16px;
  font-weight: 700;
  gap: 5px;
}

.cg-back-icon { width: 20px; height: 20px; flex: 0 0 auto; }

.cg-titles { min-width: 0; }

.cg-titles h2 {
  margin: 0;
  font-size: clamp(20px, 5.6vw, 24px);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.cg-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.25;
}

.cg-body {
  display: grid;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.cg-path {
  display: grid;
  gap: 7px;
  align-content: start;
  padding: 9px;
  border-radius: 16px;
  background: rgba(10, 19, 30, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.cg-path-head {
  display: flex;
  align-items: center;
  gap: 9px;
}

.cg-letter {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.cg-path-title {
  margin: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  font-size: 16px;
  font-weight: 750;
  color: var(--ink);
  line-height: 1.2;
}

.cg-tag {
  padding: 2px 8px 3px;
  border-radius: 999px;
  background: rgba(53, 194, 242, 0.16);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 750;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.cg-art {
  display: block;
  width: 100%;
  height: auto;
  max-height: 160px;
  object-fit: contain;
  margin: 0 auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: #081019;
}

.cg-mirror-grid {
  display: grid;
  gap: 8px;
}

.cg-mirror { margin: 0; display: grid; }

/* Show the phone in the viewer's hand; the other one appears in landscape. */
.cast-guide[data-platform="ios"] .cg-mirror-android,
.cast-guide[data-platform="android"] .cg-mirror-ios { display: none; }

.cg-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.cg-steps li {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 15.5px;
  line-height: 1.38;
  color: var(--ink-dim);
}

.cg-steps strong { color: var(--ink); font-weight: 700; }

.cg-num {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  border-radius: 50%;
  background: rgba(53, 194, 242, 0.16);
  border: 1px solid rgba(53, 194, 242, 0.36);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.cg-foot { flex: 0 0 auto; }

.cg-honest {
  margin: 0;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 155, 140, 0.24);
  background: rgba(255, 155, 140, 0.08);
  color: #ffd9d3;
  font-size: 13px;
  line-height: 1.4;
}

@media (orientation: landscape) {
  .cast-guide {
    padding: calc(8px + var(--safe-top)) calc(8px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(8px + var(--safe-left));
  }

  .cg-panel {
    max-width: 1000px;
    gap: 8px;
    padding: 8px 12px;
  }

  .cg-body {
    grid-template-columns: 1fr 1fr;
    align-items: start;
    gap: 10px;
  }

  .cg-path { gap: 6px; padding: 7px; }
  .cg-path-title { font-size: 15px; }
  .cg-titles h2 { font-size: 21px; }
  .cg-sub { font-size: 12.5px; }
  .cg-back { min-height: 46px; min-width: 88px; font-size: 15px; }
  .cg-art { max-height: 140px; }
  .cg-steps { gap: 4px; }
  .cg-steps li { font-size: 14px; line-height: 1.3; }
  .cg-num { width: 19px; height: 19px; font-size: 11.5px; }
  .cg-honest { font-size: 12.5px; padding: 6px 10px; }
}

@media (orientation: landscape) and (max-height: 360px) {
  .cg-art { max-height: 104px; }
  .cg-steps li { font-size: 13px; }
  .cg-honest { font-size: 12px; }
}

/* ------------------- 4. "Add it to your home screen" -------------------- */

.install-hint {
  position: absolute;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.ih-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 5, 9, 0.66);
}

.ih-sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  margin: 0 auto;
  padding: 12px 18px calc(14px + var(--safe-bottom));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  background: var(--panel-strong);
  box-shadow: 0 -20px 55px rgba(0, 0, 0, 0.55);
  animation: ih-rise 260ms ease-out both;
}

@keyframes ih-rise {
  from { transform: translateY(26px); opacity: 0.5; }
  to { transform: none; opacity: 1; }
}

.ih-grabber {
  width: 40px;
  height: 4px;
  margin: 0 auto 10px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.22);
}

.ih-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}

.ih-close svg { width: 20px; height: 20px; }
.ih-close:active { background: rgba(255, 255, 255, 0.08); }
.ih-close:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.ih-title {
  margin: 0 46px 3px 0;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.ih-lead {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.3;
}

.ih-art {
  display: block;
  width: 100%;
  height: auto;
  max-height: 150px;
  object-fit: contain;
  margin: 0 0 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: #081019;
}

.ih-steps {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: grid;
  gap: 9px;
}

.ih-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.ih-num {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.ih-step-text {
  display: grid;
  gap: 1px;
  font-size: 16px;
  line-height: 1.35;
  color: var(--muted);
}

.ih-step-text strong {
  color: var(--ink);
  font-weight: 700;
}

.ih-cta {
  width: 100%;
  min-height: 54px;
  font-size: 18px;
  font-weight: 800;
}

.ih-later {
  width: 100%;
  min-height: 48px;
  margin-top: 8px;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.16);
  color: var(--ink-dim);
  font-size: 16px;
  font-weight: 650;
}

@media (orientation: landscape) {
  .install-hint {
    align-items: center;
    padding: calc(10px + var(--safe-top)) 12px calc(10px + var(--safe-bottom));
  }

  .ih-sheet {
    max-width: 760px;
    max-height: 100%;
    border-radius: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 14px 18px;
    display: grid;
    grid-template-columns: minmax(180px, 230px) minmax(0, 1fr);
    grid-template-areas:
      "art title"
      "art lead"
      "art steps"
      "art cta"
      "art later";
    align-content: center;
    column-gap: 18px;
    row-gap: 2px;
    animation-name: ih-fade;
  }

  .ih-grabber { display: none; }

  .ih-art {
    grid-area: art;
    align-self: center;
    margin: 0;
    max-height: 180px;
  }

  .ih-title { grid-area: title; font-size: 20px; margin-right: 46px; }
  .ih-lead { grid-area: lead; margin-bottom: 8px; font-size: 14px; }
  .ih-steps { grid-area: steps; margin-bottom: 10px; gap: 7px; }
  .ih-step-text { font-size: 15px; }
  .ih-cta { grid-area: cta; min-height: 50px; }
  .ih-later { grid-area: later; min-height: 44px; margin-top: 6px; }
}

@keyframes ih-fade {
  from { opacity: 0.4; }
  to { opacity: 1; }
}

/* Keyboard users get a clear ring everywhere. */
.cg-back:focus-visible,
.ctrl-btn:focus-visible,
.ih-cta:focus-visible,
.ih-later:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* A very narrow portrait phone still gets a readable controls bar. */
@media (max-width: 340px) {
  .controls { padding-left: calc(12px + var(--safe-left)); padding-right: calc(12px + var(--safe-right)); }
  .ctrl-btn { font-size: 16px; padding: 8px; }
}
