/* Small, conservative layout layer for smart-TV browsers and odd aspect ratios. */
.tv-stage {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: var(--tv-width, 100vw);
  height: var(--tv-height, 100vh);
  min-height: 0 !important;
  overflow: hidden;
  background: #101c44;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tv-slide-layer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.tv-slide {
  box-sizing: border-box;
  width: 100% !important;
  height: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  max-height: none !important;
  overflow: hidden !important;
}

.tv-trains {
  padding: 2vh 3vw !important;
}

.tv-trains-content {
  width: 94%;
  max-width: none;
  padding-bottom: 9vh;
}

/* Explicit pixel values keep core train text legible in older TV engines. */
.tv-trains-station-name {
  font-size: 48px;
  font-size: clamp(1.8rem, 2.8vw, 3rem);
}

.tv-trains-window {
  font-size: 32px;
  font-size: clamp(1.25rem, 1.9vw, 2rem);
}

.tv-train-card time {
  font-size: 44px;
  font-size: clamp(1.65rem, 2.5vw, 2.7rem);
}

.tv-train-destination {
  font-size: 26px;
  font-size: clamp(1rem, 1.55vw, 1.65rem);
}

.tv-train-card-copy {
  display: flex;
  min-height: 0;
  flex-direction: column;
  justify-content: center;
  line-height: 1.15;
}

.tv-train-time-block time {
  display: block;
  white-space: nowrap;
}

.tv-train-time-block .tv-train-card-type {
  white-space: nowrap;
}

.tv-train-card-title {
  min-height: 1.35em;
  line-height: 1.1;
}

.tv-train-card-title h2 {
  line-height: 1.1;
}

.tv-train-card-title span {
  padding-top: 0.3em !important;
  padding-bottom: 0.3em !important;
  line-height: 1;
}

.tv-train-card-type {
  margin-top: 0.1em !important;
  line-height: 1.15;
}

.tv-train-details {
  margin-top: 0.3em !important;
  line-height: 1.15 !important;
}

.tv-traffic-incidents-grid {
  display: grid;
  grid-auto-flow: row;
}

.tv-traffic-incident-copy {
  gap: 0.18em;
}

/* Large landscape TVs need signage-sized type and less unused canvas. */
@media (orientation: landscape) and (min-height: 600px) {
  .tv-trains-content {
    width: 96%;
    padding-bottom: 10vh;
  }

  .tv-trains header {
    height: 7vh !important;
    min-height: 62px;
  }

  .tv-trains .tv-trains-heading {
    height: 9vh !important;
    min-height: 78px;
  }

  .tv-trains .tv-trains-list {
    gap: 0.85vh 1vw;
    padding-top: 1vh;
  }

  .tv-trains .tv-trains-list article time {
    font-size: 52px !important;
    font-size: clamp(2rem, 2.8vw, 3.2rem) !important;
  }

  .tv-trains .tv-trains-list article h2 {
    font-size: 32px !important;
    font-size: clamp(1.2rem, 1.75vw, 2rem) !important;
  }

  .tv-trains .tv-trains-list article span {
    font-size: clamp(0.8rem, 0.9vw, 1rem) !important;
  }

  .tv-trains .tv-train-card-type {
    font-size: 19px !important;
    font-size: clamp(1rem, 1.1vw, 1.25rem) !important;
  }

  .tv-trains .tv-train-details {
    font-size: 17px !important;
    font-size: clamp(0.9rem, 0.98vw, 1.1rem) !important;
  }

  .tv-weather > div.relative {
    width: 100%;
    max-width: 1680px;
  }

  .tv-weather .text-xs {
    font-size: clamp(0.85rem, 0.9vw, 1rem) !important;
  }

  .tv-weather .text-sm {
    font-size: clamp(0.95rem, 1.05vw, 1.15rem) !important;
  }

  .tv-weather .text-base {
    font-size: clamp(1.05rem, 1.2vw, 1.3rem) !important;
  }

  .tv-weather .text-lg {
    font-size: clamp(1.15rem, 1.35vw, 1.5rem) !important;
  }

  .tv-weather .text-2xl {
    font-size: clamp(1.6rem, 1.9vw, 2.1rem) !important;
  }

  .tv-traffic-updates-layout {
    margin-bottom: 13vh !important;
    gap: 1vw;
    padding: 1.2vh 1.5vw;
  }

  .tv-traffic-incident-copy > p:first-child {
    font-size: clamp(1.05rem, 1.35vw, 1.45rem) !important;
  }

  .tv-traffic-incident-copy > p:nth-child(2) {
    font-size: clamp(0.9rem, 1.05vw, 1.1rem) !important;
  }

  .tv-traffic-incident-copy > p:last-child {
    font-size: clamp(0.8rem, 0.9vw, 1rem) !important;
  }

  .tv-traffic-updates-layout section:first-child article > span {
    font-size: clamp(1rem, 1.15vw, 1.25rem) !important;
  }

  .tv-traffic-updates-layout section:first-child article > div:first-of-type > p:first-child {
    font-size: clamp(1rem, 1.25vw, 1.35rem) !important;
  }

  .tv-traffic-updates-layout section:first-child article > div:first-of-type > p:nth-child(2) {
    font-size: clamp(0.9rem, 1vw, 1.1rem) !important;
  }
}

