/* ==========================================================================
   charactercalculator.de - Swiss/minimal, dense, precision utility
   Tokens: light default, dark via prefers-color-scheme + [data-theme]
   Fonts: system stack only - no third-party font CDN (DSGVO)
   ========================================================================== */

:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
             "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "Cascadia Mono", "Segoe UI Mono",
               "Roboto Mono", Menlo, Consolas, monospace;

  --bg: #F4F6F6;
  --surface: #FFFFFF;
  --surface-2: #EBF0EF;
  --text: #0F1E1C;
  --text-muted: #566B69;
  --border: #D9E1E0;
  --border-strong: #BDCAC8;
  --accent: #0F766E;
  --accent-hover: #0B5F59;
  --accent-soft: #E1F2F0;
  --on-accent: #FFFFFF;
  --warn: #9A5B06;
  --danger: #B42318;

  --shadow-sm: 0 1px 2px rgba(15, 30, 28, .06);
  --shadow-md: 0 2px 8px rgba(15, 30, 28, .08);

  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;

  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  --sidebar-w: 268px;
  --header-h: 56px;
  --maxw: 1360px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0A100F;
    --surface: #121A19;
    --surface-2: #192322;
    --text: #E7EDEC;
    --text-muted: #94A5A3;
    --border: #253331;
    --border-strong: #354644;
    --accent: #2DD4BF;
    --accent-hover: #5EEAD4;
    --accent-soft: #10302D;
    --on-accent: #05201D;
    --warn: #E0A458;
    --danger: #F98A80;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 2px 10px rgba(0, 0, 0, .45);
  }
}

:root[data-theme="dark"] {
  --bg: #0A100F;
  --surface: #121A19;
  --surface-2: #192322;
  --text: #E7EDEC;
  --text-muted: #94A5A3;
  --border: #253331;
  --border-strong: #354644;
  --accent: #2DD4BF;
  --accent-hover: #5EEAD4;
  --accent-soft: #10302D;
  --on-accent: #05201D;
  --warn: #E0A458;
  --danger: #F98A80;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 2px 10px rgba(0, 0, 0, .45);
}

/* --------------------------------------------------------------- reset -- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 {
  line-height: 1.25; margin: 0 0 var(--s-3); font-weight: 650;
  letter-spacing: -.015em; text-wrap: balance;
}
h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); }
h2 { font-size: clamp(1.2rem, 1.05rem + .6vw, 1.5rem); margin-top: var(--s-8); }
h3 { font-size: 1.0625rem; margin-top: var(--s-6); }
p { margin: 0 0 var(--s-4); text-wrap: pretty; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
button { font: inherit; cursor: pointer; }
table { border-collapse: collapse; width: 100%; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--s-3); top: -100px; z-index: 100;
  background: var(--accent); color: var(--on-accent);
  padding: var(--s-2) var(--s-4); border-radius: var(--r-md); font-weight: 600;
}
.skip-link:focus { top: var(--s-3); }

/* -------------------------------------------------------------- header -- */
.site-header {
  position: sticky; top: 0; z-index: 46;
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: var(--s-2);
  font-weight: 700; font-size: 1rem; color: var(--text);
  text-decoration: none; letter-spacing: -.02em; white-space: nowrap;
}
.brand svg { flex: none; color: var(--accent); }
.brand b { color: var(--accent); }
.header-spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; padding: 0 var(--s-2);
  background: transparent; color: var(--text-muted);
  border: 1px solid transparent; border-radius: var(--r-md);
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.nav-toggle { display: none; }

/* --------------------------------------------------------------- shell -- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: var(--s-6);
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--s-6) var(--s-4) var(--s-12);
  align-items: start;
}

/* ------------------------------------------------------------- sidebar -- */
.sidebar {
  position: sticky; top: calc(var(--header-h) + var(--s-6));
  max-height: calc(100vh - var(--header-h) - var(--s-10));
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-3);
}
.sidebar h2 {
  margin: var(--s-4) var(--s-2) var(--s-2);
  font-size: .6875rem; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-muted);
}
.sidebar h2:first-child { margin-top: var(--s-1); }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a {
  display: block; padding: 7px var(--s-2);
  font-size: .875rem; color: var(--text); text-decoration: none;
  border-radius: var(--r-sm); border-left: 2px solid transparent;
  transition: background .16s ease, color .16s ease;
}
.sidebar a:hover { background: var(--surface-2); }
.sidebar a[aria-current="page"] {
  background: var(--accent-soft); color: var(--accent);
  font-weight: 600; border-left-color: var(--accent);
}

/* ---------------------------------------------------------------- main -- */
.main { min-width: 0; }
.lede { color: var(--text-muted); font-size: 1.0625rem; margin-bottom: var(--s-5); max-width: 62ch; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  margin-bottom: var(--s-4);
}
.card-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--s-2); margin-bottom: var(--s-3);
}
.card-head h2, .card-head h3 { margin: 0; font-size: .9375rem; font-weight: 650; }

