/* The TV Guide's layout: an info panel over a channel grid, filling the screen like a cable
   listings channel. Colors and fonts are variables, set in theme.css. */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; color-scheme: dark; background-color: var(--bg); }

body {
  margin: 0;
  background:
    repeating-linear-gradient(0deg, rgb(255 255 255 / 0.02) 0 1px, transparent 1px 3px),
    var(--bg);
  color: var(--text);
  font: 500 16px/1.3 var(--body);
  overflow: hidden;
}

a { color: var(--muted); }

.tv {
  --station-w: clamp(96px, 12vw, 180px);
  --row-h: clamp(56px, 9vh, 96px);
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas: "info logo" "banner banner" "grid grid" "footer footer";
  gap: 10px 20px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.placeholder { margin: 0; color: var(--muted); font-size: 1.2rem; padding: 16px; }

/* The info panel --------------------------------------------------------- */

.info {
  grid-area: info;
  display: flex;
  gap: 20px;
  align-items: flex-start;
  min-height: clamp(120px, 26vh, 260px);
  max-height: 32vh;
  overflow: hidden;
}

.info-pic { flex: none; height: clamp(110px, 25vh, 250px); aspect-ratio: 16 / 9; }

.info-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 3px solid var(--frame-edge);
  border-radius: 6px;
  box-shadow: 4px 4px 0 var(--shadow);
  background: var(--cell-empty);
}

.info-image.poster { object-fit: contain; }

.info-text { min-width: 0; }

.info-station {
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: clamp(14px, 1.6vw, 22px);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.info-num {
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--frame);
  color: var(--text);
  font-family: var(--display);
}

.info-live {
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--now-line);
  color: #fff;
  font-weight: 700;
  font-size: 0.8em;
}

.info-show {
  margin: 0;
  font: 400 clamp(22px, 3.2vw, 46px)/1.1 var(--display);
  color: var(--select);
  text-shadow: 3px 3px 0 var(--shadow);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.info-episode { margin: 6px 0 0; font-size: clamp(16px, 1.9vw, 26px); font-weight: 700; }

.info-episode .code { color: var(--muted); margin-right: 10px; }

.info-times { margin: 4px 0 0; color: var(--muted); font-size: clamp(14px, 1.5vw, 20px); }

.info-overview {
  margin: 6px 0 0;
  font-weight: 400;
  font-size: clamp(14px, 1.5vw, 20px);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.logo {
  grid-area: logo;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font: 400 clamp(28px, 4.5vw, 64px)/0.95 var(--display);
  text-transform: uppercase;
  color: var(--select);
  text-shadow: 4px 4px 0 var(--shadow);
}

.logo span:last-child { color: var(--text); font-size: 0.62em; }

.banner {
  grid-area: banner;
  margin: 0;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--now-line);
  font-weight: 700;
}

/* The grid --------------------------------------------------------------- */

.grid {
  grid-area: grid;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 4px solid var(--frame-edge);
  border-radius: 8px;
  background: var(--frame);
  box-shadow: 6px 6px 0 var(--shadow);
  overflow: hidden;
}

.grid-head {
  display: grid;
  grid-template-columns: var(--station-w) 1fr;
  background: var(--header);
  border-bottom: 3px solid var(--frame-edge);
}

.corner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  border-right: 3px solid var(--frame-edge);
  background: var(--frame);
}

.corner-date { font-size: clamp(11px, 1.1vw, 15px); color: var(--muted); text-transform: uppercase; }

.corner-time { font: 400 clamp(16px, 1.9vw, 28px)/1.1 var(--display); color: var(--select); white-space: nowrap; }

.slots { position: relative; }

.slot-times { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; height: 100%; }

.slot-time {
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-left: 2px solid var(--frame-edge);
  font: 400 clamp(16px, 2vw, 30px)/1 var(--display);
  text-shadow: 2px 2px 0 var(--shadow);
}

.slot-time:first-child { border-left: 0; }

.page {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  padding: 4px 8px;
  background: none;
  color: var(--select);
  font-size: clamp(16px, 1.8vw, 26px);
  cursor: pointer;
}

.page:disabled { opacity: 0.25; cursor: default; }

.page-back { left: auto; right: 44px; }
.page-forward { right: 6px; }

.grid-body { position: relative; flex: 1; min-height: 0; }

