:root {
  --brand: #9147ff;
  --brand-soft: rgba(145, 71, 255, 0.14);
  --brand-strong: #bf94ff;
  --bg: #0d0f14;
  --panel: #161925;
  --panel-soft: rgba(255, 255, 255, 0.05);
  --panel-strong: #202436;
  --border: rgba(255, 255, 255, 0.12);
  --border-brand: rgba(145, 71, 255, 0.42);
  --text: #f2f3fb;
  --muted: #a7abc1;
  --dim: #747991;
  --danger: #ff5f6d;
  --success: #20d49b;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at top left, rgba(145, 71, 255, 0.16), transparent 34%),
    linear-gradient(180deg, rgba(255,255,255,0.03), transparent 42%),
    var(--bg);
  color: var(--text);
  font-family: Inter, Avenir Next, Hiragino Sans, Yu Gothic, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

a {
  color: var(--brand-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 98px;
  padding: calc(10px + var(--safe-top)) clamp(12px, 2vw, 24px) 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 15, 20, 0.88);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.brand img {
  width: auto;
  max-width: min(58vw, 330px);
  height: clamp(63px, 7.5vw, 84px);
  display: block;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  margin-left: auto;
}

.nav-btn,
.type-tab,
.secondary-btn,
.primary-btn,
.filter-select,
.compact-select,
.date-input,
.search-input {
  min-height: 40px;
  border-radius: var(--radius);
}

.nav-btn {
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}

.nav-btn.active {
  color: var(--text);
  background: var(--panel-soft);
  border-color: var(--border);
}

.badge {
  display: inline-flex;
  justify-content: center;
  min-width: 22px;
  padding: 1px 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--brand);
  color: white;
  font-size: 0.76rem;
}

.compact-select,
.filter-select,
.date-input {
  background: var(--panel-soft);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
}

.main-layout {
  width: min(100%, 1280px);
  margin: 0 auto;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 240px);
  gap: clamp(12px, 2vw, 20px);
  padding: clamp(12px, 2vw, 20px);
}

.main-layout.main-layout-full {
  grid-template-columns: minmax(0, 1fr);
}

.content-area {
  min-width: 0;
}

.tool-panel,
.setup-warning,
.top-ad-wrap,
.ad-card,
.affiliate-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(22, 25, 37, 0.82);
  box-shadow: var(--shadow);
}

.tool-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: clamp(14px, 2vw, 18px);
}

.setup-warning {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-color: rgba(255, 95, 109, 0.4);
  color: #ffd6dc;
}

.setup-warning strong {
  color: white;
}

.type-tabs {
  display: flex;
  justify-content: flex-start;
  gap: 6px;
  flex-wrap: wrap;
}

.type-tab {
  padding: 9px 14px;
  background: var(--panel-soft);
  color: var(--muted);
  border: 1px solid var(--border);
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.type-tab:hover,
.nav-btn:hover,
.secondary-btn:hover,
.clip-actions button:hover,
.amazon-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--border-brand);
  text-decoration: none;
}

.type-tab.active {
  color: white;
  background: var(--brand);
  border-color: var(--brand);
}

.mode-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.92rem;
}

.search-controls {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-input {
  width: 100%;
  background: var(--panel-soft);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 14px;
}

.search-input:focus,
.filter-select:focus,
.compact-select:focus,
.date-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(145, 71, 255, 0.16);
}

.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  font-weight: 700;
}

.primary-btn {
  color: white;
  background: var(--brand);
  transition: transform 0.18s ease, filter 0.18s ease;
}

.secondary-btn {
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--border);
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.primary-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.suggestions {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  overflow: hidden;
  border: 1px solid var(--border-brand);
  border-radius: var(--radius);
  background: #10131c;
  box-shadow: var(--shadow);
}

