:root {
  color-scheme: light dark;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --app-max: 720px;
  --indent: 18px;

  /* light (default) */
  --bg: #f2f4f7;
  --bg2: #e8ecf1;
  --card: #ffffff;
  --card-soft: #f7f9fb;
  --text: #1a2330;
  --muted: #6b7a8d;
  --acc: #2f86e0;
  --acc2: #2470c2;
  --acc-soft: rgba(47, 134, 224, 0.12);
  --acc-line: rgba(47, 134, 224, 0.35);
  --line: rgba(20, 35, 55, 0.1);
  --ok: #1fa971;
  --warn: #c98912;
  --danger: #d94c4c;
  --vote: #7a8899;
  --shadow: 0 8px 28px rgba(20, 35, 55, 0.1);
  --shadow-sm: 0 8px 24px rgba(20, 35, 55, 0.12);
  --chip: rgba(20, 35, 55, 0.06);
  --chk-border: rgba(20, 35, 55, 0.2);
  --chk-bg: linear-gradient(160deg, #fff, #eef2f6);
  --chk-mark: #fff;
  --spoiler-blur: rgba(26, 35, 48, 0.45);
  --spoiler-bg: rgba(20, 35, 55, 0.08);
  --toast-bg: #fff1f1;
  --toast-text: #8a2a2a;
  --toast-line: rgba(217, 76, 76, 0.35);
  --fab-bg: rgba(255, 255, 255, 0.92);
  --mod-line: rgba(201, 137, 18, 0.35);
  --spoiler-tag-c: #a67a18;
  --spoiler-tag-bg: rgba(201, 137, 18, 0.14);
  --on-acc: #fff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --bg2: #1a222d;
    --card: #232d3b;
    --card-soft: rgba(35, 45, 59, 0.85);
    --text: #eef3f8;
    --muted: #8b9aab;
    --acc: #3d9cf0;
    --acc2: #2a7fd4;
    --acc-soft: rgba(61, 156, 240, 0.16);
    --acc-line: rgba(61, 156, 240, 0.35);
    --line: rgba(255, 255, 255, 0.08);
    --ok: #3ecf8e;
    --warn: #f0b429;
    --danger: #ef6b6b;
    --vote: #6b7c8f;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.35);
    --chip: rgba(255, 255, 255, 0.06);
    --chk-border: rgba(255, 255, 255, 0.18);
    --chk-bg: linear-gradient(160deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.18));
    --chk-mark: #fff;
    --spoiler-blur: rgba(238, 243, 248, 0.55);
    --spoiler-bg: rgba(0, 0, 0, 0.18);
    --toast-bg: #2a1820;
    --toast-text: #ffd0d0;
    --toast-line: rgba(239, 107, 107, 0.4);
    --fab-bg: rgba(35, 45, 59, 0.92);
    --mod-line: rgba(240, 180, 41, 0.35);
    --spoiler-tag-c: #f0c36a;
    --spoiler-tag-bg: rgba(240, 180, 41, 0.14);
    --on-acc: #fff;
  }
}