.viewport { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; }

.viewport.rolling { overflow: hidden; }

.rows { will-change: transform; }

.row {
  display: grid;
  grid-template-columns: var(--station-w) 1fr;
  height: var(--row-h);
  border-bottom: 2px solid var(--frame-edge);
}

.station {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 6px;
  border-right: 3px solid var(--frame-edge);
  background: linear-gradient(180deg, var(--frame) 0%, var(--header) 100%);
  white-space: nowrap;
  overflow: hidden;
}

.station-num { font: 400 clamp(18px, 2.2vw, 32px)/1 var(--display); color: var(--select); text-shadow: 2px 2px 0 var(--shadow); }

.station-call { font-weight: 700; font-size: clamp(13px, 1.5vw, 22px); letter-spacing: 0.04em; }

.row.selected .station { background: var(--select); color: var(--ink-on-select); }
.row.selected .station-num { color: var(--ink-on-select); text-shadow: none; }

.track { position: relative; }

/* A program. The transparent border is the gap between neighbours. */
.cell {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: 2px 10px;
  border: 2px solid transparent;
  border-radius: 6px;
  background-clip: padding-box;
  box-shadow: inset 0 2px 0 rgb(255 255 255 / 0.22), inset 0 -3px 0 rgb(0 0 0 / 0.28);
  overflow: hidden;
  cursor: pointer;
  user-select: none;
}

.cell.tint-a { background-color: var(--cell-a); }
.cell.tint-b { background-color: var(--cell-b); }
.cell-gap, .cell-tba, .cell-off { background-color: var(--cell-empty); color: var(--muted); }

.cell-title, .cell-sub { overflow: hidden; text-overflow: ellipsis; }

.cell-title {
  font-weight: 700;
  font-size: clamp(14px, 1.7vw, 26px);
  line-height: 1.12;
  text-shadow: 2px 2px 0 rgb(0 0 0 / 0.45);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.cell-sub { font-weight: 400; font-size: clamp(12px, 1.2vw, 18px); color: var(--muted); white-space: nowrap; }

/* No room for the episode title under a two-line show name. */
@media (max-height: 760px) { .cell-sub { display: none; } }

/* ◀ ▶: the program started before the window, or runs past it. */
.cell.continues-left { padding-left: 26px; }
.cell.continues-right { padding-right: 26px; }

.cell.continues-left::before, .cell.continues-right::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9em;
}

.cell.continues-left::before { content: "◀"; left: 6px; }
.cell.continues-right::after { content: "▶"; right: 6px; }

.cell.selected {
  background-color: var(--select);
  color: var(--ink-on-select);
  box-shadow: inset 0 0 0 3px #fff;
}

.cell.selected .cell-title { text-shadow: none; }
.cell.selected .cell-sub { color: var(--ink-on-select); }

.now-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--station-w) + (100% - var(--station-w)) * var(--now, 0));
  width: 3px;
  margin-left: -1px;
  background: var(--now-line);
  box-shadow: 0 0 8px var(--now-line);
  pointer-events: none;
}

/* The footer ------------------------------------------------------------- */

.footer {
  grid-area: footer;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.footer p { margin: 0; }

.credit { text-align: right; }

/* Browsing with no keyboard to hand: the hint is about keys. */
@media (hover: none) { .hint { visibility: hidden; } }

/* Phones: the logo over the info panel, two half-hour columns (set in app.js). */
@media (max-width: 640px) {
  .tv {
    --station-w: 64px;
    --row-h: 60px;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto 1fr auto;
    grid-template-areas: "logo" "info" "banner" "grid" "footer";
    gap: 8px;
  }
  .logo { flex-direction: row; align-items: baseline; gap: 8px; }
  .info { flex-direction: column; gap: 8px; min-height: 0; max-height: 34vh; }
  .info-pic { height: auto; width: 45%; }
  .info:has(.info-pic) { flex-direction: row; }
  .info-overview { -webkit-line-clamp: 2; }
  .station { flex-direction: column; gap: 2px; }
  .corner-time { font-size: 13px; }
  .station-call { font-size: 11px; }
  .slot-time { padding: 0 8px; }
  .page-back { right: 34px; }
  .footer { flex-direction: column; gap: 2px; }
  .credit { text-align: left; }
  .hint { display: none; }
}
