:root {
  color-scheme: dark;
  --bg: #0f0f0f;
  --panel: #212121;
  --field: #121212;
  --hover: #272727;
  --line: #303030;
  --control-line: #717171;
  --text: #f1f1f1;
  --muted: #aaaaaa;
  --accent: #3ea6ff;
  --accent-ink: #0f0f0f;
  --notice: #1c2b38;
  --danger: #ff7a70;
  --radius: 10px;
  --radius-small: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --tab-height: 56px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

* { box-sizing: border-box; }

html { scrollbar-color: var(--control-line) var(--bg); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

::selection { background: var(--accent); color: var(--accent-ink); }

[hidden] { display: none !important; }

h1 { font-size: 1.375rem; line-height: 1.25; margin: 0; }
h2 { font-size: 1.0625rem; line-height: 1.3; margin: var(--space-6) 0 var(--space-3); }
h3 { font-size: .875rem; line-height: 1.4; margin: 0; }
p { margin: 0; }

label { display: block; font-size: .875rem; font-weight: 600; margin: var(--space-4) 0 var(--space-1); }

textarea, input, select {
  width: 100%;
  background: var(--field);
  color: var(--text);
  caret-color: var(--accent);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-small);
  padding: 10px var(--space-3);
  font: inherit;
  min-height: 44px;
}

textarea { display: block; resize: vertical; field-sizing: content; }
select { accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); min-height: 0; }
::placeholder { color: var(--muted); opacity: 1; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

a { color: var(--accent); text-underline-offset: 3px; }

button, a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--control-line);
  border-radius: 999px;
  padding: 9px var(--space-4);
  min-height: 44px;
  font: inherit;
  font-size: .9375rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), transform 160ms var(--ease);
}

button:hover { background: var(--hover); }
button:active, a.button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: progress; }

.primary, a.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.primary:hover { background: #65b8ff; border-color: #65b8ff; }
.quiet { border-color: transparent; color: var(--muted); }
.quiet:hover { color: var(--text); }
.small { min-height: 40px; padding: 6px var(--space-3); }
.wide { width: 100%; margin-top: var(--space-4); }
.armed, .armed:hover { background: var(--text); border-color: var(--text); color: var(--accent-ink); }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.login { max-width: 360px; margin: 0 auto; padding: 14vh var(--space-4) var(--space-7); }
.login img { display: block; margin-bottom: var(--space-3); }
.login h1 { margin-bottom: var(--space-4); }

header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 56px;
  padding: var(--space-1) var(--space-4);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: var(--space-2); font-weight: 650; white-space: nowrap; }
#logout { margin-left: auto; }

nav { display: flex; gap: var(--space-1); align-self: stretch; }

nav a {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .9375rem;
  font-weight: 500;
  padding: var(--space-1) var(--space-3);
  min-height: 48px;
  text-decoration: none;
  transition: color 160ms var(--ease);
}

nav a:hover { color: var(--text); }
nav a[aria-current="page"] { color: var(--text); font-weight: 650; }

nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  inset: auto var(--space-3) 0;
  height: 2px;
  background: var(--text);
}

main { max-width: 780px; margin: 0 auto; padding: var(--space-4) var(--space-4) var(--space-7); }

section > h2:first-child { margin-top: var(--space-2); }

.error { color: var(--danger); margin-top: var(--space-3); }
.error:empty { display: none; }
.muted { color: var(--muted); font-size: .9375rem; }
.progress { color: var(--muted); font-size: .9375rem; margin-top: var(--space-3); }
.flash { background: var(--panel); border-radius: var(--radius-small); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4); }

.setup { background: var(--panel); border-radius: var(--radius); padding: var(--space-4); margin-bottom: var(--space-4); }
.setup p + a { margin-top: var(--space-3); }

.inbox-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.inbox-head h2 { margin: 0; }
.empty { background: var(--panel); border-radius: var(--radius); padding: var(--space-5) var(--space-4); text-align: center; }

.threads { list-style: none; margin: 0; padding: 0; }
.thread-item { padding: var(--space-4) 0 var(--space-5); border-top: 1px solid var(--line); }
.thread-item:first-child { border-top: 0; padding-top: var(--space-2); }

.video-line { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); font-size: .8125rem; color: var(--muted); }
.video-line span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

a.external { display: inline-flex; align-items: center; gap: var(--space-1); flex: none; font-size: .8125rem; font-weight: 500; padding: var(--space-1) 0; }
a.external svg { width: 12px; height: 12px; flex: none; }

.comment-row { display: flex; gap: var(--space-3); }
.comment-body { flex: 1; min-width: 0; }
.avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; object-fit: cover; background: var(--panel); }
.avatar-initial { display: flex; align-items: center; justify-content: center; background: #5f5f5f; color: var(--text); font-weight: 600; }
.replies .avatar { width: 28px; height: 28px; }
.replies .avatar-initial { font-size: .8125rem; }

.comment-head { display: flex; flex-wrap: wrap; align-items: center; gap: 2px var(--space-2); color: var(--muted); font-size: .8125rem; }
.comment-head strong { color: var(--text); font-size: .875rem; font-weight: 600; overflow-wrap: anywhere; }
.comment-head .channel-chip { background: var(--text); color: var(--accent-ink); border-radius: 999px; padding: 2px var(--space-2); }

.comment-text { margin-top: 2px; font-size: .9375rem; line-height: 1.45; max-width: 75ch; overflow-wrap: anywhere; white-space: pre-line; }

.badge { color: var(--accent); font-size: .875rem; font-weight: 600; margin-top: var(--space-2); overflow-wrap: anywhere; }

.comment-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); margin: 2px 0 0 -8px; }
.reaction { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1); min-width: 40px; height: 40px; padding: 0 var(--space-2); border-radius: 999px; color: var(--text); font-size: .8125rem; text-decoration: none; transition: background-color 160ms var(--ease); }
.reaction:hover { background: var(--hover); }
.reaction svg { width: 20px; height: 20px; flex: none; }
.text-action { min-height: 36px; padding: 4px var(--space-3); border-color: transparent; font-size: .875rem; font-weight: 600; }
.text-action.quiet { font-weight: 500; }

