:root {
  color-scheme: light;
  --bg: #fef9f0;
  --ink: #2d2a4a;
  --card-bg: #ffffff;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.08);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body.no-scroll {
  overflow: hidden;
}

img {
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: linear-gradient(135deg, #ffd93d, #ff9f1c);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.logo {
  margin: 0;
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-emoji {
  font-size: 1.4em;
}

.back-btn {
  border: none;
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.back-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

.section-title {
  text-align: center;
  font-size: clamp(1.4rem, 4vw, 2rem);
  margin: 8px 0 24px;
}

.grid {
  display: grid;
  gap: 20px;
}

.categories-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.videos-grid {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.card {
  border: none;
  border-radius: 24px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  transition: transform 0.15s ease;
}

.card:active {
  transform: translateY(3px) scale(0.98);
  box-shadow: none;
}

.category-card {
  border-top: 8px solid var(--card-color, #ff9f1c);
  min-height: 160px;
  justify-content: center;
}

.card-emoji {
  font-size: 3rem;
  line-height: 1;
}

.card-title {
  font-size: 1.2rem;
  font-weight: 800;
}

.card-subtitle {
  font-size: 0.9rem;
  opacity: 0.65;
}

.video-card {
  padding: 12px;
}

.thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  overflow: hidden;
  background: #eee;
}

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

.play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  background: rgba(0, 0, 0, 0.15);
}

.video-title {
  margin-top: 10px;
  font-size: 1rem;
  font-weight: 700;
}

.player-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 40, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: env(safe-area-inset-top, 16px) 16px env(safe-area-inset-bottom, 16px);
}

.player-frame {
  width: 100%;
  max-width: 960px;
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.player-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.close-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  right: 16px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: #2d2a4a;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.footer {
  text-align: center;
  font-size: 0.8rem;
  color: #8a8598;
  padding: 12px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1b2e;
    --ink: #f4f1ff;
    --card-bg: #2c2740;
    --shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
  }

  .card-subtitle {
    opacity: 0.75;
  }

  .footer {
    color: #a29bc2;
  }
}
