:root {
  --bg: #f4f6f4;
  --panel: #ffffff;
  --panel-strong: #eef3ef;
  --text: #18201c;
  --muted: #647067;
  --border: #d8dfda;
  --accent: #147a5f;
  --accent-strong: #0e5f4a;
  --warning: #a23c22;
  --shadow: 0 12px 32px rgba(23, 33, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  border-color: var(--border);
  background: #ffffff;
  color: var(--text);
}

button.secondary:hover {
  background: var(--panel-strong);
}

button.danger {
  border-color: var(--warning);
  background: var(--warning);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 0 10px;
}

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: #fbfcfb;
  padding: 22px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 6px;
  background: #1d2a24;
  color: #ffffff;
  font-weight: 700;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.brand p,
.view-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-button {
  justify-content: flex-start;
  width: 100%;
  border-color: transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  background: var(--panel-strong);
  color: var(--text);
}

.main {
  min-width: 0;
  padding: 18px;
}

.topbar,
.status-row,
.view {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
}

.login-form,
.top-actions,
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}

.login-form label {
  display: grid;
  gap: 5px;
  min-width: 180px;
  color: var(--muted);
  font-size: 12px;
}

.status-row {
  margin-top: 14px;
  padding: 12px 14px;
}

.status-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
}

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

.view {
  display: none;
  margin-top: 14px;
  min-height: 480px;
  padding: 16px;
}

.view.active {
  display: block;
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  margin-bottom: 16px;
}

.view-header h2 {
  margin: 0;
  font-size: 24px;
}

.controls select {
  width: 220px;
}

.controls input[type="search"] {
  width: 220px;
}

.page-input {
  width: 86px;
}

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

.compact-grid {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.item-card {
  display: grid;
  gap: 10px;
  min-height: 154px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.item-card h3 {
  margin: 0;
  min-height: 42px;
  font-size: 16px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.item-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
}

.adult-badge {
  width: max-content;
  border-radius: 6px;
  background: #fde9e3;
  color: var(--warning);
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 700;
}

.poster {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: linear-gradient(135deg, #1d2a24, #147a5f);
  object-fit: cover;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  padding: 28px;
  text-align: center;
}

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

.json-output {
  min-height: 360px;
  max-height: 620px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111612;
  color: #dce7df;
  padding: 14px;
  font-size: 12px;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(18, 24, 20, 0.55);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
}

.dialog-header h3 {
  margin: 0;
  font-size: 18px;
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

.dialog-body {
  display: grid;
  gap: 12px;
  max-height: 70vh;
  overflow: auto;
  padding: 14px;
}

.dialog-body pre {
  overflow: auto;
  border-radius: 8px;
  background: #111612;
  color: #dce7df;
  padding: 12px;
}

.player-shell {
  overflow: hidden;
  border-radius: 8px;
  background: #050706;
}

.player-shell video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #050706;
}

.player-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.stream-link {
  color: var(--accent);
  font-weight: 700;
}

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

.episode-row {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .nav-button {
    justify-content: center;
    padding: 0 8px;
    text-align: center;
  }

  .topbar,
  .view-header {
    align-items: stretch;
    flex-direction: column;
  }

  .login-form label,
  .controls select,
  .controls input[type="search"],
  .top-actions button,
  .login-form button {
    width: 100%;
  }

  .details-layout {
    grid-template-columns: 1fr;
  }
}
