:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-card: #1c1f28;
  --border: #2a2e3a;
  --text: #eef0f4;
  --text-dim: #9aa0ac;
  --text-faint: #656b78;
  --accent: #ff3b3b;
  --accent-soft: rgba(255, 59, 59, 0.14);
  --green: #3ddc97;
  --amber: #ffb84d;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
  height: 100%;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.brand-mark {
  background: var(--accent);
  color: white;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--bg-card); color: var(--text); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent); }

.sidebar-section { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
  font-weight: 700;
}

select, .search-input, .modal-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13.5px;
  outline: none;
  width: 100%;
  font-family: inherit;
}
select:focus, .search-input:focus, .modal-input:focus { border-color: var(--accent); }

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  transition: filter .15s, transform .1s;
}
.primary-btn:hover { filter: brightness(1.1); }
.primary-btn:active { transform: scale(0.98); }

.ghost-btn {
  background: var(--bg-card);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-faint); }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.lang-switch {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.lang-btn {
  flex: 1;
  background: var(--bg-card);
  border: none;
  color: var(--text-dim);
  padding: 8px 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.lang-btn:last-child { border-right: none; }
.lang-btn:hover { color: var(--text); }
.lang-btn.active { background: var(--accent); color: white; }
.api-key-status {
  font-size: 11.5px;
  color: var(--text-faint);
  text-align: center;
}
.api-key-status.ok { color: var(--green); }

/* Main */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}
.view-title { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.topbar-right { display: flex; gap: 8px; }
.search-input { width: 280px; }
.period-select { width: 150px; flex-shrink: 0; }

.stats-strip {
  display: flex;
  gap: 12px;
  padding: 16px 28px 0;
  flex-wrap: wrap;
}
.stat-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  min-width: 140px;
}
.stat-chip .label { font-size: 11px; color: var(--text-faint); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.stat-chip .value { font-size: 18px; font-weight: 800; margin-top: 2px; }
.stat-chip .value.accent { color: var(--accent); }
.stat-chip .value.green { color: var(--green); }

.content { padding: 20px 28px 60px; flex: 1; }

.hidden { display: none !important; }

/* Empty state */
.empty-state {
  max-width: 560px;
  margin: 60px auto;
  text-align: center;
  color: var(--text-dim);
}
.empty-icon { font-size: 40px; margin-bottom: 10px; }
.empty-state h2 { color: var(--text); font-size: 20px; margin: 0 0 10px; }
.empty-state p { font-size: 13.5px; line-height: 1.6; margin-bottom: 18px; }
.howto {
  margin-top: 24px;
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 13px;
}
.howto summary { cursor: pointer; font-weight: 700; color: var(--text); }
.howto ol { padding-left: 18px; line-height: 1.8; color: var(--text-dim); }
.howto a { color: var(--accent); }
.howto .note { color: var(--text-faint); font-size: 12px; margin-top: 8px; }

/* Loading */
.loading-state { text-align: center; padding: 80px 0; color: var(--text-dim); }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  background: rgba(255,59,59,0.08);
  border: 1px solid rgba(255,59,59,0.3);
  color: #ff8080;
  padding: 16px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.6;
}

/* Video grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
  margin-top: 16px;
}
.video-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
  display: flex;
  flex-direction: column;
}
.video-card:hover { transform: translateY(-3px); border-color: var(--text-faint); }
.thumb-wrap { position: relative; aspect-ratio: 16/9; background: #000; }
.thumb-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rank-badge {
  position: absolute; top: 8px; left: 8px;
  background: var(--accent); color: white;
  font-weight: 800; font-size: 12px;
  padding: 3px 8px; border-radius: 6px;
}
.cat-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.7); color: white;
  font-size: 10.5px; font-weight: 600;
  padding: 3px 8px; border-radius: 6px;
}
.video-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.video-title {
  font-size: 13.5px; font-weight: 700; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-channel { font-size: 12px; color: var(--text-dim); }
.video-metrics {
  display: flex; gap: 10px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--text-faint);
  margin-top: auto; padding-top: 6px; border-top: 1px solid var(--border);
}
.video-metrics span { display: flex; align-items: center; gap: 3px; }
.metric-hot { color: var(--amber); font-weight: 700; }
.metric-good { color: var(--green); font-weight: 700; }

/* Insight view */
.insight-view { display: flex; flex-direction: column; gap: 20px; }
.insight-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.insight-card h3 { margin: 0 0 12px; font-size: 15px; }
.insight-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.insight-row:last-child { border-bottom: none; }
.insight-row .k { color: var(--text-dim); }
.insight-row .v { font-weight: 700; }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 13px; padding: 6px 0; }
.bar-label { width: 130px; flex-shrink: 0; color: var(--text-dim); }
.bar-track { flex: 1; background: var(--bg-elevated); border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; }
.bar-val { width: 60px; text-align: right; font-weight: 700; font-size: 12px; }
.tips-list { padding-left: 18px; line-height: 1.9; font-size: 13.5px; color: var(--text-dim); }
.tips-list li strong { color: var(--text); }

