:root {
  color-scheme: dark;
  --bg: #07120f;
  --panel: #101917;
  --panel-2: #17211e;
  --line: #263631;
  --text: #f2f7f4;
  --muted: #aebbb5;
  --accent: #00c987;
  --accent-2: #f2c14e;
  --danger: #ff6b6b;
  --shadow: 0 18px 40px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  color: var(--text);
  background: var(--panel-2);
  min-height: 52px;
  border-radius: 12px;
  padding: 0 18px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}

button.primary {
  background: var(--accent);
  color: #03110c;
  font-weight: 800;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

button.danger {
  background: rgba(255, 107, 107, .16);
  color: #ffd1d1;
}

button.compact {
  width: max-content;
  min-height: 44px;
  padding: 0 16px;
  font-size: 14px;
}

input, select {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0b1411;
  color: var(--text);
  padding: 0 16px;
  font-size: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  background: rgba(7, 18, 15, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #06110d;
  font-weight: 900;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 14px 14px calc(96px + env(safe-area-inset-bottom));
}

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.auth-panel, .settings-panel {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.auth-panel h1, .settings-panel h2 {
  margin: 0 0 14px;
}

.form {
  display: grid;
  gap: 12px;
}

.grid {
  display: grid;
  gap: 12px;
}

.layout {
  display: grid;
  gap: 12px;
}

.player {
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 62px);
  z-index: 5;
  box-shadow: var(--shadow);
}

#video {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  background: #000;
  object-fit: contain;
}

#video:fullscreen,
#video:-webkit-full-screen {
  aspect-ratio: auto;
  height: 100%;
}

.now {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--panel);
}

.now h2 {
  margin: 0;
  font-size: 16px;
}

.now p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}
.toolbar select { min-width: 140px; }

.filters {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px 0 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.filters::-webkit-scrollbar { display: none; }

.chip {
  min-width: max-content;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
}

.chip.active {
  background: var(--accent);
  color: #06110d;
  border-color: var(--accent);
}

.channels {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

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

.channel {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 14px;
  align-items: center;
  min-height: 76px;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.channel:active { transform: scale(0.98); }

.channel.active {
  border-color: var(--accent);
}

.poster {
  display: grid;
  gap: 8px;
  align-content: start;
  min-height: 230px;
  text-align: left;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.poster.active {
  border-color: var(--accent);
}

.poster-art {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 8px;
  background: var(--panel-2);
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--accent-2);
  font-weight: 900;
}

.poster-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.poster strong {
  font-size: 13px;
  line-height: 1.2;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.poster span {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.logo {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: var(--panel-2);
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--accent-2);
  font-weight: 900;
}

.logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.channel strong {
  display: block;
  font-size: 15px;
  line-height: 1.25;
  font-weight: 700;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.channel span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.guide {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.guide h2 {
  margin: 0 0 10px;
  font-size: 15px;
}

.program {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.program strong {
  display: block;
  font-size: 13px;
}

.program span, .empty, .error {
  color: var(--muted);
  font-size: 13px;
}

.error { color: #ffd1d1; }

.notice {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b1411;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.season {
  display: grid;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.season > strong {
  font-size: 13px;
}

.episode {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 42px;
  text-align: left;
  background: #0b1411;
}

.episode span {
  color: var(--accent-2);
  font-weight: 800;
}

.episode b {
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.settings {
  display: grid;
  gap: 16px;
  justify-items: center;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row > * { flex: 1; }

.list {
  width: 100%;
  display: grid;
  gap: 8px;
}

.item {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.item strong { font-size: 14px; }
.item span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(7, 18, 15, .97);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(20px);
}

.bottom-nav button {
  min-height: 56px;
  padding: 0 4px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}

.bottom-nav button.active {
  background: var(--accent);
  color: #06110d;
  font-weight: 800;
}

@media (min-width: 560px) {
  .channels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 760px) {
  .main { padding-bottom: 24px; }
  .layout {
    grid-template-columns: minmax(0, 1fr) 340px;
    align-items: start;
  }
  .channels {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .poster-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .bottom-nav {
    left: 50%;
    transform: translateX(-50%);
    width: min(520px, calc(100% - 24px));
    border: 1px solid var(--line);
    border-radius: 8px 8px 0 0;
  }
  .player {
    position: static;
    top: auto;
  }
}

@media (min-width: 1120px) {
  .channels {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .poster-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (orientation: landscape) and (max-width: 900px) and (max-height: 500px) {
  .topbar, .bottom-nav, .now, .toolbar, .filters, .channels, .poster-grid, .guide {
    display: none !important;
  }
  .main { padding: 0; max-width: none; }
  .layout { gap: 0; }
  .player {
    position: fixed;
    inset: 0;
    top: 0;
    border-radius: 0;
    border: 0;
    z-index: 100;
  }
  #video {
    aspect-ratio: auto;
    height: 100vh;
    object-fit: contain;
  }
}

html { overscroll-behavior-y: contain; }
body { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
