:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --text: #1c2333;
  --muted: #667085;
  --border: #e3e6ee;
  --primary: #3355ff;
  --primary-hover: #2442e0;
  --primary-soft: #eef1ff;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b24;
    --surface-2: #1e2330;
    --text: #e7eaf0;
    --muted: #98a2b3;
    --border: #2a3040;
    --primary: #6b85ff;
    --primary-hover: #8399ff;
    --primary-soft: #1f2747;
    --good: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
code { font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3355ff, #7c3aed); color: #fff; font-weight: 800; font-family: var(--serif); font-size: 22px;
}
.brand-name { font-size: 1.1rem; font-weight: 700; margin: 0; letter-spacing: -.01em; color: var(--text); text-decoration: none; }
.tagline { margin: 0; font-size: .82rem; color: var(--muted); }
.privacy {
  display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--good);
  background: color-mix(in srgb, var(--good) 10%, transparent); padding: 6px 12px; border-radius: 999px;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 10px 16px; border-radius: 10px;
  font-weight: 600; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.primary:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn.block { width: 100%; padding: 13px; }
.btn.icon { padding: 8px; display: inline-grid; place-items: center; border-radius: 10px; }
.link-btn { background: none; border: none; padding: 0; color: var(--primary); font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 50%, transparent); outline-offset: 2px; }

/* ---------- Start screen ---------- */
.start { width: 100%; max-width: 820px; margin: 0 auto; padding: 48px 20px 24px; flex: 1; }
.hero { text-align: center; margin-bottom: 28px; }
.hero h1 { margin: 0 0 12px; font-size: .95rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--primary); }
.h1-sub { display: block; margin-top: 8px; font-family: var(--serif); font-size: clamp(1.7rem, 4vw, 2.4rem); line-height: 1.2; letter-spacing: -.01em; text-transform: none; color: var(--text); font-weight: 700; }
.h1-sub em { color: var(--primary); }
.hero p { color: var(--muted); max-width: 640px; margin: 0 auto; }
.hero p strong { color: var(--text); font-weight: 600; }

.input-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); padding: 18px; }
.tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; width: fit-content; margin-bottom: 14px; }
.tab { border: none; background: transparent; padding: 8px 16px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  border: 2px dashed var(--border); border-radius: 16px; padding: 44px 20px; cursor: pointer;
  color: var(--muted); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dz-title { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.formats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.fmt { font-size: .75rem; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.fmt.best { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }

#paste-input {
  width: 100%; min-height: 260px; resize: vertical; padding: 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; font-size: .95rem;
}
.paste-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 10px; }
.sample-row { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 14px; font-size: .92rem; }
.error { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); font-size: .92rem; }

.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 34px; }
.step { display: flex; gap: 12px; align-items: flex-start; }
.step .num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
.step h3 { margin: 2px 0 2px; font-size: .98rem; }
.step p { margin: 0; color: var(--muted); font-size: .88rem; }

/* ---------- Loading ---------- */
.loading { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 80px 20px; color: var(--muted); }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Results ---------- */
.results { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 24px; padding: 24px 28px; max-width: 1400px; width: 100%; margin: 0 auto; flex: 1; align-items: start; }
.sidebar { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 32px); overflow-y: auto; padding-bottom: 4px; scrollbar-width: thin; }

.file-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.file-info { min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-format { font-size: .8rem; }
.note { font-size: .82rem; background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn); padding: 10px 12px; border-radius: 10px; }

