* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242836;
  --text: #e8eaf0;
  --muted: #9aa0b0;
  --accent: #ff4d5e;
  --accent-soft: rgba(255, 77, 94, 0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 28px;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid #2b2f3d;
}

#logo { font-size: 1.15rem; white-space: nowrap; cursor: pointer; }

#search-form { display: flex; flex: 1; max-width: 640px; gap: 8px; }

#search-input {
  flex: 1;
  padding: 10px 16px;
  border-radius: 22px;
  border: 1px solid #333849;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
#search-input:focus { border-color: var(--accent); }

button {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 9px 16px;
  border-radius: 20px;
  border: 1px solid #333849;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #2e3344; }
button.active, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #ff6572; }

main { max-width: 1100px; margin: 0 auto; padding: 28px; }

h2 { font-size: 1.05rem; margin: 18px 0 14px; color: var(--muted); font-weight: 600; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  border: 1px solid transparent;
}
.card:hover { transform: translateY(-3px); border-color: #3a4054; }

.card .thumb { position: relative; aspect-ratio: 16/9; background: #000; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .duration {
  position: absolute; right: 6px; bottom: 6px;
  background: rgba(0,0,0,0.85); color: #fff;
  font-size: 0.75rem; padding: 2px 6px; border-radius: 4px;
}
.card .info { padding: 10px 12px 12px; }
.card .title {
  font-size: 0.9rem; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .meta { font-size: 0.78rem; color: var(--muted); margin-top: 6px; }

#empty-state { text-align: center; padding: 80px 20px; color: var(--muted); }
#empty-state .hint { margin-top: 10px; font-size: 0.85rem; }

.spinner {
  width: 36px; height: 36px; margin: 60px auto;
  border: 3px solid var(--surface-2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Player view */
#back-btn { margin-bottom: 16px; }

#player-wrap {
  position: relative;
  aspect-ratio: 16/9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}
#player-wrap iframe, #player { width: 100%; height: 100%; }

#pause-overlay[hidden] { display: none; }
#pause-overlay {
  position: absolute; inset: 0;
  background: rgba(10, 12, 18, 0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
}
.overlay-inner { text-align: center; }
#overlay-label { font-size: 1.6rem; font-weight: 700; margin-bottom: 18px; }
#countdown {
  font-size: 4.5rem; font-weight: 800; color: var(--accent);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.overlay-hint { margin-top: 16px; color: var(--muted); font-size: 0.9rem; }

#video-title { color: var(--text); font-size: 1.1rem; margin: 16px 0 4px; }

#controls {
  background: var(--surface);
  border-radius: 12px;
  padding: 18px 20px;
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
}
.control-group label {
  display: block; font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); margin-bottom: 8px;
}
.seg-buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
#custom-sec {
  width: 64px; padding: 8px 10px; border-radius: 18px;
  border: 1px solid #333849; background: var(--bg); color: var(--text);
  font-size: 0.9rem; outline: none; text-align: center;
}
#custom-sec:focus { border-color: var(--accent); }

.shortcuts { margin-top: 14px; color: var(--muted); font-size: 0.82rem; }
kbd {
  background: var(--surface-2); border: 1px solid #3a4054;
  border-radius: 4px; padding: 1px 6px; font-size: 0.78rem;
}

@media (max-width: 640px) {
  header { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  #logo { font-size: 1rem; }
  #search-form { flex-basis: 100%; order: 2; }
  main { padding: 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  #controls { flex-direction: column; gap: 16px; padding: 14px 16px; }
  .seg-buttons button { padding: 10px 14px; }
  #overlay-label { font-size: 1.15rem; }
  #countdown { font-size: 3rem; }
  .shortcuts { display: none; }
}

/* Safe areas for iPhone home-screen (standalone) mode */
@supports (padding: env(safe-area-inset-top)) {
  header { padding-top: calc(14px + env(safe-area-inset-top)); }
  main { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
}