.replies { margin: var(--space-2) 0 0 20px; padding-left: 24px; display: grid; gap: var(--space-3); }
.replies > * { position: relative; }
.replies > *::before { content: ""; position: absolute; left: -24px; top: -12px; width: 18px; height: 26px; border-left: 1px solid var(--control-line); border-bottom: 1px solid var(--control-line); border-bottom-left-radius: 12px; }
.replies > *:not(:last-child)::after { content: ""; position: absolute; left: -24px; top: 0; bottom: -12px; border-left: 1px solid var(--control-line); }

.more-replies > summary { color: var(--text); font-size: .875rem; font-weight: 600; min-height: 28px; padding: var(--space-1) 0; }
.more-replies[open] > summary { margin-bottom: var(--space-2); }
.more-replies .comment-row + .comment-row { margin-top: var(--space-3); }

.composer { margin-top: var(--space-2); display: grid; gap: var(--space-2); }
.composer label { margin: 0; color: var(--muted); font-size: .8125rem; font-weight: 500; }
.composer textarea { background: transparent; border: 0; border-bottom: 1px solid var(--control-line); border-radius: 0; padding: var(--space-1) 0 var(--space-2); min-height: 44px; font-size: .9375rem; resize: none; }
.composer textarea:focus-visible { outline: 0; border-bottom: 2px solid var(--accent); margin-bottom: -1px; }

.note { background: var(--notice); border-radius: var(--radius-small); padding: var(--space-2) var(--space-3); }
.note strong { color: var(--accent); font-size: .8125rem; }
.note p { font-size: .875rem; overflow-wrap: anywhere; }

.reply-actions { display: grid; gap: var(--space-2); }
.reply-buttons { display: flex; justify-content: flex-end; align-items: center; gap: var(--space-2); }
.reply-buttons button { min-height: 36px; padding: 4px var(--space-4); font-size: .875rem; }

.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: var(--space-2); }

.tool { margin: 0; }
.tool > summary { color: var(--muted); font-size: .8125rem; font-weight: 500; }
.tool[open] > summary { margin-bottom: var(--space-1); }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-1); }
.chips button { min-height: 36px; padding: 4px var(--space-3); font-size: .8125rem; }

.inline { display: flex; gap: var(--space-2); }
.inline input { flex: 1; min-width: 0; }
.inline button { flex: none; }
.refine .inline { margin-top: var(--space-2); }

.history-meta { color: var(--muted); font-size: .8125rem; margin-top: var(--space-1); }

.sources { list-style: none; padding: 0; margin: var(--space-2) 0 0; display: grid; gap: var(--space-3); }
.source-title { font-weight: 600; font-size: .875rem; overflow-wrap: anywhere; }
.source-kind { color: var(--muted); font-size: .8125rem; }
.sources blockquote { margin: var(--space-1) 0 0; color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; white-space: pre-line; max-height: 11em; overflow-y: auto; }

.list { list-style: none; padding: 0; margin: 0; background: var(--panel); border-radius: var(--radius); }
.list:empty { display: none; }
.list > li { padding: var(--space-3) var(--space-4); }
.list > li + li { border-top: 1px solid var(--line); }
.list p { max-width: 70ch; overflow-wrap: anywhere; white-space: pre-line; }
.list .comment { color: var(--muted); font-size: .9375rem; margin-bottom: var(--space-1); }
.list .meta { color: var(--muted); font-size: .8125rem; margin-top: var(--space-1); }
.list button { margin-top: var(--space-2); }
.row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.row button { margin-top: 0; }

.check { display: flex; gap: var(--space-2); align-items: center; font-weight: 400; font-size: .9375rem; margin: 0; }
.check input { width: 20px; height: 20px; flex: none; }
.helper-permission { min-height: 44px; }
.helper-name { font-weight: 600; }

#new-password { margin: var(--space-3) 0; }
#new-password p { overflow-wrap: anywhere; }
#youtube-disconnect { margin-top: var(--space-2); }

.paste-result { margin-top: var(--space-4); }
.paste-result .card { background: var(--panel); border-radius: var(--radius); padding: var(--space-4); }
.paste-result .composer { margin-top: 0; }

@media (max-width: 719px) {
  body { padding-bottom: calc(var(--tab-height) + env(safe-area-inset-bottom)); }
  header { padding-inline: var(--space-3); }

  nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 2;
    gap: 0;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel);
    border-top: 1px solid var(--line);
  }

  nav a { flex: 1 1 0; min-width: 0; min-height: var(--tab-height); padding: var(--space-1); font-size: .875rem; }
  nav a[aria-current="page"]::after { inset: 0 18% auto; }
  main { padding-inline: var(--space-3); }
  .replies { margin-left: 18px; padding-left: 18px; }
  .replies > *::before { left: -18px; width: 13px; }
  .replies > *:not(:last-child)::after { left: -18px; }
  }

@media (prefers-reduced-motion: reduce) {
  button, a.button, nav a { transition: none; }
  button:active, a.button:active { transform: none; }
}

#helper-list { margin-top: var(--space-3); }

