/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0f;
  --surface: #161625;
  --card: #1c1c30;
  --card-hover: #242440;
  --primary: #e94560;
  --secondary: #4ecdc4;
  --accent: #ffd93d;
  --text: #f0f0f0;
  --text-dim: #999;
  --text-muted: #555;
  --border: #2a2a40;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--secondary); }

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ===== Header ===== */
.hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.hdr h1 { font-size: 18px; font-weight: 600; }
.hdr-tools { display: flex; gap: 8px; }

.btn-icon {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
}
.btn-icon:active { background: var(--card-hover); }

.btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-sm {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}

/* ===== Load bar ===== */
.load-bar { padding: 12px 16px; border-bottom: 1px solid var(--border); }
#load-form { display: flex; gap: 8px; }
#video-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}
#video-input:focus { outline: none; border-color: var(--secondary); }

.video-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}
.video-title {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Progress ===== */
.progress-wrap { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.progress-track {
  height: 6px;
  border-radius: 3px;
  background: var(--surface);
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--secondary);
  transition: width 0.2s ease;
}
.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-dim);
}

.status-msg {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-dim);
  background: var(--surface);
}
.status-msg.error { color: var(--primary); }

/* ===== Search ===== */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 61px;
  background: var(--bg);
  z-index: 9;
}
#search-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
}
#search-input:focus { outline: none; border-color: var(--secondary); }
.search-count { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* ===== Content / list ===== */
.content { flex: 1; position: relative; }
.list-view { padding: 8px 16px 24px; }
.results-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.list-empty { text-align: center; color: var(--text-muted); padding: 40px 16px; }

/* ===== Comment card ===== */
.comment-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.comment-card.clickable { cursor: pointer; }
.comment-card.clickable:active { background: var(--card-hover); }
.comment-card.highlight {
  border-color: var(--secondary);
  box-shadow: 0 0 0 1px var(--secondary);
}

.comment-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.avatar { width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0; }
.comment-meta { display: flex; flex-direction: column; overflow: hidden; }
.author { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.time { font-size: 11px; color: var(--text-muted); }

.comment-text {
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  margin-bottom: 8px;
}
.comment-text mark {
  background: var(--accent);
  color: #1a1a1a;
  border-radius: 3px;
  padding: 0 1px;
}

.comment-footer { display: flex; gap: 14px; font-size: 12px; color: var(--text-dim); }

/* ===== Thread view ===== */
.thread-view { padding: 0 16px 24px; }
.thread-hdr {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}
.thread-hdr-label { font-size: 13px; color: var(--text-dim); }
.thread-body { display: flex; flex-direction: column; gap: 10px; }
.thread-replies { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; padding-left: 16px; border-left: 2px solid var(--border); }
.thread-replies-label { font-size: 12px; color: var(--text-muted); }
.load-more-replies { align-self: flex-start; }

.hidden { display: none !important; }

/* ===== Settings sheet ===== */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  z-index: 30;
  max-height: 85vh;
  overflow-y: auto;
  padding-bottom: var(--safe-bottom);
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 10px auto; }
.sheet-body { padding: 4px 20px 24px; display: flex; flex-direction: column; gap: 10px; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-weight: 600; }
.sheet-body label { font-size: 13px; color: var(--text-dim); margin-top: 6px; }
.sheet-body input[type="text"],
.sheet-body input[type="password"],
.sheet-body select {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}
.row-label { display: flex; align-items: center; justify-content: space-between; }
.hint { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

.sheet-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 20;
}
