:root {
  --yt-spec-base-background: #0f0f0f;
  --yt-spec-raised-background: #212121;
  --yt-spec-menu-background: #282828;
  --yt-spec-text-primary: #f1f1f1;
  --yt-spec-text-secondary: #aaa;
  --yt-spec-brand-background-primary: #ff0000;
  --yt-spec-static-brand-red: #ff0000;
  --yt-spec-static-overlay-background-heavy: rgba(0, 0, 0, 0.8);
  --header-height: 56px;
  --channel-banner-height: 150px;
  --sidebar-width: 72px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  font-family: Roboto, Arial, sans-serif;
  background: var(--yt-spec-base-background);
  color: var(--yt-spec-text-primary);
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

/* Masthead */
#masthead {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--yt-spec-base-background);
  z-index: 2000;
}

.masthead-start {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 169px;
}

.menu-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 50%;
  color: var(--yt-spec-text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-btn:hover {
  background: var(--yt-spec-raised-background);
}

.yt-logo {
  display: flex;
  align-items: center;
  gap: 4px;
}

.yt-logo svg {
  height: 20px;
}

.yt-logo span {
  font-family: 'YouTube Sans', Roboto, Arial, sans-serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: -1.5px;
  margin-top: 6px;
}

.masthead-center {
  flex: 1;
  max-width: 640px;
  display: flex;
  margin: 0 40px;
}

#search-form {
  display: flex;
  flex: 1;
}

#search {
  flex: 1;
  height: 40px;
  padding: 0 16px;
  border: 1px solid #303030;
  border-right: none;
  border-radius: 40px 0 0 40px;
  background: #121212;
  color: var(--yt-spec-text-primary);
  outline: none;
}

#search:focus {
  border-color: #1c62b9;
}

.search-btn {
  width: 64px;
  height: 40px;
  border: 1px solid #303030;
  border-radius: 0 40px 40px 0;
  background: #222;
  color: var(--yt-spec-text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.masthead-end {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 225px;
  justify-content: flex-end;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 50%;
  color: var(--yt-spec-text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--yt-spec-raised-background);
}

.sign-in-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 36px;
  border: 1px solid #3ea6ff;
  border-radius: 18px;
  background: transparent;
  color: #3ea6ff;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
}

.sign-in-btn:hover {
  background: rgba(62, 166, 255, 0.15);
}

/* Layout */
#page {
  padding-top: var(--header-height);
}

#channel-container {
  max-width: 1284px;
  margin: 0 auto;
  padding: 0 24px 48px;
}

/* Banner */
#channel-header {
  margin: 0 -24px;
}

#channel-banner {
  width: 100%;
  height: var(--channel-banner-height);
  background: #333;
  overflow: hidden;
}

#channel-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#channel-banner.empty {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

/* Channel meta row */
#channel-meta {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  padding: 24px 0 16px;
  flex-wrap: wrap;
}

#channel-avatar {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  margin-top: -64px;
  background: var(--yt-spec-base-background);
  border: 4px solid var(--yt-spec-base-background);
  object-fit: cover;
  flex-shrink: 0;
}

#channel-info {
  flex: 1;
  min-width: 200px;
  padding-top: 8px;
}

#channel-name {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 4px;
}

#channel-handle {
  font-size: 14px;
  color: var(--yt-spec-text-secondary);
  margin-bottom: 8px;
}

#channel-stats {
  font-size: 14px;
  color: var(--yt-spec-text-secondary);
}

#channel-description {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.5;
  max-width: 640px;
  white-space: pre-wrap;
}

#channel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 24px;
}

.subscribe-btn {
  height: 36px;
  padding: 0 16px;
  border: none;
  border-radius: 18px;
  background: var(--yt-spec-text-primary);
  color: #0f0f0f;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
}

.subscribe-btn:hover {
  background: #d9d9d9;
}

.subscribe-btn.subscribed {
  background: var(--yt-spec-raised-background);
  color: var(--yt-spec-text-primary);
}

