:root {
  --tg-font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, Noto Sans, Apple Color Emoji, Segoe UI Emoji;
  --tg-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, monospace;
  --tg-accent: #3390ec;
  --tg-accent-2: #2481d8;
  --tg-accent-contrast: #ffffff;
  --tg-bg: #ffffff;
  --tg-surface: #ffffff;
  --tg-surface-2: #f4f7fb;
  --tg-text: #0f1419;
  --tg-text-muted: #5b6b79;
  --tg-border: #e6eaef;
  --tg-quote-bg: #f1f7ff;
  --tg-quote-border: #cfe4ff;
  --tg-success: #2ba167;
  --tg-danger: #e83d3d;
  --tg-warning: #f9a826;
  --tg-shadow-1: 0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.06);
  --tg-shadow-2: 0 6px 24px rgba(0,0,0,.12);
  --tg-radius-s: 8px;
  --tg-radius-m: 12px;
  --tg-radius-l: 18px;
  --tg-radius-pill: 999px;
}

.dark :root, :root.dark, html.dark, [data-theme="dark"] {
  --tg-accent: #50a7f0;
  --tg-accent-2: #3c94de;
  --tg-accent-contrast: #0e1621;
  --tg-bg: #0e1621;
  --tg-surface: #17212b;
  --tg-surface-2: #0e1621;
  --tg-text: #e3e7ea;
  --tg-text-muted: #9fb0bf;
  --tg-border: #263241;
  --tg-quote-bg: #1b2733;
  --tg-quote-border: #2a3a4a;
  --tg-shadow-1: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  --tg-shadow-2: 0 8px 30px rgba(0,0,0,.35);
}

@media (prefers-color-scheme: dark) {
  :root:not(.light):not([data-theme="light"]) {
    --tg-accent: #50a7f0;
    --tg-accent-2: #3c94de;
    --tg-accent-contrast: #0e1621;
    --tg-bg: #0e1621;
    --tg-surface: #17212b;
    --tg-surface-2: #0e1621;
    --tg-text: #e3e7ea;
    --tg-text-muted: #9fb0bf;
    --tg-border: #263241;
    --tg-quote-bg: #1b2733;
    --tg-quote-border: #2a3a4a;
    --tg-shadow-1: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    --tg-shadow-2: 0 8px 30px rgba(0,0,0,.35);
  }
}

.tg, .edu-content {
  font-family: var(--tg-font);
  color: var(--tg-text);
}

.tg a, .edu-content a, .tg-link {
  color: var(--tg-accent);
  text-decoration: none;
}
.tg a:hover, .edu-content a:hover, .tg-link:hover { text-decoration: underline; }

.tg-button {
  -webkit-tap-highlight-color: transparent;
  appearance: none;
  border: 1px solid var(--tg-border);
  background: var(--tg-surface);
  color: var(--tg-text);
  padding: 10px 14px;
  border-radius: var(--tg-radius-pill);
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  box-shadow: var(--tg-shadow-1);
  transition: transform .06s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.tg-button:hover { border-color: transparent; box-shadow: var(--tg-shadow-2); transform: translateY(-1px); }
.tg-button:active { transform: translateY(0); }

.tg-button--primary {
  background: linear-gradient(180deg, var(--tg-accent) 0%, var(--tg-accent-2) 100%);
  border-color: transparent;
  color: var(--tg-accent-contrast);
}
.tg-button--ghost { background: transparent; }

.tg-button--download::before {
  content: "";
  width: 18px; height: 18px;
  display: inline-block;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23000"><path d="M12 3v12m0 0l-4-4m4 4l4-4M5 21h14" stroke="%23000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>') no-repeat center/contain;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23000"><path d="M12 3v12m0 0l-4-4m4 4l4-4M5 21h14" stroke="%23000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>') no-repeat center/contain;
  background: currentColor;
}

.tg-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 12px;
  border-radius: var(--tg-radius-pill);
  background: var(--tg-surface-2);
  border: 1px solid var(--tg-border);
  color: var(--tg-text-muted);
}

.tg-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  color: var(--tg-text-muted);
  font-size: 12px;
}
.tg-divider::before, .tg-divider::after { content: ""; height: 1px; background: var(--tg-border); display: block; }

.tg-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--tg-surface-2);
  border: 1px solid var(--tg-border);
  color: var(--tg-text);
  display: inline-grid;
  place-items: center;
  font-weight: 700;
}

.tg-bubble {
  background: var(--tg-surface);
  border: 1px solid var(--tg-border);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--tg-shadow-1);
  max-width: 720px;
}
.tg-bubble--in { background: var(--tg-surface); }
.tg-bubble--out { background: linear-gradient(180deg, var(--tg-accent) 0%, var(--tg-accent-2) 100%); color: var(--tg-accent-contrast); border-color: transparent; }
.tg-bubble__header { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.tg-name { font-weight: 700; }
.tg-time { margin-left: auto; font-size: 12px; opacity: .7; }

.tg-code {
  font-family: var(--tg-font-mono);
  font-size: 13px;
  background: var(--tg-surface-2);
  border: 1px solid var(--tg-border);
  border-radius: var(--tg-radius-s);
  padding: 10px 12px;
  overflow: auto;
}

.tg-quote {
  border-left: 3px solid var(--tg-quote-border);
  background: var(--tg-quote-bg);
  padding: 10px 12px;
  border-radius: 0 var(--tg-radius-m) var(--tg-radius-m) 0;
}
.tg-quote .tg-name { color: var(--tg-accent); }

details.tg-collapse {
  background: var(--tg-quote-bg);
  border: 1px solid var(--tg-quote-border);
  border-radius: var(--tg-radius-m);
  box-shadow: var(--tg-shadow-1);
}
details.tg-collapse > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  color: var(--tg-text);
  user-select: none;
}
details.tg-collapse > summary::-webkit-details-marker { display: none; }
details.tg-collapse > summary::before {
  content: "";
  width: 16px; height: 16px;
  display: inline-block;
  margin-right: 4px;
  transform: rotate(-90deg);
  transition: transform .2s ease;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6 9l6 6 6-6" fill="%23000"/></svg>') no-repeat center/contain;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6 9l6 6 6-6" fill="%23000"/></svg>') no-repeat center/contain;
  background: currentColor;
}
details.tg-collapse[open] > summary::before { transform: rotate(0deg); }
details.tg-collapse .tg-collapse__content { padding: 0 12px 12px 12px; }

