* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #111118;
  color: #e4e4ec;
  line-height: 1.5;
}

button {
  background: #5b7cf7;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover { background: #4a6ae0; }
button:disabled { background: #444458; cursor: not-allowed; }

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 12px;
  border: 1px solid #2e2e40;
  border-radius: 8px;
  background: #1a1a28;
  color: #e4e4ec;
  font-size: 1rem;
}
input[type="text"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: #5b7cf7;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: #9898b0;
}
.form-group { margin-bottom: 16px; }

.settings-view {
  max-width: 400px;
  margin: 60px auto;
  padding: 24px;
  background: #1c1c28;
  border-radius: 12px;
}
.settings-view h2 { margin-bottom: 24px; text-align: center; }
.settings-view .error { color: #ef4444; margin-bottom: 16px; font-size: 0.9rem; }

.library-view { display: none; }
.library-view.active { display: block; }

.library-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: #161620;
  border-bottom: 1px solid #2a2a38;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}
.library-header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.header-spacer { flex: 1; min-width: 8px; }

.search-wrapper {
  position: relative;
  flex: 0 1 300px;
  min-width: 160px;
}
.search-wrapper svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  fill: #666680;
  pointer-events: none;
}
.search-wrapper input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  border: 1px solid #2a2a38;
  border-radius: 24px;
  background: #1a1a28;
  color: #e4e4ec;
  font-size: 0.9rem;
}
.search-wrapper input:focus {
  outline: none;
  border-color: #5b7cf7;
  background: #1e1e2e;
}
.search-wrapper input::placeholder { color: #555568; }

.view-toggle {
  display: flex;
  background: #1a1a28;
  border-radius: 20px;
  padding: 3px;
  border: 1px solid #2a2a38;
  flex-shrink: 0;
}
.toggle-btn {
  background: transparent;
  color: #8888a0;
  border: none;
  padding: 6px 16px;
  border-radius: 18px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.toggle-btn:hover {
  color: #c0c0d0;
  background: rgba(255,255,255,0.05);
}
.toggle-btn.active {
  background: #5b7cf7;
  color: white;
}
.toggle-btn.active:hover { background: #4a6ae0; }

.btn-disconnect {
  background: transparent;
  border: 1px solid #3a3a4a;
  color: #9898b0;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.btn-disconnect:hover { background: #242434; border-color: #4a4a5a; }

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.loading {
  text-align: center;
  padding: 80px 20px;
  color: #666680;
  font-size: 0.95rem;
}
.loading::after {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  margin: 16px auto;
  border: 3px solid #2a2a38;
  border-top-color: #5b7cf7;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.year-section { margin-top: 40px; }
.year-section:first-child { margin-top: 0; }
.year-label {
  font-size: 1.4rem;
  font-weight: 700;
  color: #e4e4ec;
  margin-bottom: 20px;
  padding-bottom: 8px;
  border-bottom: 2px solid #2a2a38;
  letter-spacing: -0.02em;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}
.video-card {
  background: #1c1c28;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.video-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
}
.video-card:active { transform: scale(0.98); }

.video-card-thumb {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  background: #242434;
  overflow: hidden;
}
.video-card-thumb img {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.video-card-thumb .play-overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: 48px; height: 48px;
  background: rgba(0,0,0,0.65);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}
.video-card:hover .play-overlay {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.video-card-thumb .play-overlay svg {
  width: 22px; height: 22px;
  fill: white;
  margin-left: 2px;
}
.no-thumb {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1e1e30;
}
.no-thumb svg { width: 40px; height: 40px; fill: #3a3a50; }

.video-card-info { padding: 12px 14px 14px; }
.video-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}
.video-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: #7878a0;
  flex-wrap: wrap;
}
.date-badge {
  background: #2a2a40;
  color: #9898c0;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}
.tape-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tape-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}
.tape-card {
  background: #1c1c28;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.tape-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
}
.tape-card:active { transform: scale(0.98); }

.tape-card-mosaic {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  aspect-ratio: 16 / 9;
  background: #242434;
  overflow: hidden;
  gap: 2px;
}
.tape-card-mosaic.single { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.tape-card-mosaic.double { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.tape-card-mosaic img { width: 100%; height: 100%; object-fit: cover; }
.mosaic-placeholder {
  background: #1e1e30;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mosaic-placeholder svg { width: 28px; height: 28px; fill: #3a3a50; }

.tape-card-info { padding: 14px 16px; }
.tape-card-title { font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.tape-card-meta { font-size: 0.82rem; color: #7878a0; }
.tape-card-count {
  display: inline-block;
  background: #2a2a40;
  color: #9898c0;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-left: 6px;
}

.tape-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.tape-back-btn {
  background: #242434;
  border: 1px solid #2a2a38;
  color: #e4e4ec;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.tape-back-btn:hover { background: #2e2e40; }
.tape-back-btn svg { width: 18px; height: 18px; fill: currentColor; }
.tape-detail-title { font-size: 1.2rem; font-weight: 700; }
.tape-detail-meta {
  font-size: 0.85rem;
  color: #7878a0;
  margin-left: auto;
}

.no-results {
  text-align: center;
  padding: 80px 20px;
  color: #555568;
}
.no-results svg { width: 48px; height: 48px; fill: #3a3a50; margin-bottom: 12px; }
.no-results p { font-size: 0.95rem; }

.preview-scrubber {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 5;
}
.preview-scrubber img { width: 100%; height: 100%; object-fit: cover; }
.scrub-indicator {
  position: absolute;
  bottom: 0; left: 0;
  height: 3px;
  background: #5b7cf7;
  transition: width 0.05s;
}

.player-view {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #000;
  z-index: 200;
  flex-direction: column;
}
.player-view.active { display: flex; }

.player-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: rgba(0,0,0,0.8);
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  transition: opacity 0.3s, visibility 0.3s;
}
.player-view:not(.controls-visible) .player-header {
  opacity: 0; visibility: hidden;
}

.back-btn {
  background: none;
  border: none;
  color: white;
  padding: 8px;
  margin-right: 12px;
  cursor: pointer;
  border-radius: 50%;
}
.back-btn:hover { background: rgba(255,255,255,0.1); }
.back-btn svg { width: 24px; height: 24px; fill: currentColor; }

.player-title {
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.video-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
  position: relative;
  min-height: 0;
  cursor: pointer;
}
video { width: 100%; height: 100%; object-fit: contain; }

.player-loading {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: #888;
}
.player-loading.buffering {
  display: block;
  font-size: 0;
  width: 40px; height: 40px;
  margin-left: -20px; margin-top: -20px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  transform: none;
}

.player-view { cursor: none; }
.player-view.controls-visible { cursor: default; }

.player-controls {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 10;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  padding: 20px 16px 12px;
  transition: opacity 0.3s, visibility 0.3s;
}
.player-view:not(.controls-visible) .player-controls {
  opacity: 0; visibility: hidden;
}

.progress-bar {
  position: relative;
  width: 100%; height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  cursor: pointer;
  margin-bottom: 10px;
  transition: height 0.15s;
}
.progress-bar::before {
  content: '';
  position: absolute;
  top: -10px; bottom: -10px; left: 0; right: 0;
}
.progress-bar:hover, .progress-bar.dragging { height: 8px; }
.progress-buffered {
  position: absolute; top: 0; left: 0; height: 100%;
  background: rgba(255,255,255,0.3);
  border-radius: 2px; pointer-events: none;
}
.progress-played {
  position: absolute; top: 0; left: 0; height: 100%;
  background: #5b7cf7;
  border-radius: 2px; pointer-events: none;
}
.progress-thumb {
  position: absolute; top: 50%;
  width: 14px; height: 14px;
  background: #5b7cf7;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none; opacity: 0;
  transition: opacity 0.15s;
}
.progress-bar:hover .progress-thumb,
.progress-bar.dragging .progress-thumb { opacity: 1; }

.controls-row { display: flex; align-items: center; gap: 4px; }
.controls-spacer { flex: 1; }

.ctrl-btn {
  background: none; border: none; color: white;
  padding: 8px; cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px;
}
.ctrl-btn:hover { background: rgba(255,255,255,0.1); }
.ctrl-btn svg { width: 24px; height: 24px; fill: currentColor; }

#play-pause-btn .icon-pause { display: none; }
#play-pause-btn.playing .icon-play { display: none; }
#play-pause-btn.playing .icon-pause { display: block; }

#mute-btn .icon-vol-muted { display: none; }
#mute-btn.muted .icon-vol-high { display: none; }
#mute-btn.muted .icon-vol-muted { display: block; }

#fullscreen-btn .icon-fs-exit { display: none; }
#fullscreen-btn.is-fullscreen .icon-fs-enter { display: none; }
#fullscreen-btn.is-fullscreen .icon-fs-exit { display: block; }

.time-display {
  color: #ddd;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  padding: 0 8px;
  white-space: nowrap;
  user-select: none;
}

.volume-control { display: flex; align-items: center; }
.volume-slider {
  width: 0; opacity: 0;
  transition: width 0.2s, opacity 0.2s;
  -webkit-appearance: none; appearance: none;
  height: 4px;
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
  outline: none; cursor: pointer;
  border: none; padding: 0;
}
.volume-control:hover .volume-slider,
.volume-slider:focus { width: 80px; opacity: 1; }
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%; background: white; cursor: pointer;
}
.volume-slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%; background: white; cursor: pointer;
  border: none;
}

@media (max-width: 768px) {
  .search-wrapper { order: 10; flex: 1 0 100%; }
  .container { padding: 16px; }
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
  .tape-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
  .year-label { font-size: 1.2rem; }
}
@media (max-width: 480px) {
  .library-header { padding: 12px 16px; gap: 10px; }
  .library-header h1 { font-size: 1.05rem; }
  .video-grid { grid-template-columns: 1fr; }
  .tape-grid { grid-template-columns: 1fr; }
  .container { padding: 12px; }
  .volume-slider { display: none; }
  .player-controls { padding: 16px 8px 8px; }
}