/* -------------------------------------------------------------- editor -- */
.editor-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2);
  margin-bottom: var(--s-2);
}
.tool-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 38px; padding: 0 var(--s-3);
  font-size: .8125rem; font-weight: 550;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-md);
  transition: background .18s ease, border-color .18s ease, color .18s ease;
}
.tool-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.tool-btn svg { flex: none; color: var(--text-muted); }
.tool-btn:hover svg { color: var(--accent); }
.tool-btn.is-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.tool-btn.is-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.tool-btn.is-primary svg { color: currentColor; }
.tool-btn[data-state="done"] { border-color: var(--accent); color: var(--accent); }

.text-area {
  display: block; width: 100%;
  min-height: 260px;
  padding: var(--s-4);
  font-family: var(--font-ui); font-size: 1rem; line-height: 1.65;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  resize: vertical; tab-size: 2;
}
.text-area::placeholder { color: var(--text-muted); }
.text-area:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.text-area[readonly] { background: var(--surface-2); }

.editor-foot {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-2);
  margin-top: var(--s-2); font-size: .8125rem; color: var(--text-muted);
}
.privacy-note { display: inline-flex; align-items: center; gap: 6px; }
.privacy-note svg { color: var(--accent); flex: none; }

/* ----------------------------------------------------------- stat grid -- */
.stats-primary,
.stats-secondary {
  display: grid; gap: var(--s-2);
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.stats-primary { margin-bottom: var(--s-2); }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--s-3); min-width: 0;
}
.stat .value {
  display: block;
  font-size: 1.5rem; font-weight: 680; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1;
  color: var(--text); line-height: 1.15;
}
.stat .label {
  display: block; margin-top: 2px;
  font-size: .75rem; font-weight: 550; color: var(--text-muted);
  letter-spacing: .01em; hyphens: auto;
}
.stat .sub {
  display: block; margin-top: 3px;
  font-size: .6875rem; color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.stats-primary .stat {
  background: var(--accent-soft); border-color: transparent; padding: var(--s-4) var(--s-3);
}
.stats-primary .stat .value { font-size: clamp(1.6rem, 1.2rem + 1vw, 2.125rem); color: var(--accent); }
.stats-primary .stat .label { color: var(--text); font-weight: 600; font-size: .8125rem; }

/* -------------------------------------------------------------- limits -- */
.limits { display: grid; gap: var(--s-3); grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.limit { min-width: 0; }
.limit-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-2);
  font-size: .8125rem; margin-bottom: 5px;
}
.limit-head .name { font-weight: 550; }
.limit-head .num { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: .75rem; }
.limit-bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.limit-fill { height: 100%; width: 0; border-radius: 99px; background: var(--accent); transition: width .2s ease, background-color .2s ease; }
.limit[data-status="warn"] .limit-fill { background: var(--warn); }
.limit[data-status="over"] .limit-fill { background: var(--danger); }
.limit[data-status="warn"] .num { color: var(--warn); font-weight: 600; }
.limit[data-status="over"] .num { color: var(--danger); font-weight: 650; }

