:root {
  color-scheme: dark;
  --bg: #0d0e0f;
  --surface: #151719;
  --surface-2: #1d2023;
  --surface-3: #252a2e;
  --text: #f4f1ea;
  --muted: #aba59a;
  --quiet: #777c80;
  --line: rgba(255, 255, 255, .12);
  --line-strong: rgba(255, 255, 255, .2);
  --accent: #35c982;
  --accent-2: #e9b85c;
  --danger: #ff6b6b;
  --shadow: 0 18px 46px rgba(0, 0, 0, .32);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, rgba(53, 201, 130, .12), transparent 24rem),
    linear-gradient(180deg, #111314 0%, #0d0e0f 46%, #0b0c0d 100%);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  transition: transform .15s ease, border-color .15s ease, background .15s ease, opacity .15s ease;
}

button:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: wait;
  opacity: .6;
  transform: none;
}

button.primary {
  border-color: color-mix(in srgb, var(--accent) 80%, white);
  background: var(--accent);
  color: #05120b;
}

input,
select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101214;
  color: var(--text);
  outline: 0;
  padding: 0 12px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(53, 201, 130, .16);
}

.shell {
  width: min(1420px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 18px;
}

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

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(53, 201, 130, .46);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(53, 201, 130, .22), rgba(233, 184, 92, .12));
  color: var(--accent);
  font-weight: 850;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  line-height: 1.2;
}

.brand p,
.panel-head p {
  margin-top: 5px;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.kodi-status {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 23, 25, .86);
  color: var(--muted);
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--quiet);
  box-shadow: 0 0 0 4px rgba(119, 124, 128, .14);
}

.kodi-status[data-state="ready"] .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(53, 201, 130, .14);
}

.kodi-status[data-state="playing"] .status-dot {
  background: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(233, 184, 92, .14);
}

.kodi-status[data-state="offline"] .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(255, 107, 107, .12);
}

.remote-controls {
  display: flex;
  gap: 6px;
}

.remote-controls button {
  width: 40px;
  padding: 0;
  font-size: 17px;
}

.logout-button {
  min-height: 40px;
  padding: 0 12px;
}

.search-surface,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
}

.search-surface {
  padding: 14px;
  margin-bottom: 14px;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 128px 150px 128px 126px;
  gap: 10px;
  align-items: end;
}

.search-box,
.field {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.search-box input {
  min-height: 48px;
  font-size: 17px;
}

.search-button {
  min-height: 48px;
}

.search-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  min-height: 28px;
}

.recent-searches {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.recent-searches button,
.chip {
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #202326;
  color: #ddd8ce;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.recent-searches button:hover,
.chip:hover {
  border-color: var(--line-strong);
}

.message {
  color: var(--muted);
  text-align: right;
  min-width: min(380px, 100%);
}

.message.ok {
  color: var(--accent);
}

.message.error {
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 450px);
  gap: 14px;
  align-items: start;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.counter {
  min-width: 34px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-weight: 800;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  padding: 14px;
}

.catalog-card {
  position: relative;
  min-height: 250px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  isolation: isolate;
  animation: cardIn .22s ease both;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.catalog-card:hover,
.catalog-card.selected {
  border-color: rgba(53, 201, 130, .42);
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, .24);
}

.catalog-card.selected::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(53, 201, 130, .58);
  border-radius: 8px;
  pointer-events: none;
}

.backdrop {
  position: absolute;
  inset: 0 0 auto;
  height: 116px;
  background: #111;
  background-position: center;
  background-size: cover;
  opacity: .62;
  z-index: -2;
}

.backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(13, 14, 15, .08), var(--surface-2));
}

.catalog-body {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 12px;
  padding: 18px 14px 12px;
}

.poster {
  width: 74px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 6px;
  background: #2a2d30;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .35);
}

.poster.placeholder {
  display: grid;
  place-items: center;
  color: var(--quiet);
  font-weight: 850;
}

.catalog-copy {
  min-width: 0;
  padding-top: 18px;
}

.title {
  color: var(--text);
  font-size: 16px;
  font-weight: 820;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.meta,
.overview,
.stream-file {
  color: var(--muted);
  font-size: 13px;
}

.meta {
  margin-top: 5px;
}

.overview {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 10px 14px 0;
}

.card-footer {
  padding: 12px 14px 14px;
}

.movie-action {
  display: flex;
  justify-content: flex-end;
}

.movie-action button,
.episode-search {
  min-height: 38px;
  padding: 0 12px;
}

.episode-browser {
  display: grid;
  gap: 10px;
}

.episode-browser-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, .14);
}

