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

:root {
  --bg: #0a0e14;
  --bg-elevated: #0f141d;
  --surface: #161b22;
  --surface-2: #1d2330;
  --surface-3: #2a3142;
  --border: #2a3142;
  --border-strong: #3a4358;
  --text: #f0f6fc;
  --text-muted: #8b949e;
  --text-dim: #6e7681;
  --accent: #f97316;
  --accent-hover: #fb923c;
  --accent-soft: rgba(249, 115, 22, 0.15);
  --error: #f87171;
  --success: #34d399;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

#app { min-height: 100vh; }

button { font-family: inherit; }
img { display: block; max-width: 100%; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ── Splash ───────────────────────────────────────── */

.splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 16px;
}

.splash-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #fb923c);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 24px;
  letter-spacing: -1px;
}

.splash-text {
  color: var(--text-muted);
  font-size: 14px;
  letter-spacing: 0.5px;
}

/* ── Login ────────────────────────────────────────── */

.login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-box {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.login-box h1 {
  font-size: 28px;
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}

.login-box .hint {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
  line-height: 1.5;
}

.login-box label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  margin-top: 16px;
  margin-bottom: 6px;
}

.login-box input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 20px;
  letter-spacing: 6px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--transition);
}

.login-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-box button.primary {
  width: 100%;
  margin-top: 24px;
  padding: 14px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

.login-box button.primary:hover { background: var(--accent-hover); }
.login-box button.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.login-box input[type="email"],
.login-box input[type="password"]:not([maxlength="4"]) {
  font-size: 15px;
  letter-spacing: normal;
  text-align: left;
}

.login-box .error {
  color: var(--error);
  font-size: 13px;
  margin-top: 12px;
  min-height: 16px;
}

.login-switch {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  text-decoration: underline;
}

.link-btn:hover { color: var(--accent-hover); }

.cred-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-top: 14px;
  cursor: pointer;
  transition: var(--transition);
}

.cred-row:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}

.cred-row .cred-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  min-width: 40px;
}

.cred-row .cred-value {
  flex: 1;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 4px;
  font-variant-numeric: tabular-nums;
}

.cred-row .cred-copy {
  opacity: 0.5;
  font-size: 16px;
}

.cred-row:hover .cred-copy { opacity: 1; }

/* ── App shell ────────────────────────────────────── */

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

.topbar {
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  flex-shrink: 0;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #fb923c);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: -0.5px;
}

.tabs {
  display: flex;
  gap: 2px;
  margin-left: 8px;
}

.tabs button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
}

.tabs button:hover { background: var(--surface); color: var(--text); }
.tabs button.active { background: var(--surface-2); color: var(--text); }

.search-box {
  position: relative;
  flex: 1;
  max-width: 480px;
  margin: 0 16px;
}

.search-box input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px 8px 36px;
  border-radius: 8px;
  font-size: 14px;
  transition: var(--transition);
}

.search-box input:focus {
  outline: none;
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.search-box .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-box .shortcut {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  pointer-events: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.icon-btn:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.text-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
}

.text-btn:hover { background: var(--surface); color: var(--text); }

.status-pill {
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 8px;
  background: var(--surface);
  border-radius: 6px;
  white-space: nowrap;
}

/* ── Main area ────────────────────────────────────── */

.main {
  display: grid;
  grid-template-columns: 240px 1fr;
  overflow: hidden;
}

.main.with-player {
  grid-template-columns: 240px 1fr min(40vw, 640px);
}

.main.fullscreen-player {
  grid-template-columns: 0 0 1fr;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px 0;
}

.sidebar-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  padding: 12px 16px 6px;
}

.group-row {
  display: flex;
  align-items: center;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  transition: var(--transition);
}

.group-row:hover {
  background: var(--surface);
  color: var(--text);
}

.group-row.active {
  background: var(--surface-2);
  color: var(--text);
  border-left-color: var(--accent);
}