/* Telegram / явный override поверх media */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f4f7;
  --bg2: #e8ecf1;
  --card: #ffffff;
  --card-soft: #f7f9fb;
  --text: #1a2330;
  --muted: #6b7a8d;
  --acc: #2f86e0;
  --acc2: #2470c2;
  --acc-soft: rgba(47, 134, 224, 0.12);
  --acc-line: rgba(47, 134, 224, 0.35);
  --line: rgba(20, 35, 55, 0.1);
  --ok: #1fa971;
  --warn: #c98912;
  --danger: #d94c4c;
  --vote: #7a8899;
  --shadow: 0 8px 28px rgba(20, 35, 55, 0.1);
  --shadow-sm: 0 8px 24px rgba(20, 35, 55, 0.12);
  --chip: rgba(20, 35, 55, 0.06);
  --chk-border: rgba(20, 35, 55, 0.2);
  --chk-bg: linear-gradient(160deg, #fff, #eef2f6);
  --chk-mark: #fff;
  --spoiler-blur: rgba(26, 35, 48, 0.45);
  --spoiler-bg: rgba(20, 35, 55, 0.08);
  --toast-bg: #fff1f1;
  --toast-text: #8a2a2a;
  --toast-line: rgba(217, 76, 76, 0.35);
  --fab-bg: rgba(255, 255, 255, 0.92);
  --mod-line: rgba(201, 137, 18, 0.35);
  --spoiler-tag-c: #a67a18;
  --spoiler-tag-bg: rgba(201, 137, 18, 0.14);
  --on-acc: #fff;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1419;
  --bg2: #1a222d;
  --card: #232d3b;
  --card-soft: rgba(35, 45, 59, 0.85);
  --text: #eef3f8;
  --muted: #8b9aab;
  --acc: #3d9cf0;
  --acc2: #2a7fd4;
  --acc-soft: rgba(61, 156, 240, 0.16);
  --acc-line: rgba(61, 156, 240, 0.35);
  --line: rgba(255, 255, 255, 0.08);
  --ok: #3ecf8e;
  --warn: #f0b429;
  --danger: #ef6b6b;
  --vote: #6b7c8f;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.35);
  --chip: rgba(255, 255, 255, 0.06);
  --chk-border: rgba(255, 255, 255, 0.18);
  --chk-bg: linear-gradient(160deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.18));
  --chk-mark: #fff;
  --spoiler-blur: rgba(238, 243, 248, 0.55);
  --spoiler-bg: rgba(0, 0, 0, 0.18);
  --toast-bg: #2a1820;
  --toast-text: #ffd0d0;
  --toast-line: rgba(239, 107, 107, 0.4);
  --fab-bg: rgba(35, 45, 59, 0.92);
  --mod-line: rgba(240, 180, 41, 0.35);
  --spoiler-tag-c: #f0c36a;
  --spoiler-tag-bg: rgba(240, 180, 41, 0.14);
  --on-acc: #fff;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 80%;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: linear-gradient(165deg, var(--bg), var(--bg2) 48%, var(--bg));
  color: var(--text);
}

body {
  padding: 0 0 96px;
}

.wrap {
  max-width: var(--app-max);
  margin: 0 auto;
  padding: 14px 14px 0;
}

.gate {
  margin: 40px 16px;
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: center;
  color: var(--muted);
}

.gate h1 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  color: var(--text);
}

.hero {
  display: flex;
  gap: 12px;
  align-items: stretch;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.hero img {
  width: 64px;
  height: 90px;
  min-height: 90px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--bg);
  flex-shrink: 0;
  align-self: flex-start;
}

.hero .meta {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-height: 90px;
}

.hero .label-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.hero .meta .label {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-weight: 600;
}

.hero .icon-btn,
.hero .icon-btn.search-side {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 0;
}

.hero .icon-btn:active {
  opacity: 0.75;
}

.hero .meta h1 {
  margin: 4px 0 4px;
  font-size: 1.05rem;
  line-height: 1.25;
  word-break: break-word;
}

.hero .facts {
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--muted);
  margin: 0;
  flex: 1;
}

.hero .facts .sep {
  opacity: 0.45;
  margin: 0 0.2em;
}

.hero .back-orig {
  margin-top: auto;
  padding-top: 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  opacity: 0.8;
  align-self: flex-start;
}

.hero .back-orig:active {
  opacity: 1;
  color: var(--acc);
}

.online-btn {
  flex-shrink: 0;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid rgba(46, 180, 110, 0.28) !important;
  background: rgba(46, 180, 110, 0.1) !important;
  color: #1fa971 !important;
  border-radius: 999px !important;
  padding: 6px 10px !important;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

html[data-theme="dark"] .online-btn {
  color: #3ecf8e !important;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .online-btn {
    color: #3ecf8e !important;
  }
}

