/* AI Text Detector demo: colour tokens first. Light by default; dark from html[data-x2-theme="dark"] (the host page),
   html[data-theme="dark"] (set by demo.js from ?theme=dark or data-x2-theme), or the system setting when neither is set. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --text: #1f2328;
  --muted: #5f6670;
  --faint: #8a9099;
  --panel: #f2f3f5;
  --card: #ffffff;
  --line: #dfe2e6;
  --line-strong: #c9cdd3;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --accent-hover: #2f4ac0;
  --tag: #3b5bdb;
  --field: #ffffff;
  --pop: #ffffff;
  --pop-shadow: 0 8px 28px rgba(15, 20, 30, .18);
  --code: #eef0f3;
  --focus: #4c6ef5;
  --track-off: #c3c8cf;
  /* label colours: the same as the extension's, on both themes (each badge has its own solid background) */
  --ai: #e8590c;
  --ai-badge: #c2410c;
  --unsure: #868e96;
  --unsure-badge: #5c636a;
  --human: #2b8a3e;
  --human-badge: #2b8a3e;
  --plain-line: #ced4da;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-x2-theme="light"]):not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #15171a;
    --text: #e6e8eb;
    --muted: #a3a9b2;
    --faint: #7d848e;
    --panel: #0e1012;
    --card: #1d2024;
    --line: #2e3238;
    --line-strong: #3d424a;
    --accent: #748ffc;
    --accent-text: #0e1012;
    --accent-hover: #91a7ff;
    --tag: #91a7ff;
    --field: #1d2024;
    --pop: #23272c;
    --pop-shadow: 0 10px 30px rgba(0, 0, 0, .55);
    --code: #2a2e34;
    --focus: #91a7ff;
    --track-off: #4a5059;
    --plain-line: #4a5059;
  }
}

html[data-x2-theme="dark"],
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15171a;
  --text: #e6e8eb;
  --muted: #a3a9b2;
  --faint: #7d848e;
  --panel: #0e1012;
  --card: #1d2024;
  --line: #2e3238;
  --line-strong: #3d424a;
  --accent: #748ffc;
  --accent-text: #0e1012;
  --accent-hover: #91a7ff;
  --tag: #91a7ff;
  --field: #1d2024;
  --pop: #23272c;
  --pop-shadow: 0 10px 30px rgba(0, 0, 0, .55);
  --code: #2a2e34;
  --focus: #91a7ff;
  --track-off: #4a5059;
  --plain-line: #4a5059;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
}
main {
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  /* fills the frame exactly (the article shows it 580 px tall): the feed takes whatever height is left */
  min-height: 100vh;
  min-height: 100dvh;
}
p, h2, ol { margin: 0; }
button, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
code { font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--code); padding: 1px 4px; border-radius: 4px; }
.small { font-size: 12px; color: var(--muted); }

/* ---------- intro ---------- */
.intro .lead { font-size: 14px; font-weight: 600; line-height: 1.35; }
.intro .small { margin-top: 2px; }