.episode-browser-head span,
.manual-picker summary {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.episode-browser-head strong {
  display: block;
  margin-top: 2px;
  font-size: 17px;
}

.episode-browser-head button {
  min-height: 34px;
  padding: 0 10px;
  white-space: nowrap;
}

.episode-browser-content {
  display: grid;
  gap: 8px;
}

.season-browser {
  display: grid;
  gap: 8px;
}

.episode-list {
  display: grid;
  gap: 6px;
  max-height: 340px;
  overflow: auto;
  padding-right: 2px;
}

.episode-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  min-height: 58px;
  padding: 7px;
  text-align: left;
  font-weight: 700;
  background: #171a1d;
}

.episode-row.active {
  border-color: rgba(53, 201, 130, .7);
  background: rgba(53, 201, 130, .11);
}

.episode-row img,
.episode-thumb {
  width: 72px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  background: #2a2d30;
}

.episode-row span {
  min-width: 0;
}

.episode-row strong,
.episode-row small {
  display: block;
  overflow-wrap: anywhere;
}

.episode-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.mini-loader {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.mini-loader.error {
  color: var(--danger);
  border-color: rgba(255, 107, 107, .32);
}

.manual-picker {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.manual-picker summary {
  cursor: pointer;
}

.episode-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.episode-readout {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, .14);
}

.episode-readout span,
.stepper label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.episode-readout strong {
  font-size: 17px;
}

.stepper {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  grid-template-rows: auto 36px;
  gap: 5px;
}

.stepper label {
  grid-column: 1 / -1;
}

.stepper button {
  min-height: 36px;
  padding: 0;
  font-size: 18px;
}

.stepper input {
  min-height: 36px;
  padding: 0 6px;
  text-align: center;
}

.episode-search {
  grid-column: 1 / -1;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(460px, calc(100vw - 28px));
  padding: 20px 0;
}

.login-panel {
  display: grid;
  gap: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
}

.login-brand {
  align-items: flex-start;
}

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

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.login-form button {
  min-height: 46px;
}

.login-error {
  padding: 11px 12px;
  border: 1px solid rgba(255, 107, 107, .34);
  border-radius: 8px;
  background: rgba(255, 107, 107, .09);
  color: #ffd0d0;
}

.stream-panel {
  position: sticky;
  top: 12px;
}

.stream-list {
  display: grid;
  gap: 10px;
  padding: 14px;
  max-height: calc(100vh - 180px);
  overflow: auto;
}

.stream-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #171a1d;
  animation: cardIn .18s ease both;
}

.stream-rank {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 850;
}

.stream-main {
  min-width: 0;
}

.stream-title {
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.stream-file {
  margin-top: 8px;
  overflow-wrap: anywhere;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.chip.provider {
  color: #06120c;
  border-color: rgba(53, 201, 130, .8);
  background: var(--accent);
}

.chip.quality {
  border-color: rgba(233, 184, 92, .42);
  color: #f2d7a3;
}

.stream-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 2px;
}

.stream-actions button {
  min-height: 38px;
}

.stream-actions .browser {
  border-color: color-mix(in srgb, var(--accent) 80%, white);
  background: var(--accent);
  color: #05120b;
}

.empty-state {
  grid-column: 1 / -1;
  min-height: 180px;
  display: grid;
  place-items: center;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state.compact {
  min-height: 120px;
}

.retry-live {
  margin-top: 12px;
  padding: 0 12px;
}

.skeleton {
  min-height: 250px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, .05), transparent),
    var(--surface-2);
  background-size: 220% 100%, auto;
  animation: shimmer 1.1s ease-in-out infinite;
}

@keyframes shimmer {
  from { background-position: 120% 0, 0 0; }
  to { background-position: -120% 0, 0 0; }
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .stream-panel {
    position: static;
  }

  .stream-list {
    max-height: none;
  }
}

@media (max-width: 820px) {
  .shell {
    width: min(100vw - 20px, 1420px);
    padding-top: 12px;
  }

  .app-header {
    display: grid;
  }

  .header-actions {
    justify-content: stretch;
  }

  .kodi-status {
    flex: 1;
  }

  .search-form {
    grid-template-columns: 1fr 1fr;
  }

  .search-box,
  .search-button {
    grid-column: 1 / -1;
  }

  .search-meta {
    display: grid;
  }

  .message {
    text-align: left;
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .catalog-grid {
    grid-template-columns: 1fr;
  }

  .catalog-body {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .poster {
    width: 64px;
  }

  .stream-actions {
    grid-template-columns: 1fr;
  }

  .episode-browser-head {
    display: grid;
  }

  .episode-row {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .episode-row img,
  .episode-thumb {
    width: 58px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