/* ------------------------------------------------------------ keywords -- */
.kw-table { font-size: .875rem; }
.kw-table th, .kw-table td { text-align: left; padding: 7px var(--s-2); border-bottom: 1px solid var(--border); }
.kw-table th {
  font-size: .6875rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); font-weight: 650;
}
.kw-table td:nth-child(2), .kw-table td:nth-child(3),
.kw-table th:nth-child(2), .kw-table th:nth-child(3) {
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.kw-table tr:last-child td { border-bottom: 0; }
.muted-note { color: var(--text-muted); font-size: .875rem; margin: var(--s-2) 0 0; }

.seg { display: inline-flex; gap: 2px; padding: 2px; background: var(--surface-2); border-radius: var(--r-md); }
.seg button {
  min-height: 32px; padding: 0 var(--s-3); font-size: .8125rem; font-weight: 550;
  color: var(--text-muted); background: transparent; border: 0; border-radius: var(--r-sm);
  transition: background .16s ease, color .16s ease;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

/* ------------------------------------------------------------ settings -- */
.settings { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: .8125rem; font-weight: 550; }
.field .hint { font-size: .75rem; color: var(--text-muted); }
.field select, .field input[type="number"] {
  font: inherit; font-size: .875rem; min-height: 38px; padding: 0 var(--s-2);
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
}
.field input[type="range"] { accent-color: var(--accent); min-height: 38px; }
.switch { display: flex; align-items: center; gap: var(--s-2); font-size: .875rem; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.settings-actions { justify-content: center; align-items: flex-start; }
.settings-actions .tool-btn { min-height: 42px; }

/* --------------------------------------------------------------- 404 --- */
.not-found {
  min-height: min(68vh, 680px); display: grid; place-items: center;
  text-align: center; padding: var(--s-12) var(--s-4);
}
.not-found-inner { max-width: 640px; }
.not-found-code {
  display: block; margin-bottom: var(--s-2); color: var(--accent);
  font-size: .75rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
}
.not-found h1 { font-size: clamp(2rem, 1.4rem + 3vw, 4rem); }
.not-found p { max-width: 52ch; margin: var(--s-4) auto var(--s-6); color: var(--text-muted); }
.not-found .tool-btn { display: inline-flex; text-decoration: none; }

/* --------------------------------------------------------- readability -- */
.score-row { display: grid; gap: var(--s-3); grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.score { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-3); background: var(--surface); }
.score .value { font-size: 1.75rem; font-weight: 680; font-variant-numeric: tabular-nums; color: var(--accent); }
.score .name { font-size: .8125rem; font-weight: 600; }
.score .desc { font-size: .75rem; color: var(--text-muted); margin-top: 4px; }

/* --------------------------------------------------------------- prose -- */
.prose { max-width: 72ch; margin-top: var(--s-10); }
.prose h2 { padding-top: var(--s-2); }
.prose ul, .prose ol { margin: 0 0 var(--s-4); padding-left: 1.3em; }
.prose li { margin-bottom: 6px; }
.prose table { font-size: .875rem; margin-bottom: var(--s-5); }
.prose th, .prose td { text-align: left; padding: 8px var(--s-2); border-bottom: 1px solid var(--border); }
.prose th { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.prose td:last-child, .prose th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.prose details { border-bottom: 1px solid var(--border); padding: var(--s-3) 0; }
.prose details summary { cursor: pointer; font-weight: 600; list-style: none; position: relative; padding-right: var(--s-6); }
.prose details summary::-webkit-details-marker { display: none; }
.prose details summary::after {
  content: ""; position: absolute; right: 6px; top: .45em;
  width: 8px; height: 8px;
  border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg); transition: transform .2s ease;
}
.prose details[open] summary::after { transform: rotate(-135deg); }
.prose details > *:not(summary) { margin-top: var(--s-3); }
.prose details p:last-child { margin-bottom: 0; }
.callout {
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  padding: var(--s-3) var(--s-4); margin-bottom: var(--s-5);
}
.callout p:last-child { margin-bottom: 0; }

/* -------------------------------------------------------------- footer -- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: var(--s-8) var(--s-4) var(--s-6); }
.footer-inner { max-width: var(--maxw); margin: 0 auto; }
.footer-cols { display: grid; gap: var(--s-6); grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.footer-cols h3 {
  margin: 0 0 var(--s-2); font-size: .6875rem; text-transform: uppercase;
  letter-spacing: .09em; color: var(--text-muted); font-weight: 700;
}
.footer-cols ul { list-style: none; margin: 0; padding: 0; }
.footer-cols li { margin-bottom: 5px; }
.footer-cols a { font-size: .8125rem; color: var(--text); text-decoration: none; }
.footer-cols a:hover { color: var(--accent); text-decoration: underline; }
.footer-bottom {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-3);
  margin-top: var(--s-8); padding-top: var(--s-4); border-top: 1px solid var(--border);
  font-size: .8125rem; color: var(--text-muted);
}
.footer-bottom nav { display: flex; flex-wrap: wrap; gap: var(--s-4); }

/* ----------------------------------------------------------- responsive - */
@media (max-width: 1080px) {
  .stats-secondary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .js .nav-toggle { display: inline-flex; }
  .shell { grid-template-columns: minmax(0, 1fr); gap: var(--s-4); padding-top: var(--s-4); }
  .js .sidebar {
    position: fixed; inset: var(--header-h) auto 0 0;
    width: min(320px, 86vw); max-height: none; height: calc(100dvh - var(--header-h));
    border-radius: 0; border-width: 0 1px 0 0; z-index: 45;
    transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: var(--shadow-md);
  }
  .js .sidebar.is-open { transform: none; }
  .nav-scrim { position: fixed; inset: var(--header-h) 0 0; z-index: 44; background: rgba(8, 18, 17, .45); border: 0; }
}
@media (max-width: 720px) {
  .stats-primary, .stats-secondary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .text-area { min-height: 42vh; }
  .stat .value { font-size: 1.3rem; }
  h2 { margin-top: var(--s-6); }
}
@media (max-width: 400px) {
  .stat .value { font-size: 1.15rem; }
  .stats-primary .stat { padding: var(--s-3); }
}

@media print {
  .site-header, .sidebar, .editor-toolbar, .site-footer, .nav-scrim { display: none !important; }
  .shell { display: block; padding: 0; }
  .card { border: 1px solid #ccc; break-inside: avoid; }
}
