:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #1b1e24;
  --text: #f2f3f5;
  --muted: #9aa0a6;
  --accent: #ff7755;
  --border: #2c313a;
  --nav: 3.6rem;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0.35rem 0; }
.error { color: #ff8a80; }
h1 { font-size: 1.15rem; margin: 0; }
.section-label { font-size: 0.8rem; color: var(--muted); margin: 1rem 0 0.35rem; }

.screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.card-panel {
  width: min(100%, 24rem);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
input, button {
  font: inherit;
  font-size: 16px;
}
input {
  width: 100%;
  padding: 0.75rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #12141a;
  color: var(--text);
}
button {
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #1a0d08;
  font-weight: 700;
  padding: 0.75rem 0.9rem;
  cursor: pointer;
}
.text-btn, .icon-btn {
  background: transparent;
  color: var(--text);
  width: auto;
  padding: 0.4rem 0.6rem;
}
.icon-btn { font-size: 1.3rem; }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: calc(0.6rem + var(--safe-t)) 0.75rem 0.6rem;
  background: rgba(16, 17, 20, 0.94);
  border-bottom: 1px solid var(--border);
}
.top h1 {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  line-height: 1.3;
}
.heading-name { font-weight: 700; }
.tags { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; }
.tag {
  display: inline-flex;
  align-items: center;
  border: 1px solid #3c4452;
  background: #2a3140;
  color: #e8eaed;
  border-radius: 4px;
  padding: 0.08rem 0.42rem;
  font-size: 0.72rem;
  font-weight: 650;
  line-height: 1.35;
}

.view {
  padding: 0.75rem 0.75rem calc(var(--nav) + var(--safe-b) + 1rem);
}
.add-row, .tool-row { display: flex; gap: 0.5rem; }
.add-row input { flex: 1; }
.tool-row button { flex: 1; background: var(--panel); color: var(--text); border: 1px solid var(--border); }

.list { list-style: none; margin: 0.5rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.list li { background: transparent; border: 0; padding: 0; }
.row-btn {
  width: 100%;
  text-align: left;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.85rem 0.9rem;
}
.row-btn.person { display: flex; align-items: center; gap: 0.75rem; }
.person-thumb {
  width: 84px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  background: #12141a;
  flex: none;
}
.person-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.28rem;
  min-width: 0;
}
.person-name { font-weight: 700; line-height: 1.25; }
.row-btn small { display: block; color: var(--muted); font-weight: 500; margin-top: 0.2rem; }
.row-actions { display: flex; gap: 0.4rem; margin-top: 0.55rem; }
.row-actions button { flex: 1; padding: 0.55rem; }

.progress { margin-bottom: 0.6rem; }
.bar { height: 8px; background: var(--panel); border-radius: 99px; overflow: hidden; }
#barFill { height: 100%; width: 0; background: var(--accent); }

.tabs { display: flex; gap: 0.35rem; overflow: auto; margin: 0.5rem 0; }
.tabs button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  white-space: nowrap;
}
.tabs button.active { border-color: var(--accent); color: var(--accent); }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .view, .top { max-width: 1100px; margin-left: auto; margin-right: auto; }
}

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 1;
  cursor: pointer;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .badge {
  position: absolute;
  left: 4px;
  bottom: 4px;
  font-size: 0.65rem;
  background: rgba(0,0,0,0.65);
  padding: 2px 6px;
  border-radius: 4px;
}
.card.unresolved {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem;
  font-size: 0.75rem;
  text-align: center;
  color: var(--muted);
}
.card.pending {
  background: repeating-linear-gradient(-45deg, var(--panel), var(--panel) 8px, #252932 8px, #252932 16px);
}
.card.video::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E") center / 20px no-repeat;
  pointer-events: none;
}
.card.focus { outline: 2px solid var(--accent); }

.mode-thread #tabs,
.mode-thread #grid { display: none; }
.posts { display: none; }
.mode-thread .posts { display: flex; flex-direction: column; gap: 0.75rem; }
.page-label { margin: 0.2rem 0 0; font-size: 0.75rem; color: var(--muted); }
.post {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem;
}
.post.focus { outline: 2px solid var(--accent); }
.post-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
  color: var(--muted);
  font-size: 0.8rem;
}
.post-head strong { color: var(--text); font-size: 0.95rem; }
.post-body p { margin: 0.55rem 0; white-space: pre-wrap; line-height: 1.4; }
.post-media {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
  margin: 0.45rem 0;
}

.bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 0.4rem;
  padding: 0.45rem 0.6rem calc(0.45rem + var(--safe-b));
  background: rgba(16, 17, 20, 0.96);
  border-top: 1px solid var(--border);
}
.bottom button {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}
.bottom button.active { color: var(--accent); border-color: var(--border); background: var(--panel); }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0,0,0,0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
#lbClose {
  position: absolute;
  top: calc(0.4rem + var(--safe-t));
  right: 0.6rem;
  background: none;
  color: white;
  font-size: 2rem;
}
#lbContent img, #lbContent video { max-width: 100%; max-height: 70dvh; }
.lb-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.8rem; justify-content: center; }
.lb-actions a, .lb-actions button {
  color: var(--accent);
  background: var(--panel);
  text-decoration: none;
  border: 1px solid var(--border);
}