.panel-hint { font-size: 11.5px; color: var(--text-faint); line-height: 1.5; }

/* Channel analysis */
.channel-view { display: flex; flex-direction: column; gap: 20px; }
.channel-cards { display: flex; flex-direction: column; gap: 20px; }
.channel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.channel-card-head { display: flex; align-items: center; gap: 14px; }
.channel-avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--bg-elevated); }
.channel-head-meta { flex: 1; min-width: 0; }
.channel-name { font-size: 17px; font-weight: 800; }
.channel-sub { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.channel-remove-btn { padding: 6px 10px; font-size: 12px; }

.spark-block { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; }
.spark-label { font-size: 11.5px; color: var(--text-faint); font-weight: 700; margin-bottom: 6px; }
.sparkline { width: 100%; height: 70px; display: block; }
.spark-hint { font-size: 12px; color: var(--text-faint); background: var(--bg-elevated); border: 1px dashed var(--border); border-radius: 10px; padding: 12px 16px; line-height: 1.6; }

.shorts-split { display: flex; flex-direction: column; gap: 2px; }

.channel-videos-label { font-size: 12px; color: var(--text-faint); font-weight: 700; margin-top: 4px; }
.channel-video-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 8px; }
.weekday-block { display: flex; flex-direction: column; gap: 2px; }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tag-pill {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--text);
  line-height: 1.6;
  white-space: nowrap;
}
.tag-pill b { color: var(--accent); font-weight: 700; margin-left: 4px; }

.compare-table-wrap .table-scroll { overflow-x: auto; }
.compare-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.compare-table th, .compare-table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.compare-table thead th { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.compare-table tbody td:first-child { color: var(--text-dim); font-weight: 600; }
.compare-table tbody td:not(:first-child) { font-weight: 700; }
.compare-table tbody tr:last-child td { border-bottom: none; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow);
}
.modal-wide { max-width: 640px; max-height: 85vh; overflow-y: auto; }
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal-desc { font-size: 13px; color: var(--text-dim); margin: 0 0 14px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.detail-player { position: relative; width: 100%; aspect-ratio: 16/9; border-radius: 10px; overflow: hidden; background: #000; margin-bottom: 10px; }
.detail-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.detail-iframe { width: 100%; height: 100%; border: 0; display: block; }
.play-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.25);
  border: none; cursor: pointer;
  transition: background .15s;
}
.play-overlay:hover { background: rgba(0,0,0,0.4); }
.play-overlay svg { width: 64px; height: 64px; filter: drop-shadow(0 2px 10px rgba(0,0,0,0.6)); transform: scale(1); transition: transform .15s; }
.play-overlay:hover svg { transform: scale(1.08); }
.watch-link {
  display: inline-block;
  font-size: 12.5px; color: var(--text-dim);
  text-decoration: none;
  margin-bottom: 14px;
}
.watch-link:hover { color: var(--accent); text-decoration: underline; }
.detail-title { font-size: 17px; font-weight: 800; margin-bottom: 6px; line-height: 1.4; }
.detail-channel { color: var(--text-dim); font-size: 13px; margin-bottom: 14px; }
.detail-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 16px; }
.detail-stat { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 10px; text-align: center; }
.detail-stat .n { font-size: 16px; font-weight: 800; }
.detail-stat .l { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; margin-top: 2px; }
.earnings-box {
  background: var(--accent-soft);
  border: 1px solid rgba(255,59,59,0.25);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.7;
}
.earnings-box .amt { font-size: 20px; font-weight: 800; color: var(--accent); }
.close-x { position: sticky; top:0; text-align:right; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; flex-wrap: wrap; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { margin-top: 0; border-top: none; }
}