/* Tabs */
#channel-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #303030;
  margin-bottom: 24px;
}

.tab {
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--yt-spec-text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: default;
}

.tab.active {
  color: var(--yt-spec-text-primary);
  border-bottom-color: var(--yt-spec-text-primary);
}

/* Video grid */
#video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px 16px;
}

.video-card {
  cursor: pointer;
  display: block;
}

.video-card:hover .video-title {
  color: #fff;
}

.thumbnail-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: #212121;
  isolation: isolate;
}

.thumbnail-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.watch-progress-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  width: 0%;
  background: #ff0000;
  z-index: 2;
  pointer-events: none;
  border-radius: 0 2px 0 12px;
}

.watch-progress-bar.visible {
  box-shadow: 0 0 4px rgba(255, 0, 0, 0.6);
}

.yt-resume-toast {
  position: absolute;
  left: 12px;
  bottom: 72px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(28, 28, 28, 0.95);
  border-radius: 8px;
  font-size: 14px;
  color: #fff;
  max-width: calc(100% - 24px);
}

.yt-resume-toast.hidden {
  display: none;
}

.yt-resume-toast button {
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.yt-resume-toast button:hover {
  background: rgba(255, 255, 255, 0.25);
}

.video-meta {
  display: flex;
  gap: 12px;
  padding-top: 12px;
}

.video-meta .mini-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.video-details {
  flex: 1;
  min-width: 0;
}

.video-title {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}

.video-stats {
  font-size: 14px;
  color: var(--yt-spec-text-secondary);
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 64px 24px;
  color: var(--yt-spec-text-secondary);
}

.empty-state a {
  color: #3ea6ff;
}

/* Watch page */
#watch-layout {
  max-width: 1720px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 402px;
  gap: 24px;
}

/* YouTube-style custom player */
.yt-player {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
}

.yt-player:fullscreen {
  border-radius: 0;
}

.yt-player-video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}

.yt-player-big-play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border: none;
  background: transparent;
  cursor: pointer;
  z-index: 3;
  opacity: 1;
  transition: opacity 0.2s;
  padding: 0;
}

.yt-player.is-playing .yt-player-big-play {
  opacity: 0;
  pointer-events: none;
}

.yt-player-shade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 120px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 1;
}

.yt-player.show-controls .yt-player-shade,
.yt-player.is-paused .yt-player-shade {
  opacity: 1;
}

.yt-player-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  padding: 0 12px 8px;
  opacity: 0;
  transition: opacity 0.2s;
}

.yt-player.show-controls .yt-player-controls,
.yt-player.is-paused .yt-player-controls {
  opacity: 1;
}

.yt-progress {
  position: relative;
  height: 5px;
  margin: 0 4px 10px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  cursor: pointer;
}

.yt-progress:hover {
  height: 7px;
  margin-bottom: 9px;
}

.yt-progress-buffer,
.yt-progress-played {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 2px;
  width: 0%;
}

.yt-progress-buffer {
  background: rgba(255, 255, 255, 0.35);
}

.yt-progress-played {
  background: #ff0000;
  z-index: 1;
}

.yt-progress-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 13px;
  height: 13px;
  margin-top: -6.5px;
  margin-left: -6.5px;
  background: #ff0000;
  border-radius: 50%;
  z-index: 2;
  transform: scale(0);
  transition: transform 0.1s;
}

.yt-progress:hover .yt-progress-thumb {
  transform: scale(1);
}

.yt-controls-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.yt-ctrl-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.yt-ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.yt-time {
  font-size: 13px;
  color: #fff;
  font-weight: 500;
  white-space: nowrap;
  margin-left: 4px;
}

.yt-controls-spacer {
  flex: 1;
}

.yt-volume-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
}

.yt-volume-slider {
  width: 0;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  outline: none;
  transition: width 0.15s;
  cursor: pointer;
}

.yt-volume-wrap:hover .yt-volume-slider,
.yt-volume-slider:focus {
  width: 72px;
}

