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

:root {
  --bg: #111;
  --bg-surface: #1a1a1a;
  --bg-hover: #252525;
  --text: #eee;
  --text-dim: #888;
  --accent: #e22;
  --accent-hover: #f33;
  --border: #333;
  --control-bg: rgba(0, 0, 0, 0.7);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

.hidden { display: none !important; }

.view {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* Buttons */
.btn {
  border: none;
  cursor: pointer;
  font-size: 18px;
  border-radius: 8px;
  padding: 12px 24px;
  min-height: 48px;
  min-width: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover, .btn-primary:active { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-icon {
  background: transparent;
  color: var(--text);
  font-size: 24px;
  padding: 8px 12px;
}

.btn-small {
  font-size: 14px;
  padding: 8px 16px;
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-large {
  font-size: 22px;
  padding: 18px 48px;
}

.btn-control {
  font-size: 32px;
  min-width: 64px;
  min-height: 64px;
}

/* Login */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 20px;
}
.login-container h1 { font-size: 48px; }
.login-container p { color: var(--text-dim); font-size: 20px; }

/* Browse Header */
.browse-header {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  gap: 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.header-left h2 { font-size: 20px; white-space: nowrap; }
.header-center { flex: 1; display: flex; justify-content: center; }
.header-right { display: flex; gap: 8px; align-items: center; }

.search-bar {
  display: flex;
  max-width: 600px;
  width: 100%;
}
.search-bar input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px 0 0 8px;
  color: var(--text);
  font-size: 18px;
  padding: 10px 16px;
  outline: none;
  min-height: 48px;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar .btn-icon {
  border-radius: 0 8px 8px 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: none;
}

/* Tabs */
.tab-bar {
  display: flex;
  gap: 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  padding: 14px 20px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  min-height: 48px;
}
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* Browse Content */
.browse-content {
  height: calc(100% - 120px);
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

/* Video Grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.video-card {
  background: var(--bg-surface);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.video-card:active {
  transform: scale(0.97);
  background: var(--bg-hover);
}

.video-card .thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #222;
}

.video-card .info {
  padding: 12px;
}
.video-card .title {
  font-size: 16px;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}
.video-card .channel {
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Channel result card (search) */
.video-card.channel-result .thumb-wrap {
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-hover);
}
.video-card.channel-result .channel-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  background: #222;
}
.video-card.channel-result .channel.badge {
  color: var(--accent);
  font-weight: 600;
}

/* Channel / Playlist List */
.channel-list, .playlist-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.list-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-surface);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
}
.list-card:active { background: var(--bg-hover); }
.list-card img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
}
.list-card .list-title {
  font-size: 16px;
  font-weight: 600;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
  font-size: 20px;
}

#load-more {
  display: block;
  margin: 20px auto;
  width: 240px;
}

/* Player */
.player-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#player-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

#player-audio { display: none; }

.player-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,0.6) 0%,
    transparent 20%,
    transparent 70%,
    rgba(0,0,0,0.8) 100%
  );
  opacity: 1;
  transition: opacity 0.3s;
}
.player-overlay.hide-controls {
  opacity: 0;
  pointer-events: none;
}

.player-top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
}

.player-back {
  font-size: 28px;
  flex-shrink: 0;
}

.player-title {
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--control-bg);
  padding: 16px 32px;
  border-radius: 12px;
  font-size: 20px;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  margin-top: auto;
}

.time-display {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  min-width: 50px;
  text-align: center;
}

.seek-bar-container {
  flex: 1;
  display: flex;
  align-items: center;
}

#seek-bar {
  width: 100%;
  height: 8px;
  -webkit-appearance: none;
  appearance: none;
  background: #444;
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}
#seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.quality-controls {
  display: flex;
  gap: 8px;
}
.btn-toggle {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  padding: 8px 14px;
  min-height: 44px;
  min-width: 64px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-toggle:active {
  background: var(--accent);
}

/* Settings Panel */
.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.settings-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 500px;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.settings-header h3 {
  font-size: 22px;
}

.settings-group {
  margin-bottom: 20px;
}
.settings-group label {
  display: block;
  font-size: 16px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.settings-options {
  display: flex;
  gap: 8px;
}
.settings-options .btn-toggle {
  flex: 1;
  text-align: center;
}
.settings-options .btn-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.settings-footer {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 4px;
}