.suggestion {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 13px;
  background: transparent;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.suggestion:last-child {
  border-bottom: 0;
}

.suggestion:hover,
.suggestion.active {
  background: var(--brand-soft);
}

.suggestion span:last-child {
  color: var(--muted);
  font-size: 0.8rem;
}

.filter-controls,
.custom-range {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.custom-range {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.custom-range label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.top-ad-wrap {
  margin: 14px 0;
  padding: 10px;
}

.ad-rail {
  position: sticky;
  top: 90px;
  height: fit-content;
}

.ad-card,
.affiliate-card {
  padding: 10px;
}

.ad-label {
  display: block;
  margin-bottom: 8px;
  color: var(--dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
  color: var(--dim);
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.5;
}

.ad-slot-horizontal {
  min-height: 92px;
}

.ad-slot-vertical {
  min-height: 420px;
}

.adsbygoogle {
  display: block;
}

.affiliate-card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.amazon-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.amazon-link {
  display: block;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.4;
}

.amazon-link span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  margin-top: 4px;
}

.affiliate-disclosure {
  color: var(--dim);
  font-size: 0.74rem;
  line-height: 1.5;
  margin: 12px 0 0;
}

.status-bar {
  min-height: 28px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.status-bar.error {
  color: var(--danger);
}

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

.clip-card,
.skeleton-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
}

.clip-card {
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.clip-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-brand);
}

.clip-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #050507;
}

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

.clip-duration {
  position: absolute;
  right: 8px;
  bottom: 8px;
  border-radius: 5px;
  background: rgba(0,0,0,0.72);
  color: white;
  padding: 2px 7px;
  font-size: 0.74rem;
}

.clip-body {
  padding: 11px;
}

.clip-title {
  margin: 0 0 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.8em;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.4;
}

.clip-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.clip-meta span:first-child {
  color: var(--brand-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clip-actions {
  display: flex;
  gap: 6px;
  padding: 0 11px 11px;
}

.clip-actions button {
  flex: 1;
  min-height: 34px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 0.76rem;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.clip-actions button.active {
  color: #fff;
  background: rgba(32, 212, 155, 0.18);
  border-color: rgba(32, 212, 155, 0.55);
}

.empty-state {
  display: flex;
  min-height: 240px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  color: var(--dim);
  text-align: center;
}

.empty-icon {
  font-size: 2.6rem;
  color: var(--brand-strong);
  opacity: 0.45;
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  padding: 20px 0 6px;
}

.load-more-wrap .secondary-btn {
  min-width: min(100%, 220px);
}

.skeleton-card {
  min-height: 230px;
}

.skeleton-thumb,
.skeleton-line {
  background: linear-gradient(90deg, rgba(255,255,255,0.05), rgba(255,255,255,0.12), rgba(255,255,255,0.05));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.skeleton-thumb {
  aspect-ratio: 16 / 9;
}

.skeleton-line {
  height: 14px;
  margin: 12px;
  border-radius: 4px;
}

.skeleton-line.short {
  width: 56%;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.78);
}

.overlay.active {
  display: flex;
}

.player-modal {
  width: min(1120px, 100%);
  max-height: calc(100vh - 24px);
  overflow: auto;
  border: 1px solid var(--border-brand);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.player-header {
  min-height: 58px;
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: #111520;
}

.embed-container {
  min-height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 2vw, 20px);
  background: #050507;
}

.embed-container iframe {
  width: min(100%, 980px);
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 8px;
}

.player-info {
  padding: 18px;
}

.player-info h2 {
  margin: 0 0 10px;
  font-size: clamp(1.1rem, 2vw, 1.45rem);
  line-height: 1.35;
}

.player-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  color: var(--muted);
}

.player-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px clamp(12px, 2vw, 24px) calc(18px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  color: var(--dim);
  font-size: 0.82rem;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.doc-page {
  background: var(--bg);
}

.doc-shell {
  width: min(100%, 860px);
  margin: 0 auto;
  padding: 30px 16px;
}

.doc-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.doc-header,
.doc-body {
  padding: clamp(18px, 3vw, 30px);
}

.doc-header {
  border-bottom: 1px solid var(--border);
}

.doc-header h1 {
  margin: 6px 0;
}

.doc-kicker {
  color: var(--brand-strong);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.doc-section + .doc-section {
  margin-top: 24px;
}

.doc-section h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.doc-section p,
.doc-section li {
  color: var(--muted);
  line-height: 1.7;
}

.doc-list {
  padding-left: 1.2rem;
}

@media (max-width: 1120px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 220px);
  }
}

@media (max-width: 820px) {
  .app-header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .header-nav {
    order: 3;
    flex-basis: 100%;
  }

  .main-layout {
    display: block;
  }

  .right-rail {
    position: static;
    margin-top: 14px;
  }

  .ad-slot-vertical {
    min-height: 180px;
  }

  .search-controls {
    flex-direction: column;
  }

  .filter-controls,
  .custom-range {
    grid-template-columns: 1fr;
  }

  .clips-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 10px;
  }

  .clip-body {
    padding: 9px;
  }

  .clip-title {
    font-size: 0.84rem;
  }

  .clip-actions {
    padding: 0 9px 9px;
  }

  .clip-actions button {
    font-size: 0.72rem;
  }

  .overlay {
    padding: 0;
    align-items: stretch;
  }

  .player-modal {
    max-height: 100dvh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .player-header {
    padding-top: calc(10px + var(--safe-top));
  }

  .embed-container {
    min-height: 260px;
  }

  .player-actions {
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .app-header {
    align-items: flex-start;
  }

  .brand img {
    max-width: min(62vw, 220px);
    height: clamp(58px, 16vw, 68px);
  }

  .header-nav,
  .type-tabs,
  .clip-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .type-tabs {
    grid-template-columns: 1fr;
  }

  .nav-btn,
  .type-tab,
  .clip-actions button {
    width: 100%;
  }

  .clips-grid {
    grid-template-columns: 1fr;
  }
}