.group-row .name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-row .count {
  margin-left: 8px;
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ── Items grid (cards) ───────────────────────────── */

.items-area {
  background: var(--bg);
  overflow-y: auto;
  position: relative;
}

.items-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: baseline;
  padding: 16px 20px 8px;
  background: linear-gradient(to bottom, var(--bg) 70%, transparent);
  gap: 12px;
}

.items-header h2 {
  font-size: 18px;
  letter-spacing: -0.3px;
}

.items-header .meta {
  color: var(--text-dim);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.row-section {
  margin-bottom: 8px;
}

.row-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 12px 20px 8px;
}

.row-scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 0 20px 16px;
  scroll-snap-type: x mandatory;
}

.row-scroll .card {
  flex: 0 0 auto;
  width: 160px;
  scroll-snap-align: start;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding: 4px 20px 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}

.card:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.card.playing {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
}

.card .thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--surface-3);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
}

.card .thumb-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--text-dim);
}

.card .progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  background: var(--accent);
}

.card .meta {
  padding: 10px 12px;
  flex: 1;
  min-width: 0;
}

.card .name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.card .group {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.card .badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.7);
  color: var(--text);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 6px;
  border-radius: 4px;
}

.card .heart {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  border: none;
  color: white;
  cursor: pointer;
  opacity: 0.7;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  z-index: 2;
}

.card:hover .heart,
.card .heart.fav {
  opacity: 1;
}

.card .heart:hover {
  transform: scale(1.1);
  background: rgba(0, 0, 0, 0.8);
}

.card .heart.fav {
  color: var(--error);
}

/* ── Player panel ─────────────────────────────────── */

.player-panel {
  background: black;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.player-panel video {
  width: 100%;
  height: 100%;
  flex: 1;
  background: black;
  object-fit: contain;
}

.player-panel .info {
  background: var(--bg-elevated);
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-panel .info .titles {
  flex: 1;
  min-width: 0;
}

.player-panel .info .titles .name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-panel .info .titles .group {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-panel .info .actions {
  display: flex;
  gap: 4px;
}

.player-panel .placeholder {
  color: var(--text-dim);
  text-align: center;
  padding: 32px;
  font-size: 14px;
  margin: auto;
}

/* ── Series episode list ──────────────────────────── */

.series-detail {
  padding: 0 20px 24px;
}

.series-detail h3 {
  font-size: 16px;
  margin: 12px 0 8px;
  color: var(--text-muted);
  font-weight: 600;
}

.season-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 20px 12px;
}

.season-tabs button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  transition: var(--transition);
}

.season-tabs button.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--accent);
}

.episode-row {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  gap: 12px;
  transition: var(--transition);
}

.episode-row:hover {
  background: var(--surface);
}

.episode-row.playing {
  background: var(--accent-soft);
  color: var(--accent);
}

.episode-row .num {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-dim);
  width: 60px;
  flex-shrink: 0;
}

.episode-row .title {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Empty state ──────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 32px;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
}

.empty-state .icon {
  font-size: 48px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.empty-state p {
  font-size: 13px;
  max-width: 320px;
  line-height: 1.5;
}

/* ── Toast ────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: var(--transition);
  z-index: 100;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.error { border-color: var(--error); }
.toast.success { border-color: var(--success); }

/* ── Responsive ───────────────────────────────────── */

@media (max-width: 980px) {
  .main { grid-template-columns: 200px 1fr; }
  .main.with-player {
    grid-template-rows: 1fr auto;
    grid-template-columns: 200px 1fr;
  }
  .player-panel {
    grid-column: 1 / -1;
    grid-row: 2;
    height: 60vh;
    max-height: 480px;
  }
}

@media (max-width: 680px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .search-box { display: none; }
  .brand-text { display: none; }
  .tabs button { padding: 6px 10px; font-size: 13px; }
  .main { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main.with-player {
    grid-template-rows: 40vh 1fr;
    grid-template-columns: 1fr;
  }
  .player-panel {
    grid-column: 1;
    grid-row: 1;
    height: auto;
  }
}
