:root {
  --bg: #06131d;
  --text: #fff;
  --muted: #9fb5c3;
  --focus: #fff;
  --sidebar: 18vw;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
.screen {
  display: none;
  width: 100vw;
  height: 100vh;
  background: radial-gradient(circle at 80% 5%, #174d69 0, #0a2231 42%, #06131d 100%);
}
.screen.active { display: block; }
.center {
  text-align: center;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 4vh 5vw;
}
.center.active { display: flex; }
.brand { width: 28vw; max-width: 410px; height: auto; }
.brand.small { width: 18vw; max-width: 290px; }
.spinner {
  width: 54px;
  height: 54px;
  border: 6px solid rgba(255,255,255,0.145);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 28px;
}
@keyframes spin { to { transform: rotate(360deg); } }
h1 { font-size: 3vw; margin: 1.5vh 0; }
p { font-size: 1.35vw; }
.muted { color: var(--muted); }
.url { font-weight: 700; color: #8bd3f4; }
.pair-code {
  font-size: 6vw;
  font-weight: 900;
  letter-spacing: 1.3vw;
  margin: 1vh 0 2vh;
  padding: 1.5vh 2vw;
  background: #fff;
  color: #07131e;
  border-radius: 16px;
}
.status { color: #9ee7b0; }
button.focusable {
  background: #244c60;
  border-radius: 12px;
  padding: 16px 28px;
  font-weight: 800;
  outline: 0;
}
.focusable:focus, .focusable.focused {
  transform: scale(1.035);
  box-shadow: 0 0 0 4px var(--focus);
  z-index: 5;
}

.app-screen.active { display: flex; }
.sidebar {
  width: var(--sidebar);
  height: 100vh;
  padding: 3vh 1.2vw 2vh;
  background: linear-gradient(180deg, #0d2c3e, #071824);
  border-right: 1px solid rgba(255,255,255,0.094);
  display: flex;
  flex-direction: column;
}
.side-brand {
  width: 10vw;
  max-height: 15vh;
  object-fit: contain;
  align-self: center;
  margin-bottom: 2vh;
}
.sidebar nav { display: flex; flex-direction: column; }
.sidebar .nav-item {
  width: 100%;
  height: 7.4vh;
  margin-bottom: .7vh;
  padding: 0 1vw;
  background: transparent;
  border-radius: 10px;
  text-align: left;
  font-size: 1.58vw;
  font-weight: 800;
  color: #bdd0da;
  display: flex;
  align-items: center;
}
.sidebar .nav-item.active {
  background: linear-gradient(90deg, #1489b8, #17627f);
  color: #fff;
}
.nav-icon { width: 2.2vw; margin-right: .9vw; font-size: 1.9vw; text-align: center; }
.side-footer {
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,0.125);
  padding: 2vh .7vw 0;
  display: flex;
  flex-direction: column;
}
.side-footer strong {
  font-size: 1vw;
  margin-bottom: .5vh;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-footer span { font-size: 1.05vw; color: var(--muted); }
.page {
  width: calc(100vw - var(--sidebar));
  height: 100vh;
  padding: 3vh 3vw;
  overflow: hidden;
}

.page-header { height: 22vh; display: flex; align-items: center; }
.page-header small, .catalog-header small, .settings-header small {
  color: #65c8ed;
  font-weight: 800;
  letter-spacing: .12em;
}
.page-header h1 { font-size: 3.2vw; margin: .7vh 0; }
.page-header p { color: var(--muted); margin: .5vh 0; }
.menu-grid { display: flex; width: 100%; height: 70vh; }
.tile {
  width: calc(33.333% - 1vw);
  height: 66vh;
  margin-right: 1.5vw;
  text-align: left;
  border-radius: 20px;
  padding: 2vw;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  outline: 0;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.094);
  box-shadow: 0 20px 50px rgba(0,0,0,0.267);
}
.tile:last-child { margin-right: 0; }
.tile:before {
  content: "";
  position: absolute;
  z-index: 2;
  top: 0; right: 0; bottom: 0; left: 0;
  background: linear-gradient(180deg, transparent 38%, rgba(6,19,29,0.145) 58%, rgba(6,19,29,0.949) 100%);
}
.tile span, .tile small { position: relative; z-index: 3; }
.tile-art {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  object-fit: cover;
  opacity: .92;
  z-index: 1;
}
.tile span { font-size: 2.2vw; font-weight: 900; }
.tile small { font-size: 1.05vw; margin-top: 9px; opacity: .82; }
.tile.live { background: linear-gradient(155deg, #04977f, #06483f); }
.tile.movies { background: linear-gradient(155deg, #8347d1, #3c1f70); }
.tile.series { background: linear-gradient(155deg, #d34b58, #741e29); }

.catalog-page { padding-bottom: 2vh; }
.catalog-header { height: 11vh; display: flex; align-items: center; justify-content: space-between; }
.catalog-header h2 { font-size: 2.3vw; margin: .5vh 0; }
.catalog-tools { display: flex; align-items: center; }
.catalog-header #catalog-count { color: var(--muted); font-size: 1vw; min-width: 6vw; text-align: right; }
.catalog-search {
  width: 20vw;
  height: 5.4vh;
  margin-right: 1.2vw;
  padding: 0 .6vw 0 1vw;
  border: 1px solid rgba(255,255,255,0.188);
  border-radius: 28px;
  background: #0d2b3c;
  display: flex;
  align-items: center;
}
.search-icon {
  width: 1.05vw; height: 1.05vw; margin: 0 .65vw 0 .15vw;
  border: .16vw solid #75d4f5; border-radius: 50%; position: relative; flex: 0 0 auto;
}
.search-icon:after {
  content: ""; position: absolute; width: .55vw; height: .15vw;
  right: -.45vw; bottom: -.22vw; background: #75d4f5; transform: rotate(45deg); border-radius: 2px;
}
.catalog-search input {
  width: 100%; height: 4.2vh; padding: 0 .7vw; border: 0; outline: 0;
  border-radius: 20px; background: transparent; color: #fff; font-size: 1.05vw;
}
.catalog-search input::placeholder { color: #9bb2bf; }
.catalog-search:focus-within { box-shadow: 0 0 0 4px #fff; border-color: #fff; }
.catalog-search input:focus { transform: none; box-shadow: none; }
.search-clear {
  margin-right: .8vw; padding: 1vh .9vw !important; border-radius: 20px !important;
  background: #244c60 !important; color: #dce9ef; font-size: .82vw;
}
.catalog-body { height: 84vh; display: flex; min-width: 0; }
.category-list {
  width: 18vw;
  min-width: 18vw;
  height: 84vh;
  margin-right: 1.2vw;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding: .4vh .4vw 4vh .3vw;
  scrollbar-width: none;
}
.category-list::-webkit-scrollbar { display: none; }
.category {
  width: 100%;
  min-height: 6.2vh;
  margin-bottom: .7vh;
  white-space: normal;
  padding: 1vh .8vw !important;
  background: #15394d !important;
  color: #bdd0da;
  text-align: left;
  font-size: 1.34vw;
  line-height: 1.22;
  font-weight: 800;
}
.category.selected { background: #1686b1 !important; color: #fff; }
.catalog-grid {
  height: 84vh;
  min-width: 0;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  padding: .1vh .1vw 5vh;
  scroll-behavior: smooth;
}
.catalog-grid > p { width: 100%; color: var(--muted); font-size: 1.4vw; }
.card {
  width: calc(20% - .7vw);
  height: 31.5vh;
  margin: .35vw;
  min-width: 0;
  background: #17394c;
  border-radius: 12px;
  padding: 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  outline: 0;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.200);
}
.catalog-grid[data-type="live"] .card { width: calc(25% - .8vw); height: 20vh; }
.card-image {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #132f3f;
  opacity: 1;
  transition: opacity .18s ease;
}
.card-image.image-pending { opacity: 0; }
.card-vod .card-image, .card-series .card-image { padding: .35vh .2vw 5.2vh; background: #102938; }
.card-live .card-image {
  object-fit: contain;
  width: 50%;
  height: 45%;
  top: 5%;
  left: 25%;
  right: auto;
  bottom: auto;
  padding: .5vh;
  background: transparent;
}
.card:before {
  content: "";
  position: absolute;
  z-index: 1;
  top: 35%;
  right: 0;
  bottom: 0;
  left: 0;
  background: linear-gradient(transparent, #041019);
}
.card-live:before { top: 36%; background: linear-gradient(transparent, #041019 75%); }
.card span {
  position: relative;
  z-index: 2;
  font-weight: 800;
  font-size: 1.05vw;
  line-height: 1.25;
  text-shadow: 0 2px 3px #000;
}
.card-live span {
  width: calc(100% + 1vw);
  min-height: 6.3vh;
  margin: 0 -.5vw -.45vh;
  padding: 1vh .8vw;
  border-radius: 8px;
  background: rgba(6,19,29,0.910);
  display: flex;
  align-items: center;
  font-size: 1.36vw;
  line-height: 1.2;
  letter-spacing: .01em;
}
.card small { position: relative; z-index: 2; color: #b9ccd6; margin-top: 5px; }
.favorite-badge {
  position: absolute;
  z-index: 3;
  top: .7vh;
  right: .55vw;
  width: 2vw;
  height: 2vw;
  border-radius: 50%;
  background: rgba(9,33,49,0.867);
  color: #ffd34f;
  font-size: 1.25vw;
  font-style: normal;
  line-height: 2vw;
  text-align: center;
}

.player-screen { padding: 0; background: #000; }
.player-screen video { width: 100%; height: 100%; background: #000; }
.player-screen #player-overlay { position: absolute; left: 3vw; top: 3vh; display: flex; align-items: center; }
.player-screen #player-overlay > * { margin-right: 20px; }
.player-screen #player-overlay { transition: opacity .25s ease; }
.player-screen #player-overlay.overlay-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.player-screen.live-clean #player-overlay { display: none !important; }
.player-screen.live-clean, .player-screen.live-clean video { background: #000 !important; }
.back { background: #244c60; border-radius: 10px; padding: 12px 18px; }
.hidden { display: none !important; }

.settings-header { height: 18vh; display: flex; align-items: center; }
.settings-header h2 { font-size: 2.5vw; margin: .6vh 0; }
.settings-header p { margin: .4vh 0; color: var(--muted); }
.settings-grid { display: flex; flex-wrap: wrap; width: 100%; }
.settings-card {
  width: calc(50% - .7vw);
  margin-bottom: 1.4vw;
  background: linear-gradient(150deg, #14384b, #0b2331);
  border: 1px solid rgba(255,255,255,0.094);
  border-radius: 18px;
  padding: 2.2vh 1.5vw;
  box-shadow: 0 18px 45px rgba(0,0,0,0.200);
}
.device-card { margin-right: 1.4vw; }
.settings-card h3 { font-size: 1.35vw; margin: 0 0 1.5vh; color: #7bd3f3; }
.info-row {
  min-height: 5.7vh;
  border-top: 1px solid rgba(255,255,255,0.071);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.info-row span { font-size: 1vw; color: var(--muted); margin-right: 1vw; }
.info-row strong {
  font-size: 1.05vw;
  text-align: right;
  max-width: 62%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.good { color: #62dda0 !important; }
.bad { color: #ff7d87 !important; }
.action-card { width: 100%; display: flex; align-items: center; padding: 2vh 1.5vw; }
.action-card h3 { margin: 0 2vw 0 0; white-space: nowrap; }
.action-card p { font-size: 1vw; color: var(--muted); flex: 1; margin-right: 2vw; }
.primary-action { background: linear-gradient(90deg, #168fbd, #176383) !important; white-space: nowrap; }

.detail-header {
  height: 11vh;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.detail-header small, .media-detail-page > .detail-content > small {
  color: #65c8ed;
  font-weight: 800;
  letter-spacing: .12em;
}
.detail-header h2 { margin: .4vh 0 0; font-size: 2.1vw; }
.live-title-line { display: flex; align-items: center; }
.live-preview-logo {
  width: 5.8vw;
  height: 7.8vh;
  object-fit: contain;
  margin-right: 1vw;
  background: rgba(255,255,255,0.051);
  border-radius: 10px;
}
.live-status {
  padding: .8vh 1vw;
  border-radius: 30px;
  background: #b51f32;
  color: #fff;
  font-size: .9vw;
  font-weight: 900;
}
.live-header-actions { display: flex; align-items: center; }
.live-header-actions > * { margin-left: .8vw; }
.favorite-action {
  padding: 1.1vh 1.1vw !important;
  background: #263f50 !important;
  color: #dce9ef;
  font-size: .9vw;
}
.favorite-action.favorite-active { background: #6a5114 !important; color: #ffe17a; }
.live-video-frame {
  width: 100%;
  height: 48vh;
  padding: 0;
  overflow: hidden;
  border-radius: 16px;
  background: #000;
  box-shadow: 0 18px 45px rgba(0,0,0,0.467);
  position: relative;
  display: block;
  outline: 0;
}
.live-video-frame video { width: 100%; height: 100%; object-fit: contain; background: #000; opacity: 0; transition: opacity .18s ease; }
.live-video-frame video.preview-visible { opacity: 1; }
.fullscreen-hint {
  position: absolute;
  right: 1.2vw;
  bottom: 1.4vh;
  padding: .8vh 1vw;
  border-radius: 24px;
  background: rgba(6,19,29,0.800);
  font-size: .78vw;
  letter-spacing: .05em;
}
.epg-panel { height: 38vh; padding-top: 1.1vh; overflow: hidden; }
.epg-panel h3 { margin: 0 0 .8vh; font-size: 1.95vw; }
#live-epg-list { display: flex; width: 100%; overflow-x: auto; padding: .3vh .3vw 1vh; }
.epg-row {
  width: 32.3%;
  min-width: 32.3%;
  height: 25.5vh;
  margin-right: 1%;
  padding: 1.35vh 1.15vw;
  border: 1px solid rgba(255,255,255,0.094);
  border-radius: 12px;
  background: #102e40;
  overflow: hidden;
}
.epg-row.current { border-color: #34b9ec; background: #17445d; }
.epg-time { color: #70d3f7; font-size: 1.32vw; font-weight: 800; }
.epg-copy h4 { margin: .8vh 0 .55vh; font-size: 1.52vw; line-height: 1.2; }
.epg-copy p { margin: 0; color: #d0dce2; font-size: 1.20vw; line-height: 1.35; }
.epg-empty { color: var(--muted); font-size: 1.38vw; }

.media-detail-page { display: flex; align-items: center; }
.detail-poster-wrap {
  width: 27vw;
  height: 80vh;
  margin-right: 3vw;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(150deg, #173e53, #0a202e);
  box-shadow: 0 20px 50px rgba(0,0,0,0.400);
}
.detail-poster { width: 100%; height: 100%; object-fit: contain; background: #0b2432; }
.detail-content { flex: 1; max-height: 88vh; overflow-y: auto; padding: 2vh 1.2vw 3vh 0; }
.detail-content h2 { margin: 1vh 0 1.4vh; font-size: 3vw; line-height: 1.05; }
.detail-content h3 { margin: 2vh 0 .7vh; color: #77d4f5; font-size: 1.3vw; }
.detail-meta { display: flex; flex-wrap: wrap; margin-bottom: 1.5vh; }
.detail-meta span {
  min-width: 10vw;
  margin: 0 1vw 1vh 0;
  padding: 1vh 1vw;
  border-radius: 10px;
  background: rgba(255,255,255,0.051);
  display: flex;
  flex-direction: column;
}
.detail-meta b { color: #87cbe5; font-size: .8vw; text-transform: uppercase; }
.detail-meta em { margin-top: .4vh; font-size: 1.05vw; font-style: normal; font-weight: 800; }
.detail-synopsis { margin: 0; max-width: 46vw; color: #d5e0e6; font-size: 1.08vw; line-height: 1.55; }
.detail-credits p { margin: .8vh 0; color: #b5c8d2; font-size: .95vw; }
.detail-credits b { color: #fff; }
.detail-action { margin-top: 2.2vh; min-width: 13vw; }
.detail-buttons { display: flex; align-items: center; }
.detail-buttons .favorite-action { margin: 2.2vh 0 0 1vw; }

/* Newer webOS versions use native grid; webOS 4.x keeps the flex fallback above. */
@supports (display: grid) {
  .menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); column-gap: 1.5vw; }
  .tile { width: auto; margin-right: 0; }
  .catalog-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-auto-rows: 31.5vh;
    column-gap: .8vw;
    row-gap: .8vw;
  }
  .catalog-grid[data-type="live"] { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: 20vh; }
  .card, .catalog-grid[data-type="live"] .card { width: auto; height: auto; margin: 0; }
  .settings-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 1.4vw; row-gap: 1.4vw; }
  .settings-card { width: auto; margin: 0; }
  .action-card { grid-column: 1 / -1; width: auto; }
}
