:root {
  --bg: #0b0f19;
  --bg-card: #171d2e;
  --bg-card-selected: #2a3557;
  --accent: #e8a33d;
  --accent-dark: #b8791e;
  --text: #f4f1ea;
  --text-dim: #9aa3b8;
  --focus-ring: #ffffff;
  --danger: #c0392b;
}

* {
  box-sizing: border-box;
}

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

.view {
  width: 100vw;
  height: 100vh;
  display: none;
  flex-direction: column;
}

.view.active {
  display: flex;
}

/* ---------- Selection view ---------- */

#view-selection {
  padding: 3vh 4vw;
}

.header {
  text-align: center;
  margin-bottom: 1.2vh;
}

.header h1 {
  font-size: 3.2vw;
  margin: 0 0 0.3em 0;
  color: var(--accent);
}

.header p {
  font-size: 1.4vw;
  color: var(--text-dim);
  margin: 0;
}

.count-select-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7vw;
  font-size: 1.2vw;
  color: var(--text-dim);
  margin-top: 1.2vh;
}

#count-select {
  font-size: 1.3vw;
  font-weight: 700;
  padding: 0.5vh 1vw;
  border-radius: 10px;
  border: 3px solid var(--text-dim);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
}

#count-select:focus,
#count-select:focus-visible {
  outline: none;
  border-color: var(--focus-ring);
}

#grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  grid-auto-rows: 1fr;
  gap: 1.4vh 1.2vw;
  overflow-y: auto;
  padding: 0.5vh 0.5vw;
}

.video-card {
  position: relative;
  background: linear-gradient(135deg, var(--bg-card), #1e2740);
  border: 4px solid transparent;
  border-radius: 16px;
  padding: 1.4vh 1.2vw;
  min-height: 110px;
  color: var(--text);
  font-size: 1.3vw;
  font-weight: 600;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.video-card:focus,
.video-card:focus-visible {
  outline: none;
  border-color: var(--focus-ring);
  transform: scale(1.06);
  z-index: 2;
}

.video-card.selected {
  background: linear-gradient(135deg, var(--bg-card-selected), #3a4a80);
  border-color: var(--accent);
}

.video-card .badge {
  position: absolute;
  top: -14px;
  left: -14px;
  width: 3.2vw;
  height: 3.2vw;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1206;
  font-size: 1.6vw;
  font-weight: 800;
  display: none;
  align-items: center;
  justify-content: center;
}

.video-card.selected .badge {
  display: flex;
}

.footer-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2vw;
  padding-top: 2vh;
}

.btn {
  font-size: 1.8vw;
  font-weight: 700;
  padding: 1.6vh 3vw;
  border-radius: 14px;
  border: 4px solid transparent;
  cursor: pointer;
  color: var(--text);
  background: #2a3557;
}

.btn:focus,
.btn:focus-visible {
  outline: none;
  border-color: var(--focus-ring);
  transform: scale(1.05);
}

.btn-primary {
  background: var(--accent);
  color: #1a1206;
}

.btn-primary:disabled {
  background: #4a4a4a;
  color: #8a8a8a;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  border: 3px solid var(--text-dim);
  color: var(--text-dim);
}

.btn-shuffle {
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: #1a1206;
  margin-top: 1vh;
  font-size: 1.5vw;
}

/* ---------- Player view ---------- */

#view-player {
  background: #000;
  align-items: center;
  justify-content: center;
}

#video-player {
  width: 100%;
  height: 100%;
  background: #000;
}

#player-controls {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5vh;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

#player-controls.visible {
  opacity: 1;
  pointer-events: auto;
}

#player-status {
  color: var(--text);
  font-size: 1.8vw;
  font-weight: 600;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

#control-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6vw;
}

.ctrl-btn {
  width: 6.5vw;
  height: 6.5vw;
  min-width: 84px;
  min-height: 84px;
  border-radius: 50%;
  border: 4px solid transparent;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.ctrl-btn svg {
  width: 55%;
  height: 55%;
  fill: #ffffff;
}

.ctrl-btn-main {
  width: 9.5vw;
  height: 9.5vw;
  min-width: 120px;
  min-height: 120px;
  background: rgba(255, 255, 255, 0.2);
}

.ctrl-btn:focus,
.ctrl-btn:focus-visible {
  outline: none;
  border-color: var(--focus-ring);
  background: rgba(255, 255, 255, 0.35);
  transform: scale(1.08);
}

#progress-row {
  width: 60vw;
  max-width: 900px;
  display: flex;
  align-items: center;
  gap: 1.5vw;
}

#seek-bar {
  --fill-pct: 0%;
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--fill-pct),
    rgba(255, 255, 255, 0.25) var(--fill-pct),
    rgba(255, 255, 255, 0.25) 100%
  );
  cursor: pointer;
  outline: none;
}

#seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

#seek-bar::-moz-range-track {
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.25);
}

#seek-bar::-moz-range-progress {
  height: 8px;
  border-radius: 4px;
  background: var(--accent);
}

#seek-bar::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

#seek-bar:focus::-webkit-slider-thumb {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

#seek-bar:focus::-moz-range-thumb {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

#progress-time {
  color: var(--text);
  font-size: 1.2vw;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

.ctrl-btn-close {
  position: absolute;
  top: 3vh;
  right: 3vw;
  width: 3.5vw;
  height: 3.5vw;
  min-width: 48px;
  min-height: 48px;
}

/* ---------- End view ---------- */

#view-end {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 3vh;
}

#view-end h2 {
  font-size: 3vw;
  color: var(--accent);
  margin: 0;
}

.end-logo {
  width: 9vw;
  min-width: 90px;
  max-width: 160px;
  border-radius: 16px;
}

.like-btn {
  width: 4.4vw;
  height: 4.4vw;
  min-width: 60px;
  min-height: 60px;
  border-radius: 50%;
  border: 3px solid var(--text-dim);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.like-btn svg {
  width: 55%;
  height: 55%;
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 2;
  transition: fill 0.15s ease, stroke 0.15s ease;
}

.like-btn.liked {
  border-color: var(--accent);
}

.like-btn.liked svg {
  fill: var(--accent);
  stroke: var(--accent);
  animation: likePop 0.35s ease;
}

@keyframes likePop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}

.like-btn:focus,
.like-btn:focus-visible {
  outline: none;
  border-color: var(--focus-ring);
  transform: scale(1.08);
}

/* ---------- Footer ---------- */

#site-footer {
  position: fixed;
  bottom: 0.8vh;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.85vw;
  color: var(--text-dim);
  opacity: 0.55;
  pointer-events: none;
}

#site-footer a {
  color: var(--text-dim);
  text-decoration: none;
  pointer-events: auto;
}

#site-footer a:hover,
#site-footer a:focus {
  color: var(--accent);
  text-decoration: underline;
  outline: none;
}