.online-btn .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px rgba(46, 180, 110, 0.18);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet.hidden { display: none !important; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.sheet-panel {
  position: relative;
  z-index: 1;
  width: min(100%, var(--app-max));
  max-height: min(72vh, 560px);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.sheet-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.sheet-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
}

.search-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  margin-bottom: 10px;
}

.sheet-list {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 80px;
}

.sheet-empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 24px 8px;
}

.sheet-user,
.sheet-anime {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--card-soft);
  border-radius: 12px;
  padding: 8px 10px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.sheet-user img,
.sheet-anime img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}

.sheet-anime img {
  width: 34px;
  height: 48px;
  border-radius: 6px;
}

.sheet-user .name,
.sheet-anime .name {
  font-weight: 600;
  font-size: 0.88rem;
}

.sheet-user .sub,
.sheet-anime .sub {
  font-size: 0.72rem;
  color: var(--muted);
}

.toolbar {
  display: flex;
  gap: 8px;
  margin: 14px 0 10px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar button,
.composer button,
.actions button,
.vote button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
}

.toolbar button.active {
  background: var(--acc);
  border-color: var(--acc2);
  color: var(--on-acc);
}

.composer {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 14px;
}

.composer.reply-only textarea,
.composer.reply-only .opts,
.composer.banned textarea,
.composer.banned .opts {
  display: none;
}

.composer.reply-only,
.composer.banned {
  padding: 10px 12px;
}

.composer.reply-only .hint-row,
.composer.banned .hint-row {
  margin-bottom: 0;
}

.composer.banned .hint {
  color: var(--danger);
}

.composer .hint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.composer .hint {
  font-size: 0.8rem;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}

.composer button.ghost {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 0.75rem;
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.composer button.ghost:hover {
  color: var(--text);
  border-color: var(--acc);
}

.head .src {
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--chip);
  border-radius: 999px;
  padding: 2px 8px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.user-hit {
  font: inherit;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-decoration: none;
  text-align: left;
}

button.user-hit.name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
}

button.user-hit.av-hit {
  display: inline-flex;
  line-height: 0;
  border-radius: 50%;
}

.comment.flash {
  outline: 1px solid var(--acc-line);
  box-shadow: 0 0 0 3px var(--acc-soft);
  transition: outline 0.2s, box-shadow 0.2s;
}

.to-top {
  position: fixed;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--fab-bg);
  color: var(--text);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
}

.to-top:active {
  transform: scale(0.96);
}

.load-more {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 12px 0 4px;
}

.sentinel {
  height: 1px;
  margin-bottom: 24px;
}

.composer textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}

.composer .opts {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  min-width: 0;
}

.chk {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.chk input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.chk .box {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 6px;
  border: 1.5px solid var(--chk-border);
  background: var(--chk-bg);
  box-shadow: inset 0 1px 0 var(--chip);
  position: relative;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.12s;
}

.chk .box::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid var(--chk-mark);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0.4);
  opacity: 0;
  transition: opacity 0.12s, transform 0.12s;
}

.chk:hover .box {
  border-color: var(--acc-line);
}

.chk input:focus-visible + .box {
  outline: 2px solid var(--acc-line);
  outline-offset: 2px;
}

.chk input:checked + .box {
  border-color: transparent;
  background: linear-gradient(145deg, var(--acc), var(--acc2));
  box-shadow: 0 4px 12px var(--acc-soft);
}

.chk input:checked + .box::after {
  opacity: 1;
  transform: rotate(45deg) scale(1);
}

.chk:active .box {
  transform: scale(0.94);
}

.chk input:checked ~ .lbl {
  color: var(--text);
}

.composer .scope {
  display: inline-flex;
  gap: 6px;
  flex-shrink: 1;
  min-width: 0;
}