/* ---------- feed panel ---------- */
.feed-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1 1 250px;
  min-height: 250px;
  max-height: 640px;
}
.feed-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  min-width: 0;
  flex: none;
}
.switch {
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; background: none; padding: 2px; cursor: pointer;
  font-weight: 650; font-size: 13px; flex: none;
}
.track {
  width: 34px; height: 20px; border-radius: 10px; background: var(--track-off);
  position: relative; transition: background .15s; flex: none;
}
.thumb {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s;
}
.switch[aria-checked="true"] .track { background: var(--accent); }
.switch[aria-checked="true"] .thumb { transform: translateX(14px); }
.status {
  flex: 1; min-width: 0; font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right;
}
.reset {
  flex: none; border: 1px solid var(--line-strong); background: var(--card); border-radius: 8px;
  padding: 3px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.reset:hover { border-color: var(--muted); }

.feed {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

/* ---------- a post ---------- */
.post {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px 12px;
  flex: none;
}
/* the label's frame, drawn over the card like the extension's */
.post::after {
  content: ""; position: absolute; inset: -1px; border-radius: 10px; pointer-events: none;
  border: 0 solid transparent;
}
.post[data-kind="ai"]::after { border: 3px solid var(--ai); }
.post[data-kind="uncertain"]::after { border: 3px solid var(--unsure); }
.post[data-kind="human"]::after { border: 3px solid var(--human); }
.post[data-kind="checking"]::after { border: 2px dotted var(--unsure); }
.post[data-kind="short"]::after,
.post[data-kind="error"]::after { border: 1px solid var(--plain-line); }

.post-head { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .02em;
}
.who { flex: 1; min-width: 0; line-height: 1.3; }
.name { font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.headline, .when { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.when { color: var(--faint); }
.dots { flex: none; color: var(--faint); font-size: 18px; line-height: 1; padding: 2px 2px 0; letter-spacing: 1px; user-select: none; }

.post-text {
  margin-top: 10px;
  white-space: pre-line;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.45;
}
.post-text.clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}
.post-text .tag { color: var(--tag); font-weight: 600; }
.more {
  border: 0; background: none; padding: 0; margin-top: 2px; cursor: pointer;
  color: var(--muted); font-size: 13px; font-weight: 600;
}
.more:hover { color: var(--text); text-decoration: underline; }
.placeholder { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--faint); }

/* ---------- the label badge (as in the extension) ---------- */
.badge {
  flex: none;
  margin: 1px 0 0;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 4px 11px;
  font: 700 13px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #fff;
  background: var(--unsure-badge);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  cursor: pointer;
  white-space: nowrap;
  max-width: 100%;
}
.badge[hidden] { display: none; }
.badge[data-kind="ai"] { background: var(--ai-badge); }
.badge[data-kind="uncertain"] { background: var(--unsure-badge); }
.badge[data-kind="human"] { background: var(--human-badge); }
.badge[data-kind="checking"] { background: #fff; color: #343a40; border: 1px dotted #868e96; }
.badge[data-kind="short"],
.badge[data-kind="error"] { background: #f1f3f5; color: #343a40; border-color: #adb5bd; }
.badge[data-kind="checking"]::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%;
  border: 2px solid #adb5bd; border-top-color: #495057; vertical-align: -1px; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .badge[data-kind="checking"]::before { animation: none; } .feed { scroll-behavior: auto; } }

/* ---------- the reasons card ---------- */
.why {
  position: absolute;
  z-index: 5;
  top: 50px;
  right: 10px;
  width: min(310px, calc(100% - 20px));
  background: var(--pop);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--pop-shadow);
  padding: 12px 14px 10px;
}
.why[hidden] { display: none; }
.why-head { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; }
.why-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; background: var(--unsure); }
.why-dot[data-kind="ai"] { background: var(--ai); }
.why-dot[data-kind="human"] { background: var(--human); }
.why-dot[data-kind="checking"], .why-dot[data-kind="short"], .why-dot[data-kind="error"] { background: #adb5bd; }
.why-x { margin-left: auto; border: 0; background: none; color: var(--faint); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; }
.why-x:hover { color: var(--text); }
.why-by { margin-top: 2px; font-size: 12px; color: var(--muted); }
.why ul { margin: 8px 0 0; padding: 0; list-style: none; }
.why li { position: relative; padding-left: 16px; margin-top: 4px; font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.why li::before { content: "•"; position: absolute; left: 3px; color: var(--faint); }
.why p.msg { margin-top: 8px; font-size: 13px; overflow-wrap: anywhere; }
.why-foot { margin-top: 10px; padding-top: 6px; border-top: 1px solid var(--line); font-size: 11px; color: var(--faint); }

/* ---------- try your own ---------- */
.try { display: flex; flex-direction: column; gap: 5px; }
.try-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.try h2 { font-size: 14px; font-weight: 650; }
.try-row { display: flex; gap: 8px; align-items: stretch; }
.try textarea {
  flex: 1; min-width: 0; resize: vertical; min-height: 44px; max-height: 180px;
  border: 1px solid var(--line-strong); border-radius: 10px; padding: 7px 10px;
  background: var(--field); font-size: 13px; line-height: 1.4;
}
.try textarea::placeholder { color: var(--faint); }
.check {
  flex: none; border: 1px solid var(--line-strong); background: var(--card); border-radius: 10px;
  padding: 0 18px; font-weight: 650; cursor: pointer;
}
.check:hover:not(:disabled) { border-color: var(--muted); }
.check:disabled { opacity: .55; cursor: default; }
.try-result {
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--card);
}
.try-result[hidden] { display: none; }
.try-result .badge { cursor: default; }
.try-result ul { margin: 0; padding: 0 0 0 16px; font-size: 13px; }
.try-result li { overflow-wrap: anywhere; }
.try-result .msg { font-size: 13px; overflow-wrap: anywhere; }
.try-result .why-foot { margin-top: 0; padding-top: 4px; align-self: stretch; }

/* ---------- download ---------- */
.get { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; }
.download {
  flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--accent-text); text-decoration: none;
  font-weight: 700; font-size: 14px; padding: 10px 18px; border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.download:hover { background: var(--accent-hover); }
.how { display: contents; }
.how summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text); list-style: none;
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 0;
}
.how summary::-webkit-details-marker { display: none; }
.how summary::before {
  content: ""; width: 6px; height: 6px; margin-right: 4px; border: solid var(--muted); border-width: 0 2px 2px 0;
  transform: rotate(-45deg); transition: transform .15s;
}
.how[open] summary::before { transform: rotate(45deg); }
.how-body { flex-basis: 100%; }
.steps { padding: 0; list-style: none; counter-reset: step; font-size: 12.5px; line-height: 1.6; }
.steps li { display: inline; counter-increment: step; margin-right: 8px; }
.steps li::before { content: counter(step) ". "; font-weight: 700; color: var(--text); }
.how-body .small { margin-top: 2px; font-size: 12px; color: var(--muted); }

/* ---------- phones ---------- */
@media (max-width: 520px) {
  main { padding: 8px 10px 10px; gap: 9px; }
  .intro .lead { font-size: 13.5px; }
  .feed { padding: 8px; gap: 8px; }
  .feed-wrap { flex-basis: 220px; min-height: 220px; }
  .post { padding: 11px 12px; }
  .avatar { width: 36px; height: 36px; font-size: 13px; }
  .post-head { gap: 8px; }
  .get { gap: 8px 10px; }
  .download { padding: 10px 12px; font-size: 13.5px; gap: 6px; }
  .how summary { font-size: 12.5px; }
  .intro .small { font-size: 11.5px; }
  .switch-label { font-size: 12.5px; }
}
@media (max-width: 360px) {
  .status { display: none; }
  .feed-bar { justify-content: space-between; }
}
.try-note { margin: 6px 0 0; }