.yt-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
}

.yt-volume-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: #fff;
}

#watch-info h1 {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.4;
  margin: 12px 0 8px;
}

#watch-stats {
  font-size: 14px;
  color: var(--yt-spec-text-secondary);
  padding-bottom: 16px;
  border-bottom: 1px solid #303030;
}

#watch-channel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
}

#watch-channel-row img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

#watch-channel-row .name {
  font-weight: 500;
  font-size: 16px;
}

#watch-description {
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  background: var(--yt-spec-raised-background);
  border-radius: 12px;
  padding: 12px;
  margin-top: 8px;
}

#related h3 {
  font-size: 16px;
  margin-bottom: 12px;
}

.related-item {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  cursor: pointer;
}

.related-item:hover .related-title {
  color: #fff;
}

.related-thumb {
  width: 168px;
  height: 94px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: #212121;
}

.related-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.related-meta {
  font-size: 12px;
  color: var(--yt-spec-text-secondary);
  margin-top: 4px;
}

/* Admin */
.admin-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 80px 24px 48px;
}

.admin-page h1 {
  font-size: 28px;
  margin-bottom: 8px;
}

.admin-page .subtitle {
  color: var(--yt-spec-text-secondary);
  margin-bottom: 32px;
}

.admin-page .subtitle a {
  color: #3ea6ff;
}

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 24px;
}

.alert.success {
  background: #0d3d1a;
  color: #6ee7a0;
}

.alert.error {
  background: #3d0d0d;
  color: #f88;
}

.admin-section {
  background: var(--yt-spec-raised-background);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
}

.admin-section h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.form-row {
  margin-bottom: 16px;
}

.form-row label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--yt-spec-text-secondary);
}

.form-row input[type='text'],
.form-row input[type='date'],
.form-row input[type='url'],
.form-row input[type='file'],
.form-row textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #303030;
  border-radius: 8px;
  background: #121212;
  color: var(--yt-spec-text-primary);
}

.form-row textarea {
  min-height: 80px;
  resize: vertical;
}

.btn-primary {
  height: 36px;
  padding: 0 16px;
  border: none;
  border-radius: 18px;
  background: #3ea6ff;
  color: #0f0f0f;
  font-weight: 500;
  cursor: pointer;
}

.btn-primary:hover {
  background: #65b8ff;
}

.btn-danger {
  height: 32px;
  padding: 0 12px;
  border: none;
  border-radius: 16px;
  background: #5c1a1a;
  color: #f88;
  font-size: 13px;
  cursor: pointer;
}

.upload-status {
  margin-bottom: 20px;
  padding: 16px;
  background: #1a3a5c;
  border-radius: 8px;
}

.upload-status.hidden {
  display: none;
}

.upload-status-bar {
  height: 8px;
  background: #303030;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 10px;
}

.upload-status-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: #3ea6ff;
  transition: width 0.2s ease;
}

.upload-status p {
  font-size: 14px;
  color: #ccc;
  margin: 0;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.video-list-admin {
  list-style: none;
}

.video-list-admin li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #303030;
}

.video-list-admin li:last-child {
  border-bottom: none;
}

.video-list-admin img {
  width: 120px;
  height: 68px;
  object-fit: cover;
  border-radius: 8px;
}

.video-list-admin .info {
  flex: 1;
  min-width: 0;
}

.video-list-admin .info strong {
  display: block;
  margin-bottom: 4px;
}

@media (max-width: 1200px) {
  #watch-layout {
    grid-template-columns: 1fr;
  }

  #related .related-thumb {
    width: 120px;
    height: 68px;
  }
}

@media (max-width: 656px) {
  #channel-avatar {
    width: 80px;
    height: 80px;
    margin-top: -40px;
  }

  #channel-name {
    font-size: 24px;
  }

  #video-grid {
    grid-template-columns: 1fr;
  }

  .masthead-center {
    display: none;
  }
}