.composer .scope-btn {
  padding: 5px 9px;
  font-size: 0.72rem;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}

.composer .scope-btn.active {
  background: var(--acc-soft);
  border-color: var(--acc-line);
  color: var(--text);
}

.composer button.primary,
.actions button.primary {
  background: var(--acc);
  border-color: var(--acc2);
  color: var(--on-acc);
}

.composer button.primary.send {
  margin-left: auto;
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.toolbar .notify-chk {
  margin: 0 0 0 auto;
  width: auto;
  flex-shrink: 0;
  font-size: 0.75rem;
  white-space: nowrap;
}

.toolbar .notify-chk .box {
  width: 16px;
  height: 16px;
}

.toolbar .online-btn {
  margin-left: 0;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.thread {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.comment {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 8px;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 10px;
}

.comment.nested {
  margin-left: 0;
  padding-left: calc(10px + var(--indent) * var(--depth, 1));
  background: var(--card-soft);
  border-top: 1px solid var(--line);
}

.reply-to {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0 0 2px;
}

.reply-to-hit {
  font: inherit;
  font-size: inherit;
  color: var(--acc);
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font-weight: 600;
}

.reply-to-hit:active {
  opacity: 0.75;
}

.vote {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 2px;
}

.vote button {
  padding: 4px 6px;
  background: transparent;
  border: none;
  color: var(--vote);
  font-size: 0.95rem;
  line-height: 1;
}

.vote button.on-up { color: var(--ok); }
.vote button.on-down { color: var(--danger); }

.vote.disabled {
  opacity: 0.35;
  pointer-events: none;
}

.vote button:disabled {
  cursor: default;
  opacity: 0.5;
}

.vote .score {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.head img.av {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg);
}


.head .mod {
  font-size: 0.7rem;
  color: var(--warn);
  border: 1px solid var(--mod-line);
  border-radius: 999px;
  padding: 1px 7px;
}

.head .banned-tag {
  font-size: 0.7rem;
  color: var(--danger);
  border: 1px solid var(--toast-line);
  border-radius: 999px;
  padding: 1px 7px;
  background: var(--toast-bg);
}

.head .seria,
.head .spoiler-tag {
  font-size: 0.72rem;
  color: var(--acc);
  background: var(--acc-soft);
  border-radius: 999px;
  padding: 2px 8px;
}

.head .spoiler-tag {
  color: var(--spoiler-tag-c);
  background: var(--spoiler-tag-bg);
}

.head .time {
  font-size: 0.75rem;
  color: var(--muted);
}

.body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  line-height: 1.4;
  margin: 4px 0 8px;
}

.body.deleted {
  color: var(--muted);
  font-style: italic;
}

.body.spoiler.blurred {
  cursor: pointer;
  user-select: none;
  position: relative;
  color: transparent;
  text-shadow: 0 0 10px var(--spoiler-blur);
  background: var(--spoiler-bg);
  border-radius: 8px;
  padding: 8px;
}

.body.spoiler.blurred::after {
  content: "Нажми, чтобы открыть спойлер";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--text);
  text-shadow: none;
  pointer-events: none;
}

.body.spoiler.revealed {
  color: inherit;
  text-shadow: none;
  background: transparent;
  padding: 0;
}

.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.actions button {
  padding: 5px 9px;
  font-size: 0.78rem;
  background: transparent;
}

.actions button.danger { color: var(--danger); }

.more-replies {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 10px 10px calc(10px + var(--indent) * var(--depth, 1));
  border: none;
  border-top: 1px solid var(--line);
  background: var(--card-soft);
  color: var(--acc);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  box-sizing: border-box;
}

.more-replies:active {
  opacity: 0.75;
}

.reply-box {
  margin-top: 8px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 10px;
}

.error-toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: var(--toast-text);
  border: 1px solid var(--toast-line);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  z-index: 50;
  max-width: 90vw;
}

.hidden { display: none !important; }
