:root {
  --bg: #1b1f3b;
  --bg2: #262c53;
  --accent: #ff9f45;
  --accent2: #4dd0e1;
  --text: #ffffff;
  --text-dim: #b8bce0;
  --card: #2c3364;
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Verdana, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body.night #app { background: #05060f; }
body.night { --bg: #05060f; --card: #10132a; --text-dim: #6a6f9a; }

/* ---------- Login ---------- */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 20%, var(--bg2), var(--bg));
}
.login-card {
  text-align: center;
  padding: 24px;
  width: 320px;
  max-width: 90vw;
}
.logo { font-size: 32px; font-weight: 800; margin-bottom: 24px; }
.login-msg { min-height: 24px; color: var(--accent); font-weight: 600; margin-bottom: 8px; }
.pin-display {
  font-size: 28px;
  letter-spacing: 6px;
  min-height: 40px;
  margin-bottom: 20px;
}
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.pin-pad button {
  font-size: 26px;
  padding: 20px 0;
  border-radius: var(--radius);
  border: none;
  background: var(--card);
  color: var(--text);
  font-weight: 700;
}
.pin-pad button:active { background: var(--accent); }
.key-ok { background: #2e7d32 !important; }
.key-del { background: #7d2e2e !important; }

/* ---------- App shell ---------- */
#app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--bg2);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar .brand { font-size: 20px; font-weight: 800; }
.topbar .actions { display: flex; gap: 10px; }
.icon-btn {
  background: var(--card);
  border: none;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 18px;
}

.tabs { display: flex; gap: 8px; padding: 10px 18px; overflow-x: auto; }
.tabs button {
  background: var(--card);
  border: none;
  color: var(--text-dim);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
}
.tabs button.active { background: var(--accent); color: #1b1f3b; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
  padding: 10px 18px 100px;
}
.tile {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.tile img { width: 100%; aspect-ratio: 1/1; object-fit: cover; display: block; background: #000; }
.tile .badge {
  position: relative;
  margin-top: -30px;
  align-self: flex-end;
  background: rgba(0,0,0,0.6);
  padding: 3px 8px;
  border-radius: 8px 0 0 0;
  font-size: 12px;
}
.tile .title { padding: 10px 10px 4px; font-weight: 700; font-size: 15px; }
.tile .sub { padding: 0 10px 10px; font-size: 12px; color: var(--text-dim); }
.tile.yt img { aspect-ratio: 16/9; }

.empty-state { padding: 40px 18px; text-align: center; color: var(--text-dim); font-size: 16px; }

/* ---------- Player ---------- */
.player-view {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.player-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
}
.player-top button { background: none; border: none; color: var(--text); font-size: 22px; }

.player-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 20px 20px;
}
.cover-wrap { position: relative; width: min(280px, 70vw); aspect-ratio: 1/1; }
.cover-wrap canvas { position: absolute; inset: -20px; width: calc(100% + 40px); height: calc(100% + 40px); }
.cover-wrap img { position: relative; width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,0.5); }

video.video-player, .yt-embed-wrap iframe {
  width: 100%;
  max-width: 720px;
  aspect-ratio: 16/9;
  border-radius: var(--radius);
  border: none;
  background: #000;
}
.yt-embed-wrap { width: 100%; display: flex; justify-content: center; }

.track-title { font-size: 20px; font-weight: 800; margin-top: 16px; text-align: center; }
.track-sub { color: var(--text-dim); margin-top: 4px; }

.progress-row { width: 100%; max-width: 500px; margin-top: 18px; display: flex; align-items: center; gap: 10px; }
.progress-row input[type=range] { flex: 1; }
.time { font-size: 13px; color: var(--text-dim); width: 46px; text-align: center; }

.controls-row { display: flex; align-items: center; gap: 22px; margin-top: 20px; }
.controls-row button { background: var(--card); border: none; color: var(--text); border-radius: 50%; width: 56px; height: 56px; font-size: 20px; }
.controls-row .play-btn { width: 76px; height: 76px; font-size: 28px; background: var(--accent); color: #1b1f3b; }

.tool-row { display: flex; gap: 12px; margin-top: 26px; flex-wrap: wrap; justify-content: center; }
.tool-row button { background: var(--card); border: none; color: var(--text-dim); padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 13px; }
.tool-row button.active { background: var(--accent2); color: #1b1f3b; }

.playlist-box { width: 100%; max-width: 600px; margin: 24px auto 40px; padding: 0 18px; }
.playlist-box .pl-item { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; }
.playlist-box .pl-item.current { background: var(--card); }
.playlist-box .pl-item img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.playlist-box .pl-item .n { flex: 1; font-size: 14px; }

.subtitle-box {
  position: relative;
  margin-top: 10px;
  max-width: 500px;
  text-align: center;
  font-size: 15px;
  color: var(--text-dim);
  min-height: 20px;
}

/* ---------- Menus / overlays ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 30; display: flex; align-items: flex-end; }
.sheet { background: var(--bg2); width: 100%; border-radius: 20px 20px 0 0; padding: 20px; max-height: 70vh; overflow-y: auto; }
.sheet h3 { margin-top: 0; }
.sheet .opt-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.sheet .opt-row button { background: var(--card); border: none; color: var(--text); padding: 12px 18px; border-radius: 12px; font-weight: 700; }
.sheet .opt-row button.active { background: var(--accent); color: #1b1f3b; }
.sheet .close-btn { display: block; width: 100%; padding: 14px; background: var(--card); border: none; color: var(--text); border-radius: 12px; margin-top: 10px; font-weight: 700; }

.locked-banner {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 30px;
}
.locked-banner .big { font-size: 60px; margin-bottom: 10px; }

@media (min-width: 700px) {
  .player-stage { padding-top: 20px; }
  .cover-wrap { width: 320px; }
}