.count-card {
  background: linear-gradient(135deg, var(--primary), #6d4aff); color: #fff; border-radius: 18px; padding: 18px 20px; box-shadow: var(--shadow);
}
.count-label { font-size: .85rem; opacity: .9; font-weight: 600; }
.count-row { display: flex; align-items: center; justify-content: space-between; }
.count { font-size: 3.2rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.count-card .btn.icon { background: rgba(255, 255, 255, .15); border-color: rgba(255, 255, 255, .25); color: #fff; }
.count-card .btn.icon:hover { background: rgba(255, 255, 255, .28); }
.limit { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: .85rem; }
.limit input {
  width: 100px; padding: 5px 9px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .14); color: #fff; font: inherit; font-weight: 600;
}
.limit input::placeholder { color: rgba(255, 255, 255, .6); }
.progress { margin-top: 10px; height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .22); overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: #fff; border-radius: 99px; transition: width .3s, background .3s; }
.progress .bar.over { background: #ffb4b4; }
.limit-status { font-size: .85rem; margin-top: 6px; font-weight: 600; min-height: 1px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 6px; text-align: center; display: flex; flex-direction: column; }
.stat-num { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { font-size: .7rem; color: var(--muted); line-height: 1.2; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel h3 { margin: 0; font-size: .98rem; }
.panel > p { margin: 2px 0 8px; }

.cat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.cat-item {
  display: grid; grid-template-columns: 12px 1fr auto 38px; align-items: center; gap: 10px; padding: 6px 6px; border-radius: 8px; cursor: pointer;
}
.cat-item:hover { background: var(--surface-2); }
.cat-item.empty { opacity: .45; }
.dot { width: 12px; height: 12px; border-radius: 4px; }
.cat-name { font-size: .9rem; }
.cat-words { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cat-item.on .cat-words { color: var(--text); font-weight: 600; }

.switch { position: relative; width: 36px; height: 20px; border-radius: 99px; background: var(--border); border: none; padding: 0; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch[aria-checked="true"] { background: var(--good); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }

.check { display: flex; gap: 10px; align-items: flex-start; font-size: .88rem; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--primary); }

/* ---------- Document preview ---------- */
.doc { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); min-width: 0; }
.doc-toolbar {
  position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 18px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px); border-radius: 18px 18px 0 0;
}
.hint { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); }
.hint strong { color: var(--text); }
.seg { display: flex; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.seg-btn { border: none; background: transparent; padding: 5px 12px; border-radius: 8px; font-size: .82rem; font-weight: 600; color: var(--muted); }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

.doc-body { padding: 18px 26px 40px 18px; font-family: var(--serif); font-size: 1.02rem; }
.blk {
  position: relative; padding: 6px 10px 6px 16px; margin: 0 0 4px; border-left: 4px solid var(--c); border-radius: 0 8px 8px 0;
  cursor: pointer; transition: background .12s, opacity .12s;
}
.blk:hover, .blk.active { background: color-mix(in srgb, var(--c) 9%, transparent); }
.blk.first { margin-top: 18px; }
.blk.first:first-child { margin-top: 0; }
.blk-tag {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--font); font-size: .72rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  color: var(--c); margin-bottom: 4px;
}
.blk-tag .state { font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--muted); }
.blk-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.blk.heading .blk-text { font-family: var(--font); font-weight: 700; font-size: 1.02rem; }
.blk.lvl1 .blk-text { font-size: 1.18rem; }
.blk.table .blk-text { font-family: var(--font); font-size: .82rem; max-height: 180px; overflow: auto; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }
.blk.off { opacity: .55; }
.blk.off .blk-text { color: var(--muted); }
.blk-words { position: absolute; right: 8px; top: 6px; font-family: var(--font); font-size: .72rem; color: var(--muted); opacity: 0; transition: opacity .12s; background: var(--surface); padding: 0 6px; border-radius: 6px; }
.blk:hover .blk-words, .blk.active .blk-words { opacity: 1; }
.blk.edited::after {
  content: "edited"; position: absolute; left: -2px; top: 50%; transform: translate(-100%, -50%); font-family: var(--font); font-size: .6rem; font-weight: 700;
  color: var(--muted); writing-mode: vertical-rl; rotate: 180deg; padding: 0 2px;
}
.blk-note { font-family: var(--font); font-size: .8rem; color: var(--muted); font-style: italic; margin-top: 2px; }
.empty-msg { padding: 40px; text-align: center; color: var(--muted); font-family: var(--font); }

/* ---------- Picker ---------- */
.picker {
  position: fixed; z-index: 50; width: 300px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(16, 24, 40, .2); padding: 10px; max-height: 70vh; overflow-y: auto;
}
.picker-title { font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 4px 8px 6px; }
.picker ul { list-style: none; margin: 0; padding: 0; }
.picker li button {
  width: 100%; display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: center; text-align: left;
  border: none; background: none; padding: 7px 8px; border-radius: 8px; font-size: .9rem;
}
.picker li button:hover, .picker li button:focus-visible { background: var(--surface-2); }
.picker li button.current { background: var(--primary-soft); font-weight: 700; }
.picker .tag-on { font-size: .72rem; color: var(--good); font-weight: 600; }
.picker .tag-off { font-size: .72rem; color: var(--muted); }
.picker-follow { padding: 8px 8px 4px; border-top: 1px solid var(--border); margin-top: 6px; }
#picker-reset { padding: 6px 8px; }

/* ---------- Toast & footer ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #1c2333; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: .9rem; font-weight: 600; transition: opacity .2s, transform .2s; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.footer { text-align: center; padding: 16px 20px 24px; }
.footer p { margin: 4px 0; }
.footer a { color: var(--primary); }

/* ---------- Help content (start page) ---------- */
.seo-content { margin-top: 56px; padding-top: 36px; border-top: 1px solid var(--border); }
.seo-content h2 { font-family: var(--serif); font-size: 1.5rem; margin: 32px 0 10px; letter-spacing: -.01em; }
.seo-content h2:first-child { margin-top: 0; }
.seo-content p, .seo-content li { color: var(--muted); }
.seo-content strong { color: var(--text); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0 10px; }
.col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; }
.col h3 { margin: 0 0 6px; font-size: 1rem; }
.col.good h3 { color: var(--good); }
.col.bad h3 { color: var(--bad); }
.col ul { margin: 0; padding-left: 18px; }
.col li { margin: 3px 0; font-size: .93rem; }
.limits { padding-left: 20px; }
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; padding: 0 16px; }
.faq summary { cursor: pointer; font-weight: 600; padding: 13px 0; list-style-position: outside; }
.faq details[open] summary { border-bottom: 1px solid var(--border); }
.faq details p { margin: 10px 0 14px; }
.faq a { color: var(--primary); }

/* ---------- Support (Ko-fi / Buy Me a Coffee) ---------- */
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.support-btn { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; background: #ffdd57; border-color: #f5cf3c; color: #3b2a00; border-radius: 999px; padding: 8px 18px; font-size: .9rem; }
.support-btn:hover { background: #ffd23a; }

/* ---------- Referral box ---------- */
.partner { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.partner-head { display: flex; align-items: center; gap: 8px; font-size: .98rem; }
.partner p { margin: 6px 0 10px; font-size: .88rem; color: var(--muted); }
.partner-btn { display: block; text-align: center; text-decoration: none; background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.partner-btn:hover { background: var(--primary); color: #fff; }
.partner .partner-disclosure { margin: 8px 0 0; font-size: .72rem; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .results { grid-template-columns: 1fr; padding: 16px; }
  .sidebar { position: static; max-height: none; overflow: visible; }
  .how, .two-col { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; }
  .doc-body { padding: 14px 14px 30px 10px; }
  .blk.edited::after { display: none; }
}
