:root {
  --bg: #0f0f0f;
  --bg-elev: #1c1c1c;
  --bg-elev-2: #272727;
  --border: #303030;
  --text: #f1f1f1;
  --text-muted: #aaa;
  --accent: #ff0033;
  --accent-hover: #ff3355;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

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

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}
.brand {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.brand::first-letter { color: var(--accent); }

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px 12px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  padding: 8px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.tab:hover { background: var(--bg-elev-2); }
.tab.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, transform 0.05s;
  text-decoration: none;
}
.btn:hover { background: var(--bg-elev-2); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
}
.btn-danger {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
  padding: 6px 10px;
  font-size: 13px;
}
.btn-danger:hover { background: #3a1a1a; color: #ff8080; border-color: #5a2a2a; }

/* Feed */
.feed {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px;
  padding-bottom: calc(32px + var(--safe-bottom));
  max-width: 1400px;
  margin: 0 auto;
}
@media (min-width: 640px) {
  .feed { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
  .feed { grid-template-columns: repeat(3, 1fr); gap: 20px; padding: 20px; }
}
@media (min-width: 1280px) {
  .feed { grid-template-columns: repeat(4, 1fr); }
}

.card {
  background: transparent;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s;
}
.card:hover { transform: translateY(-2px); }
.card-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-length {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  z-index: 1;
}
.card-thumb::after {
  content: "▶";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: white;
  opacity: 0;
  background: rgba(0, 0, 0, 0.35);
  transition: opacity 0.15s;
}
.card:hover .card-thumb::after { opacity: 1; }

.card-body {
  display: flex;
  gap: 10px;
  padding: 10px 2px 0;
}
.card-channel-thumb {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-elev);
  flex-shrink: 0;
  overflow: hidden;
}
.card-channel-thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-text { flex: 1; min-width: 0; }
.card-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}
.card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}
.card-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.card-action {
  font-size: 12px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 999px;
}
.card-action:hover { background: var(--bg-elev); color: var(--text); }

/* Empty / Loading */
.empty, .loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty h2 { color: var(--text); margin: 0 0 8px; }
.empty p { margin: 0 0 20px; }
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}
.modal-content {
  position: relative;
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 900px;
  width: 100%;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  border: 1px solid var(--border);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  font-size: 16px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: rgba(0, 0, 0, 0.8); }

/* Player */
.player-content { max-width: 1100px; }
.player-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: black;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
}
.player-wrap iframe {
  width: 100%;
  height: 100%;
  border: none;
}
.player-meta {
  padding: 16px;
}
.player-meta h3 { margin: 0 0 4px; font-size: 16px; }
.player-meta p { margin: 0 0 12px; }

/* Manage modal */
.manage-content { max-width: 600px; }
.manage-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  z-index: 1;
}
.manage-header h2 { margin: 0; font-size: 18px; }
.manage-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.manage-section:last-child { border-bottom: none; }
.manage-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 12px;
  font-weight: 600;
}

.inline-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.inline-form input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
}
.inline-form input:focus { border-color: var(--accent); }

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: -4px 0 12px;
}
.hint code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

.playlist-list, .channel-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.list-item .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.list-item .thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-elev);
  flex-shrink: 0;
  overflow: hidden;
}
.list-item .thumb img { width: 100%; height: 100%; object-fit: cover; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.row select {
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
}
.full-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  margin: 8px 0 4px;
}
.full-input:focus { border-color: var(--accent); }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 200;
  max-width: calc(100vw - 32px);
}
.toast.error { background: #3a1a1a; border-color: #5a2a2a; color: #ffb0b0; }
