:root {
  --bg: #f7f7fa;
  --fg: #1a1a1a;
  --muted: #666;
  --accent: #2867d4;
  --row-bg: #fff;
  --border: #e2e2ea;
  --btn-bg: #2867d4;
  --btn-fg: #fff;
  --btn-bg-hover: #1f54b3;
  --error: #c0392b;
}

* { box-sizing: border-box; }

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

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

header h1 { margin: 0; font-size: 1.5rem; }
#mode-indicator {
  color: var(--muted);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
#mode-indicator .close-edit {
  background: var(--btn-bg);
  color: var(--btn-fg);
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  font-size: 0.9rem;
}
#mode-indicator .close-edit:hover { background: var(--btn-bg-hover); }

main { padding: 1.5rem; max-width: 900px; margin: 0 auto; }

.collection {
  background: var(--row-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.collection-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: #fafafd;
  border-bottom: 1px solid var(--border);
}
.collection.collapsed .collection-header { border-bottom: none; }

.collection-header > .collection-actions { margin-left: auto; }

.collapse-toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  width: 1.5rem;
  padding: 0;
  line-height: 1;
  color: var(--muted);
}
.collapse-toggle:hover { color: var(--fg); }

.collection-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.collection-header input.rename {
  font-size: 1.1rem;
  border: 1px solid var(--border);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.collection-actions button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  margin-left: 0.25rem;
}

.collection-actions button:hover { background: #eef; }

.add-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.add-form input {
  flex: 1;
  padding: 0.5rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.add-form button {
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: none;
  border-radius: 4px;
  padding: 0 1rem;
  cursor: pointer;
  font-size: 1rem;
}
.add-form button:hover { background: var(--btn-bg-hover); }

.video-list { list-style: none; padding: 0; margin: 0; }

.video-row {
  display: flex;
  align-items: stretch;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
}
.video-row:last-child { border-bottom: none; }

.video-thumb {
  flex: 0 0 160px;
  height: 90px;
  background: #ddd;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.video-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.video-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}
.video-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.video-meta { color: var(--muted); font-size: 0.85rem; }

.video-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.video-actions button {
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  cursor: pointer;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.video-actions button:hover { background: var(--btn-bg-hover); }
.video-actions button.remove {
  background: #fff;
  color: var(--error);
  border: 1px solid var(--border);
  font-size: 1.2rem;
}
.video-actions button.remove:hover { background: #fee; }

.progress {
  width: 100%;
  height: 8px;
  background: #eee;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 0.5rem;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease-out;
}

.error-msg {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

#player-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  align-items: center; justify-content: center;
  z-index: 100;
  display: none;
}
#player-overlay.open { display: flex; }
.player-box {
  position: relative;
  width: min(90vw, 1280px);
  background: #000;
}
#player {
  width: 100%;
  height: auto;
  display: block;
  max-height: 85vh;
}
#player-close {
  position: absolute;
  top: -2.5rem;
  right: 0;
  background: transparent;
  color: #fff;
  font-size: 1.5rem;
  border: none;
  cursor: pointer;
}

.app-toolbar {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 1rem auto;
}
.app-toolbar button {
  padding: 0.5rem 1rem;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.app-toolbar button:hover { background: var(--btn-bg-hover); }
.app-toolbar .new-collection { margin: 0; }

.new-collection {
  display: block;
  margin: 1rem auto;
  padding: 0.5rem 1rem;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}
