:root {
  --bg: #121212;
  --surface: #1b1b1b;
  --surface-2: #242424;
  --line: #2e2e2e;
  --text: #ececec;
  --text-dim: #9a9a9a;
  --accent: #e5e5e5;
  --danger: #d86a6a;
  --radius: 4px;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
}

.search-form {
  display: flex;
  flex: 1;
  max-width: 420px;
  margin-left: auto;
}
.search-form input {
  flex: 1;
  height: 34px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  outline: none;
}
.search-form input:focus { border-color: #555; }
.search-form button {
  height: 34px;
  padding: 0 14px;
  background: var(--accent);
  color: #111;
  border: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-weight: 500;
}

.source-wrap { display: flex; gap: 8px; align-items: center; }
.source-wrap select,
.icon-btn {
  height: 34px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 24px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tabs a {
  padding: 12px 0;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* Main */
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.loader, .error, .empty {
  padding: 48px 0;
  text-align: center;
  color: var(--text-dim);
}
.error { color: var(--danger); }

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 20px 16px;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--surface-2);
  border-radius: var(--radius);
}
.card:hover .card-title { text-decoration: underline; }
.card-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta {
  font-size: 12px;
  color: var(--text-dim);
}

/* Schedule and directory */
.schedule-day { margin-bottom: 36px; }
.schedule-day h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
}

.episode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.episode-grid a {
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
  text-align: center;
}
.episode-grid a:hover { border-color: #555; }

/* Pager */
.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 36px;
  color: var(--text-dim);
  font-size: 14px;
}
.pager button {
  height: 34px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.pager button:disabled { opacity: 0.35; cursor: default; }

/* Detail */
.detail {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 32px;
}
.detail-poster {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.detail h1 {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: 4px;
}
.japanese {
  color: var(--text-dim);
  margin-bottom: 20px;
}
.info-table {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 20px;
  margin-bottom: 20px;
  font-size: 14px;
}
.info-table dt { color: var(--text-dim); }
.genres {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}
.genres span {
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-dim);
}
.synopsis {
  font-size: 14px;
  color: #cfcfcf;
  margin-bottom: 24px;
  max-width: 720px;
}
.synopsis p + p { margin-top: 10px; }
.section-sub {
  font-size: 15px;
  font-weight: 600;
  margin: 28px 0 12px;
}

/* Player */
.player-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1040px;
  margin: 0 auto;
}
.player-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.player-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
}
.player-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  background: #000;
}
.player-title {
  font-size: 18px;
  font-weight: 600;
}
.player-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.player-nav a {
  height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
}
.player-nav a:hover { border-color: #555; }
.player-nav a.disabled { opacity: 0.35; pointer-events: none; }

.server-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.server-block h4 {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.server-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.server-row:last-child { margin-bottom: 0; }
.quality-label {
  min-width: 56px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
}
.server-row button,
.dl-link {
  height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
}
.server-row button:hover,
.dl-link:hover { border-color: #555; }
.server-row button.active {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  width: min(420px, 92vw);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.modal-box h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
}
.modal-box label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}
.modal-box input {
  height: 36px;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
}
.hint {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
}
.hint code { color: var(--text); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-actions button {
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: transparent;
}
.modal-actions button:last-child {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
}

@media (max-width: 760px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 14px; }
  .search-form { order: 3; max-width: none; width: 100%; margin-left: 0; }
  main { padding: 20px 14px 48px; }
  .tabs { padding: 0 14px; gap: 18px; }
  .detail { grid-template-columns: 1fr; }
  .detail-poster { max-width: 220px; }
}
