:root {
  --bg: #1a1a1a;
  --surface: #2a2a2a;
  --surface-variant: #3a3a3a;
  --primary: #666666;
  --on-primary: #1a1a1a;
  --text: #b8b8b8;
  --text-dim: #8a8a8a;
  --outline: #4a4a4a;
  --placeholder: #333333;
  --player-height: 188px;
  --nav-text: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body { overflow: hidden; }

#app { height: 100%; position: relative; }

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.screen.hidden { display: none !important; }

.screen.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
}

/* Login */
#login-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 12px;
  padding: 28px;
}

.login-card h1 {
  margin: 0 0 8px;
  color: var(--primary);
}

.login-sub {
  margin: 0 0 20px;
  color: var(--text-dim);
}

.ban-card {
  text-align: center;
}

.ban-message {
  margin: 24px 0 0;
  font-size: 1.1rem;
  color: var(--text);
}

.login-card label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.login-card input {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--outline);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}

.login-card button, .secondary-btn, #empty-refresh-btn {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
  cursor: pointer;
}

.error-text { color: #f87171; font-size: 0.9rem; margin: 0 0 8px; }

/* Main layout */
#main-screen {
  height: 100%;
}

#browser-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#player-panel {
  flex-shrink: 0;
  height: var(--player-height);
  background: var(--surface);
  border-top: 1px solid var(--outline);
  padding: 8px 12px;
  position: relative;
}

#player-panel.fullscreen {
  position: fixed;
  inset: 0;
  height: 100%;
  z-index: 50;
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.search-row, .nav-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}

#search-input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--outline);
  background: var(--surface);
  color: var(--text);
}

#browse-title {
  flex: 1;
  margin: 0;
  font-size: 1.1rem;
  color: var(--nav-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--nav-text);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: rgba(255,255,255,0.08); }

#favorites-btn.active { color: var(--primary); }

.browse-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 12px;
  align-content: start;
}

.browse-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  min-width: 0;
}

.browse-card.hidden-item { opacity: 0.5; }

.cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  contain: layout size style;
  flex-shrink: 0;
}

.cover-inner {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--placeholder);
}

.cover-wrap.has-subfolders .cover-inner {
  inset: 4px;
  box-shadow: 0 0 0 2px var(--primary), 0 0 12px color-mix(in srgb, var(--primary) 60%, transparent);
}

.cover-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  max-width: none;
  max-height: none;
}

.cover-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 2.5rem;
}

.progress-bar {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 10px;
  height: 10px;
  border: 2px solid var(--primary);
  border-radius: 6px;
  background: rgba(0,0,0,0.5);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
}

.cover-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.cover-overlay.downloading {
  background: rgba(0, 0, 0, 0.45);
}

.download-ring {
  width: 52px;
  height: 52px;
  transform: rotate(-90deg);
}

.download-ring circle.track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 4;
}

.download-ring circle.fill {
  fill: none;
  stroke: var(--primary);
  stroke-width: 4;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.15s linear;
}

.local-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.local-badge.above-progress {
  bottom: 32px;
}

.local-badge svg {
  width: 20px;
  height: 20px;
  display: block;
}

.card-star-btn,
.card-play-btn {
  position: absolute;
  z-index: 3;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.card-star-btn {
  top: 0;
  left: 2px;
  width: 48px;
  height: 48px;
  background: transparent;
  color: var(--primary);
}

.card-star-btn svg {
  width: 40px;
  height: 40px;
  display: block;
}

.card-star-btn .star-outline {
  fill: none;
  stroke: currentColor;
  stroke-width: 3.2;
  stroke-linejoin: round;
}

.card-star-btn .star-filled {
  fill: currentColor;
}

.card-play-btn {
  top: 6px;
  right: 6px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
}

.card-play-btn svg {
  width: 20px;
  height: 20px;
  display: block;
  margin-left: 2px;
}

.card-play-btn:hover {
  filter: brightness(1.08);
}

.card-name {
  font-size: 0.85rem;
  line-height: 1.2;
  text-align: center;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.loading-panel, .empty-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--outline);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.status-text {
  padding: 4px 12px;
  font-size: 0.85rem;
  color: var(--primary);
}

/* Player */
.player-idle, .player-active, .player-fullscreen {
  height: 100%;
}

.player-top {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 6px;
}

.player-thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  border: none;
  background: var(--placeholder);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  cursor: pointer;
}

.player-thumb.large {
  width: min(280px, 70vw);
  height: min(280px, 70vw);
  margin: 0 auto 16px;
  display: block;
}

.player-meta { flex: 1; min-width: 0; }

.player-title {
  font-size: 0.95rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-sub {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-idle {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-idle .settings-btn { margin-left: auto; }

#seek-slider, #seek-slider-fs {
  width: 100%;
  accent-color: var(--primary);
}

.time-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.9);
  margin-bottom: 4px;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
}

.controls-row .settings-btn {
  position: absolute;
  right: 0;
}

.play-btn {
  width: 72px;
  height: 72px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-btn.large { width: 120px; height: 120px; }

.player-fs-title {
  text-align: center;
  font-size: 1.2rem;
  color: #fff;
  margin-bottom: 12px;
}

/* Settings */
.settings-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--outline);
}

.settings-header h2 { margin: 0; flex: 1; }

.settings-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-body label {
  font-size: 0.9rem;
  margin-top: 8px;
}

.setting-value { color: var(--text-dim); font-size: 0.85rem; }

.color-row {
  display: flex;
  gap: 8px;
}

.color-row input[type="color"] {
  width: 48px;
  height: 40px;
  border: none;
  padding: 0;
  background: none;
}

.color-row input[type="text"] {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--outline);
  background: var(--surface);
  color: var(--text);
}

.secondary-btn { margin-top: 12px; }

.danger-btn {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  background: #b3261e;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

.danger-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.local-files-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.local-files-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
  gap: 8px;
  padding: 24px;
}

.local-files-empty .hint {
  margin: 0;
  font-size: 0.9rem;
  max-width: 280px;
}

.local-files-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.local-files-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--outline);
}

.local-files-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  color: var(--primary);
}

.local-files-meta {
  flex: 1;
  min-width: 0;
}

.local-files-name {
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.local-files-size {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.local-files-delete {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
}

.local-files-delete:hover {
  color: #f2b8b5;
  background: rgba(179, 38, 30, 0.15);
}

/* Context menu */
.context-menu {
  position: fixed;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  overflow: hidden;
}

.context-title {
  padding: 10px 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--outline);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.context-menu button:hover { background: rgba(255,255,255,0.06); }

.hidden { display: none !important; }

@media (max-width: 600px) {
  :root { --player-height: 170px; }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