.tg-attachment {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--tg-border);
  border-radius: var(--tg-radius-m);
  background: var(--tg-surface);
}
.tg-attachment__icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  color: var(--tg-accent);
  background: var(--tg-quote-bg);
  border: 1px solid var(--tg-quote-border);
}
.tg-attachment__meta { display: grid; gap: 2px; }
.tg-attachment__title { font-weight: 600; }
.tg-attachment__desc { font-size: 12px; color: var(--tg-text-muted); }

.tg-spoiler {
  color: transparent;
  text-shadow: 0 0 8px rgba(0,0,0,.6);
  background: linear-gradient(0deg, rgba(0,0,0,.06), rgba(0,0,0,0));
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s ease;
}
.tg-spoiler:hover, .tg-spoiler.is-open { color: inherit; text-shadow: none; background: transparent; }

.tg-list {
  display: grid; gap: 8px;
  padding-left: 0; list-style: none;
}
.tg-list__item { display: flex; gap: 10px; align-items: flex-start; }
.tg-list__item::before {
  content: ""; width: 18px; height: 18px; margin-top: 3px; flex: 0 0 18px;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 6L9 17l-5-5" fill="%23000"/></svg>') no-repeat center/contain;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 6L9 17l-5-5" fill="%23000"/></svg>') no-repeat center/contain;
  background: var(--tg-accent);
}

.tg-note {
  background: var(--tg-quote-bg);
  border: 1px solid var(--tg-quote-border);
  border-radius: var(--tg-radius-m);
  padding: 12px;
}

.edu-course-card {
  background: var(--tg-surface);
  border: 1px solid var(--tg-border);
  border-radius: 16px;
  box-shadow: var(--tg-shadow-1);
  padding: 16px;
}
.edu-course-card__title { font-weight: 800; font-size: 22px; }
.edu-course-card__meta { color: var(--tg-text-muted); font-size: 13px; }

.edu-module {
  background: var(--tg-surface);
  border: 1px solid var(--tg-border);
  border-radius: 14px;
  padding: 14px;
}
.edu-module__header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.edu-module__title { font-weight: 700; }
.edu-module__body { display: grid; gap: 10px; }

.edu-lesson { display: grid; gap: 8px; padding: 12px; border-radius: 12px; background: var(--tg-surface-2); border: 1px solid var(--tg-border); }
.edu-lesson__title { font-weight: 700; }
.edu-lesson__desc { color: var(--tg-text-muted); font-size: 14px; }
.edu-lesson__actions { display: flex; flex-wrap: wrap; gap: 8px; }

.edu-download { display: inline-flex; align-items: center; gap: 8px; }
.edu-download .tg-button--download { padding-left: 12px; padding-right: 14px; }

.tg-media { border-radius: 14px; overflow: hidden; border: 1px solid var(--tg-border); }
.tg-reaction { display: inline-flex; gap: 6px; align-items: center; padding: 4px 8px; border-radius: var(--tg-radius-pill); background: var(--tg-surface-2); border: 1px solid var(--tg-border); font-size: 12px; color: var(--tg-text); }

.tg-caption { color: var(--tg-text-muted); font-size: 13px; }

.tg-kbd { font-family: var(--tg-font-mono); background: var(--tg-surface-2); border: 1px solid var(--tg-border); border-bottom-width: 2px; padding: 2px 6px; border-radius: 6px; font-size: 12px; }

.tg-table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--tg-surface); border: 1px solid var(--tg-border); border-radius: 12px; overflow: hidden; }
.tg-table th, .tg-table td { padding: 10px 12px; border-bottom: 1px solid var(--tg-border); }
.tg-table th { text-align: left; color: var(--tg-text-muted); font-weight: 600; background: var(--tg-surface-2); }
.tg-table tr:last-child td { border-bottom: 0; }

.tg-search { display: flex; align-items: center; gap: 8px; background: var(--tg-surface); border: 1px solid var(--tg-border); border-radius: var(--tg-radius-pill); padding: 8px 12px; }
.tg-search input { border: 0; outline: 0; background: transparent; color: var(--tg-text); width: 100%; }

.tg-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: var(--tg-radius-pill); background: var(--tg-surface-2); border: 1px solid var(--tg-border); font-size: 12px; }
.tg-chip--accent { background: rgba(51,144,236,.12); border-color: rgba(51,144,236,.24); color: var(--tg-accent); }

.tg-help { font-size: 13px; color: var(--tg-text-muted); }

.tg-grid { display: grid; gap: 12px; }
.tg-row { display: flex; gap: 12px; align-items: flex-start; }
.tg-col { flex: 1 1 0; }

.tg-muted { color: var(--tg-text-muted); }
.tg-hr { height: 1px; background: var(--tg-border); border: 0; }

.tg-wrap { overflow-wrap: anywhere; word-break: break-word; }