.tv-slide *,
.tv-stage * {
  box-sizing: border-box;
}

.tv-slide img,
.tv-stage img,
.tv-slide video,
.tv-stage video {
  max-width: 100%;
}

/* Browser zoom reduces the CSS viewport. Keep the dynamic slides inside the
   visible TV safe area at 125% and 150%, without depending on clamp(). */
@media (orientation: landscape) and (max-height: 900px) {
  .tv-trains {
    padding: 1.2vh 2.4vw !important;
  }

  .tv-trains-content {
    width: 97%;
    padding-bottom: 13vh !important;
  }

  .tv-trains header {
    height: 6vh !important;
    min-height: 42px !important;
    padding-bottom: 0.6vh;
  }

  .tv-trains header img {
    max-height: 30px;
  }

  .tv-trains header p {
    font-size: 12px !important;
    line-height: 1.2;
  }

  .tv-trains .tv-trains-heading {
    height: 8vh !important;
    min-height: 60px !important;
  }

  .tv-trains-station-name {
    font-size: 34px !important;
    line-height: 1.05;
  }

  .tv-trains-window {
    font-size: 24px !important;
  }

  .tv-trains .tv-trains-heading p {
    font-size: 12px !important;
    line-height: 1.2;
  }

  .tv-trains .tv-trains-list {
    gap: 5px 0.8vw;
    padding-top: 0.5vh;
    padding-bottom: 0;
  }

  .tv-trains .tv-trains-list article {
    gap: 0.7vw;
    padding: 4px 0.75vw;
    border-radius: 9px;
  }

  .tv-trains .tv-trains-list article time {
    font-size: 30px !important;
    line-height: 1.05;
  }

  .tv-trains .tv-trains-list article h2 {
    font-size: 22px !important;
    line-height: 1.1;
  }

  .tv-trains .tv-trains-list article span {
    font-size: 11px !important;
    padding: 4px 6px !important;
  }

  .tv-trains .tv-train-card-type {
    margin-top: 2px !important;
    font-size: 12px !important;
  }

  .tv-trains .tv-train-details {
    display: block !important;
    margin-top: 2px !important;
    font-size: 11px !important;
    line-height: 1.1 !important;
  }

  .tv-weather {
    align-items: flex-start !important;
    padding: 1.2vh 2.4vw 13vh !important;
  }

  .tv-weather > div.relative {
    max-width: none;
    display: flex;
    height: 100%;
    flex-direction: column;
  }

  .tv-weather header {
    margin-bottom: 1.3vh !important;
    padding-bottom: 0.8vh !important;
  }

  .tv-weather header img {
    max-height: 30px;
  }

  .tv-weather header p {
    font-size: 12px !important;
    line-height: 1.2;
  }

  .tv-weather > div.relative > div.grid {
    flex: 1;
    align-items: stretch;
    gap: 1.2vh !important;
  }

  .tv-weather section {
    min-height: 0 !important;
    border-radius: 16px !important;
    padding: 1.2vh 1.2vw !important;
  }

  .tv-weather > div.relative > div.grid > div.flex {
    min-height: 0;
  }

  .tv-weather > div.relative > div.grid > div.flex > section {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
  }

  .tv-weather > div.relative > div.grid > div.flex > section > div.grid {
    flex: 1;
    align-items: stretch;
  }

  .tv-weather > div.relative > div.grid > div.flex > section > div.grid > article {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .tv-weather > div.relative > div.grid > div.flex > section > div.divide-y {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-around;
  }

  .tv-weather section p {
    line-height: 1.15;
  }

  .tv-weather .text-7xl,
  .tv-weather .text-8xl {
    font-size: 52px !important;
  }

  .tv-weather .text-4xl {
    font-size: 27px !important;
  }

  .tv-weather .text-3xl {
    font-size: 24px !important;
  }

  .tv-weather .text-2xl {
    font-size: 21px !important;
  }

  .tv-weather .text-xl {
    font-size: 18px !important;
  }

  .tv-weather .text-lg {
    font-size: 15px !important;
  }

  .tv-weather .text-base {
    font-size: 14px !important;
  }

  .tv-weather .text-sm {
    font-size: 12px !important;
  }

  .tv-weather .text-xs {
    font-size: 10px !important;
  }

  .tv-weather article {
    padding-top: 0.7vh !important;
    padding-bottom: 0.7vh !important;
  }

  .tv-weather footer {
    margin-top: 0.6vh !important;
    font-size: 10px !important;
  }

  .tv-traffic-updates-layout {
    margin-bottom: 13vh !important;
    gap: 0.8vw;
    padding: 1vh 1.3vw;
  }

  .tv-traffic-updates header {
    height: 9vh !important;
    min-height: 52px !important;
    padding-right: 2vw;
    padding-left: 2vw;
  }

  .tv-traffic-updates header img {
    max-height: 30px;
  }

  .tv-traffic-updates header h1 {
    font-size: 22px !important;
  }

  .tv-traffic-updates header p,
  .tv-traffic-updates header span {
    font-size: 10px !important;
  }

  .tv-traffic-updates-layout section > div:first-child {
    padding: 0.8vh 1vw;
  }

  .tv-traffic-updates-layout section h2 {
    font-size: 17px !important;
  }

  .tv-traffic-updates-layout section:first-child article {
    gap: 8px;
    padding-right: 0.8vw;
    padding-left: 0.8vw;
  }

  .tv-traffic-updates-layout section:first-child article > span {
    width: 42px;
    height: 32px;
    font-size: 12px !important;
  }

  .tv-traffic-updates-layout section:first-child article > div:first-of-type > p:first-child {
    font-size: 13px !important;
  }

  .tv-traffic-updates-layout section:first-child article > div:first-of-type > p:nth-child(2) {
    margin-top: 2px;
    font-size: 11px !important;
  }

  .tv-traffic-updates-layout section:first-child article > div:last-of-type p:first-child {
    font-size: 14px !important;
  }

  .tv-traffic-updates-layout section:first-child article > div:last-of-type p:last-child {
    font-size: 9px !important;
  }

  .tv-traffic-incident {
    grid-template-columns: 2.75rem minmax(0, 1fr) !important;
    gap: 7px;
    padding-right: 0.8vw;
    padding-left: 0.8vw;
  }

  .tv-traffic-incident > span {
    width: 42px;
    height: 32px;
    font-size: 12px !important;
  }

  .tv-traffic-incident-copy > p:first-child {
    font-size: 13px !important;
  }

  .tv-traffic-incident-copy > p:nth-child(2) {
    font-size: 11px !important;
  }

  .tv-traffic-incident-copy > p:last-child {
    font-size: 10px !important;
  }

  .tv-traffic-layout {
    margin-bottom: 13vh !important;
  }
}

/* Keep the clock and refresh control inside the visible safe area. */
@media (max-width: 900px), (max-height: 620px) {
  .tv-stage [aria-label="Local time and date"] {
    left: 12px !important;
    bottom: 12px !important;
    padding: 8px 10px !important;
    border-radius: 9px !important;
  }

  .tv-stage [aria-label="Local time and date"] time {
    min-width: 0 !important;
    font-size: 23px !important;
  }

  .tv-stage [aria-label="Local time and date"] p {
    margin-top: 4px !important;
    font-size: 11px !important;
  }

  .tv-stage button[aria-label="Refresh slides from the server"] {
    right: 12px !important;
    bottom: 12px !important;
    min-width: 40px;
    min-height: 40px;
  }
}

/* Short screens need compact train rows; preserve the key departure details. */
@media (max-height: 900px) {
  .tv-trains header {
    height: 6vh !important;
    min-height: 38px;
  }

  .tv-trains header img {
    max-height: 24px;
  }

  .tv-trains .tv-trains-heading {
    height: 9vh !important;
    min-height: 58px;
  }

  .tv-trains .tv-train-details {
    display: block !important;
  }

  .tv-trains .tv-trains-list article time {
    font-size: 30px !important;
    font-size: clamp(18px, 2.3vh, 26px) !important;
  }

  .tv-trains .tv-trains-list article h2 {
    font-size: 22px !important;
    font-size: clamp(15px, 2vh, 22px) !important;
  }

  .tv-trains .tv-trains-content {
    padding-bottom: 13vh !important;
  }

  .tv-traffic header,
  .tv-traffic-updates header {
    min-height: 54px !important;
  }

  .tv-weather {
    padding-bottom: 13vh !important;
  }

  .tv-weather section {
    min-height: 0 !important;
  }
}

/* Tall portrait displays get a single readable train column. */
@media (orientation: portrait) and (min-height: 700px) {
  .tv-trains .tv-trains-list {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: repeat(10, minmax(0, 1fr)) !important;
    gap: 5px !important;
  }

  .tv-trains .tv-trains-list article {
    min-height: 0;
    padding-right: 10px;
    padding-left: 12px;
  }

  .tv-trains .tv-trains-list article time {
    font-size: clamp(18px, 2.7vh, 30px) !important;
  }

  .tv-trains .tv-trains-list article h2 {
    font-size: clamp(15px, 2.2vh, 24px) !important;
  }

  .tv-trains .tv-trains-list article span {
    font-size: 11px;
  }

  .tv-trains .tv-train-details {
    font-size: 11px;
  }

  .tv-traffic-layout,
  .tv-traffic-updates-layout {
    margin-bottom: 9vh !important;
  }
}

/* The 4:3 and 16:10 modes keep the same composition; just tighten gutters. */
@media (min-width: 900px) and (max-width: 1300px) and (min-height: 650px) {
  .tv-traffic-layout {
    grid-template-columns: minmax(300px, 34vw) minmax(0, 1fr) !important;
  }
}

/* Readable type at common TV browser zoom settings (100%, 125%, and 150%).
   Fixed sizes are intentional: some built-in TV browsers under-apply clamp(). */
@media (orientation: landscape) and (max-height: 900px) {
  .tv-trains .tv-trains-list article time {
    font-size: 29px !important;
  }

  .tv-trains .tv-trains-list article h2 {
    font-size: 24px !important;
  }

  .tv-trains .tv-trains-list article span {
    font-size: 12px !important;
  }

  .tv-trains .tv-train-card-type {
    font-size: 14px !important;
  }

  .tv-trains .tv-train-details {
    font-size: 13px !important;
    line-height: 1.2 !important;
  }

  .tv-trains .tv-trains-heading p {
    font-size: 14px !important;
  }

  .tv-weather .text-7xl,
  .tv-weather .text-8xl {
    font-size: 68px !important;
  }

  .tv-weather .text-4xl {
    font-size: 36px !important;
  }

  .tv-weather .text-3xl {
    font-size: 30px !important;
  }

  .tv-weather .text-2xl {
    font-size: 25px !important;
  }

  .tv-weather .text-xl {
    font-size: 21px !important;
  }

  .tv-weather .text-lg {
    font-size: 18px !important;
  }

  .tv-weather .text-base {
    font-size: 16px !important;
  }

  .tv-weather .text-sm {
    font-size: 14px !important;
  }

  .tv-weather .text-xs {
    font-size: 12px !important;
  }

  .tv-weather footer {
    font-size: 12px !important;
  }
}

@media (orientation: landscape) and (max-height: 760px) {
  .tv-trains .tv-trains-list article time {
    font-size: 26px !important;
  }

  .tv-trains .tv-trains-list article h2 {
    font-size: 22px !important;
  }

  .tv-trains .tv-train-card-type {
    font-size: 13px !important;
  }

  .tv-trains .tv-train-details {
    font-size: 12px !important;
  }

  .tv-weather .text-7xl,
  .tv-weather .text-8xl {
    font-size: 58px !important;
  }

  .tv-weather .text-4xl {
    font-size: 32px !important;
  }

  .tv-weather .text-3xl {
    font-size: 27px !important;
  }

  .tv-weather .text-2xl {
    font-size: 23px !important;
  }

  .tv-weather .text-xl {
    font-size: 19px !important;
  }

  .tv-weather .text-lg {
    font-size: 16px !important;
  }

  .tv-weather .text-base {
    font-size: 15px !important;
  }

  .tv-weather .text-sm {
    font-size: 13px !important;
  }

  .tv-weather .text-xs {
    font-size: 11px !important;
  }
}
