:root {
  color-scheme: dark;
  --bg: #070708;
  --surface: #141417;
  --surface-2: #1d1d22;
  --text: #f5f5f7;
  --muted: #9b9ba7;
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.18);
  --glass: rgba(18, 18, 22, 0.72);
  --border: rgba(255, 255, 255, 0.08);
  --danger: #ff6b6b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  touch-action: manipulation;
}

button,
input[type="range"] {
  font: inherit;
}

#app {
  min-height: 100%;
}

.view {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
}

.view.active {
  display: block;
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.library-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: calc(18px + var(--safe-top)) calc(18px + var(--safe-right)) 12px
    calc(18px + var(--safe-left));
}

.library-header__main {
  min-width: 0;
  flex: 1;
}

.library-header__actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.user-label {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-header h1 {
  margin: 4px 0 0;
  font-size: 1.8rem;
  font-weight: 700;
}

.library-empty {
  margin: 24px 18px;
  padding: 18px;
  border-radius: 18px;
  background: var(--surface);
  color: var(--muted);
  line-height: 1.5;
}

.library-empty code {
  color: var(--text);
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
  gap: 14px;
  padding: 8px calc(16px + var(--safe-right)) calc(24px + var(--safe-bottom))
    calc(16px + var(--safe-left));
}

.video-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.video-card__thumb-wrap {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: 18px;
  background: var(--surface-2);
  aspect-ratio: 16 / 10;
}

.video-card__thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-card__duration {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.video-card__title {
  display: block;
  padding: 0 4px;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
}

.player-stage {
  position: relative;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background: #000;
  overflow: hidden;
}

#screen {
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: block;
  background: #000;
  object-fit: contain;
}

.player-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.player-status.hidden {
  display: none;
}

.subtitle-overlay {
  position: absolute;
  left: 50%;
  bottom: calc(120px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: min(92%, 860px);
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: clamp(0.95rem, 2.4vw, 1.25rem);
  line-height: 1.35;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  pointer-events: none;
  white-space: pre-wrap;
  z-index: 3;
}

.subtitle-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.subtitle-picker__label {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.72);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.subtitle-select {
  min-width: 108px;
  max-width: 160px;
  padding: 8px 10px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font: inherit;
}

.subtitle-select option {
  color: #111;
}

.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + var(--safe-top)) calc(12px + var(--safe-right)) 12px
    calc(12px + var(--safe-left));
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.72), transparent);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.now-playing {
  min-width: 0;
  flex: 1;
}

.now-playing__title {
  margin: 2px 0 0;
  font-size: 1rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.control-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px calc(16px + var(--safe-right)) calc(18px + var(--safe-bottom))
    calc(16px + var(--safe-left));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88), rgba(0, 0, 0, 0.35), transparent);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.control-dock.hidden,
.player-stage.controls-hidden .top-bar {
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
}

.seek-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.time-label {
  min-width: 52px;
  font-size: 0.82rem;
  color: #ddd;
  font-variant-numeric: tabular-nums;
}

.time-label:last-child {
  text-align: right;
}

.seek-bar,
.volume-bar {
  flex: 1;
  height: 28px;
  appearance: none;
  background: transparent;
}

.seek-bar::-webkit-slider-runnable-track,
.volume-bar::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.seek-bar::-webkit-slider-thumb,
.volume-bar::-webkit-slider-thumb {
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.transport-row,
.audio-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.audio-row {
  margin-top: 14px;
}

.round-btn {
  position: relative;
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  display: grid;
  place-content: center;
}

.skip-label {
  position: absolute;
  bottom: 11px;
  font-size: 0.62rem;
  font-weight: 700;
  opacity: 0.85;
}

.round-btn--primary .icon-pause {
  display: none;
}

.round-btn svg {
  width: 30px;
  height: 30px;
}

.round-btn--primary {
  width: 78px;
  height: 78px;
  background: var(--accent);
}

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

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

.icon-btn {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: #fff;
  display: grid;
  place-content: center;
}

.icon-btn.glass {
  background: var(--glass);
  backdrop-filter: blur(16px);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

#mute-btn .icon-muted,
#mute-btn.is-muted .icon-volume {
  display: none;
}

#mute-btn.is-muted .icon-muted {
  display: block;
}

.hint {
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.55);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(20, 20, 24, 0.92);
  color: #fff;
  font-size: 0.92rem;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 20;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.login-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(10, 132, 255, 0.18), transparent 42%),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  padding: 28px 24px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}

.login-card h1 {
  margin: 8px 0 10px;
  font-size: 1.6rem;
}

.login-copy {
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.5;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 54px;
  padding: 0 18px;
  border-radius: 14px;
  background: #fff;
  color: #111;
  font-weight: 650;
  text-decoration: none;
}

.google-btn svg {
  width: 22px;
  height: 22px;
}

.login-error {
  margin: 16px 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}

@media (min-width: 768px) {
  .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }

  #screen {
    object-fit: contain;
    max-height: 100dvh;
  }
}
