:root {
  --bg: #0f1a24;
  --bg-deep: #08111a;
  --panel: #13202c;
  --panel-hover: #162533;
  --text: #ffffff;
  --text-soft: #cccccc;
  --text-muted: #a3a3a3;
  --pink: #ffd4d4;
  --yellow: #ffdf10;
  --counter-bg: #ffd600;
  --counter-text: #806b00;
  --green: #27ae60;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-width: 320px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

button { font: inherit; }

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Nav */
.nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-logo img { height: 40px; display: block; }
.nav-badge {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--yellow);
  padding: 6px 12px;
  border-radius: 100px;
}

/* Hero */
.hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: end;
  margin: 48px 0 32px;
}
.subtitle {
  font-size: 14px;
  letter-spacing: 3.5px;
  color: var(--text-soft);
  margin: 0 0 22px;
}
.title {
  font-weight: 800;
  font-size: 43px;
  line-height: 52px;
  margin: 0 0 16px;
}
.title span { color: var(--pink); }
.lead { margin: 0; line-height: 1.6; color: var(--text-soft); }

.search {
  position: relative;
}
.search input {
  width: 100%;
  background: var(--bg-deep);
  color: #e6e6e6;
  padding: 22px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  outline: none;
}
.search input::placeholder { color: grey; }
.search input:focus { box-shadow: 0 0 0 2px var(--yellow); }

/* Category pills */
.cats {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 8px;
}
.cat {
  flex: none;
  border: 1px solid #2a3a48;
  background: transparent;
  color: var(--text-soft);
  padding: 10px 20px;
  border-radius: 100px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
.cat:hover { border-color: var(--text-soft); }
.cat.active {
  background: var(--yellow);
  border-color: var(--yellow);
  color: #000;
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 40px 24px;
  margin: 32px 0 64px;
}
.card {
  display: block;
  text-decoration: none;
  cursor: pointer;
}
.thumb {
  aspect-ratio: 3 / 4;
  border-radius: 16px;
  overflow: hidden;
  background: var(--panel);
  margin-bottom: 11px;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .25s ease;
}
.card:hover .thumb img { transform: scale(1.03); }
.card-category {
  color: var(--green);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  margin: 0 0 6px;
}
.card-title {
  font-weight: 700;
  font-size: 18px;
  line-height: 22px;
  margin: 0;
}

.empty {
  text-align: center;
  padding: 120px 0;
}
.empty h5 { color: #ff3f05; font-size: 12px; margin: 0 0 12px; letter-spacing: 1px; }
.empty h1 { font-size: 32px; margin: 0 0 8px; }
.empty p { color: var(--text-muted); margin: 0; }

/* Detail */
.detail-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 8px 0 24px;
  flex-wrap: wrap;
}
.back {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid #2a3a48;
  display: grid;
  place-items: center;
  text-decoration: none;
  font-size: 20px;
  flex: none;
}
.back:hover { border-color: var(--text-soft); }
.crumbs { font-size: 13px; color: var(--text-muted); margin-bottom: 2px; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.detail-title { font-size: 22px; font-weight: 800; margin: 0; }
.detail-head .spacer { flex: 1; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--yellow);
  color: #000;
  font-weight: 700;
  font-size: 14px;
  padding: 12px 20px;
  border-radius: 100px;
  text-decoration: none;
  border: none;
  cursor: pointer;
}
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid #2a3a48;
}

.detail-body {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  margin-bottom: 48px;
}
.detail-body.no-topics { grid-template-columns: 1fr; }

.topics {
  background: var(--panel);
  border-radius: 24px;
  padding: 16px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  position: sticky;
  top: 16px;
  align-self: start;
}
.topics h3 {
  color: #d1d8de;
  font-size: 14px;
  margin: 0;
  padding: 16px;
}
.topic {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-radius: 16px;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  margin-bottom: 8px;
}
.topic:hover { background: var(--panel-hover); }
.topic.active { background: var(--bg); }
.counter {
  flex: none;
  width: 54px;
  height: 54px;
  border-radius: 10.8px;
  background: var(--counter-bg);
  color: var(--counter-text);
  font-weight: 800;
  display: grid;
  place-items: center;
  position: relative;
}
.counter .play {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ff0033;
  color: #fff;
  font-size: 9px;
  display: grid;
  place-items: center;
}
.topic h4 { margin: 0; font-size: 14px; line-height: 20px; }
.topic p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 18px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.viewer {
  background: #000;
  border-radius: 24px;
  padding: 24px;
  min-width: 0;
}
.video-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--panel);
  border-radius: 16px;
  padding: 20px 24px;
  margin-bottom: 24px;
}
.video-note h2 { margin: 0 0 4px; font-size: 20px; font-weight: 800; }
.video-note p { margin: 0; color: var(--text-muted); font-size: 14px; }
.pdf {
  width: 100%;
  height: calc(100vh - 160px);
  min-height: 480px;
  border: none;
  border-radius: 12px;
  background: #1a1a1a;
  display: block;
}
.pdf-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 16px;
}
.no-file {
  color: var(--text-muted);
  text-align: center;
  padding: 120px 24px;
}

.footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 48px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid #1c2b38;
}

/* Mobile / PWA polish */
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  overflow-x: hidden;
}
.nav { padding-top: max(24px, env(safe-area-inset-top)); }
.cats { scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.cats::-webkit-scrollbar { display: none; }
.card-title, .detail-title, .topic h4 { overflow-wrap: anywhere; }
.pdf { height: calc(100dvh - 160px); }
.pdf-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  background: var(--panel);
  border-radius: 16px;
  padding: 40px 20px;
  overflow-wrap: anywhere;
}
.pdf-fallback p { margin: 0; color: var(--text-soft); font-weight: 600; }
@media (pointer: coarse) {
  .btn, .cat { min-height: 44px; }
  .back { width: 44px; height: 44px; }
  .topic { min-height: 64px; }
}

@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
  .detail-body { grid-template-columns: 1fr; }
  .topics { position: static; max-height: 360px; }
}

@media (max-width: 640px) {
  .wrap, .nav, .footer { padding-left: 16px; padding-right: 16px; }
  .hero { grid-template-columns: 1fr; margin-top: 24px; gap: 20px; }
  .title { font-size: 28px; line-height: 1.3; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 24px 16px; }
  .card-title { font-size: 15px; line-height: 19px; }
  .search input { padding: 16px 20px; font-size: 16px; } /* 16px stops iOS zoom-on-focus */
  .viewer { padding: 12px; border-radius: 16px; }
  .pdf { height: 70dvh; min-height: 360px; }
  .nav { padding-left: 16px; padding-right: 16px; }
  .nav-badge { font-size: 11px; padding: 5px 10px; }
  .detail-title { font-size: 18px; }
  .video-note, .pdf-actions { flex-direction: column; align-items: stretch; }
  .video-note .btn, .pdf-actions .btn { justify-content: center; }
  .footer { flex-direction: column; }
}
