/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #fafaf8;
  --bg-2:    #f2f1ec;
  --bg-3:    #e8e7e0;
  --surface: #ffffff;
  --border:  #dddbd3;
  --border-2:#c9c7be;
  --text:    #1a1a18;
  --text-2:  #5a5a56;
  --text-3:  #9a9992;
  --ink:     #1a1a18;
  --ink-fg:  #fafaf8;
  --green:   #166534;
  --amber:   #92400e;
  --red:     #991b1b;
  --r:       6px;
  --r-lg:    10px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

/* ===== Header ===== */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 200;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}

.logo-mark {
  width: 26px; height: 26px;
  background: var(--ink);
  border-radius: 5px;
  display: grid; place-items: center;
  flex-shrink: 0;
}

.logo-mark svg { width: 13px; height: 13px; }

.logo-name {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.logo-tagline {
  font-size: 0.73rem;
  color: var(--text-3);
  padding-left: 10px;
  border-left: 1px solid var(--border);
  margin-left: 1px;
  white-space: nowrap;
}

@media (max-width: 600px) { .logo-tagline { display: none; } }


/* Lang selector in header */
.header-lang {
  font-family: inherit;
  font-size: 0.75rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text-2);
  padding: 4px 8px;
  outline: none;
  cursor: pointer;
  margin-left: 4px;
}

.header-lang:focus { border-color: var(--border-2); }

/* Hamburger button */
.hamburger {
  width: 36px; height: 36px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 0;
  transition: background 0.1s;
}

.hamburger:hover { background: var(--bg-2); }

.hamburger span {
  display: block;
  width: 16px; height: 1.5px;
  background: var(--text-2);
  border-radius: 2px;
  transition: all 0.2s;
}

.hamburger.open span:nth-child(1) { transform: translateY(5.5px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-5.5px) rotate(-45deg); }

/* ===== Mobile drawer ===== */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26,26,24,0.4);
  z-index: 150;
  opacity: 0;
  transition: opacity 0.2s;
}

.drawer-overlay.open { display: block; opacity: 1; }

.drawer {
  position: fixed;
  top: 0; right: 0;
  width: min(320px, 88vw);
  height: 100vh;
  background: var(--surface);
  z-index: 160;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

[dir="rtl"] .drawer { right: auto; left: 0; transform: translateX(-100%); }

.drawer.open { transform: translateX(0); }
[dir="rtl"] .drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.drawer-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}

.drawer-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-3);
  cursor: pointer;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: var(--r);
  transition: background 0.1s;
}

.drawer-close:hover { background: var(--bg-2); color: var(--text); }

.drawer nav {
  padding: 0.75rem 0;
  display: flex;
  flex-direction: column;
}

.drawer nav a {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  padding: 0.7rem 1.25rem;
  transition: background 0.1s;
  border-left: 3px solid transparent;
}

.drawer nav a:hover { background: var(--bg-2); border-left-color: var(--border-2); }

.drawer-section {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}

.drawer-section-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  margin-bottom: 0.6rem;
}

.drawer-lang-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.drawer-lang-btn {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-2);
  cursor: pointer;
  text-align: left;
  transition: all 0.1s;
}

.drawer-lang-btn:hover { background: var(--bg-3); color: var(--text); }
.drawer-lang-btn.active { background: var(--ink); color: var(--ink-fg); border-color: transparent; }

/* ===== Page ===== */
.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ===== Above-textarea bar ===== */
.above-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.15rem 0 0.55rem;
  flex-wrap: wrap;
  gap: 8px;
}

.live-counts {
  display: flex;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-2);
}

.lc-item { display: flex; align-items: center; gap: 5px; }

.lc-item + .lc-item::before {
  content: '';
  width: 1px; height: 11px;
  background: var(--border);
  margin: 0 10px;
}

.lc-val { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

.toolbar { display: flex; gap: 5px; flex-wrap: wrap; }

.btn {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: var(--r);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  transition: all 0.1s;
  white-space: nowrap;
}

.btn:hover { background: var(--bg-2); border-color: var(--border-2); color: var(--text); }

.btn-solid {
  background: var(--ink);
  color: var(--ink-fg);
  border-color: transparent;
}

.btn-solid:hover { background: #2e2e2c; color: var(--ink-fg); }

/* ===== Textarea block ===== */
.textarea-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: border-color 0.15s;
}

.textarea-block:focus-within { border-color: var(--border-2); }

#main-textarea {
  display: block;
  width: 100%;
  min-height: 220px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.92rem;
  line-height: 1.8;
  padding: 1rem 1.2rem;
  resize: vertical;
  caret-color: var(--ink);
}

#main-textarea::placeholder { color: var(--text-3); }

.textarea-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.9rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 6px;
}

.limit-pills { display: flex; gap: 5px; flex-wrap: wrap; }

.lpill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  transition: all 0.12s;
}

.ldot { width: 5px; height: 5px; border-radius: 50%; background: var(--border-2); flex-shrink: 0; }
.lpill.ok   .ldot { background: var(--green); }
.lpill.near { background: #fef3c7; border-color: #fbbf24; color: var(--amber); }
.lpill.near .ldot { background: var(--amber); }
.lpill.over { background: #fee2e2; border-color: #fca5a5; color: var(--red); }
.lpill.over .ldot { background: var(--red); }

.char-hint { font-size: 0.68rem; color: var(--text-3); }

/* ===== Stats row ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  overflow: hidden;
}

@media (max-width: 580px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .textarea-block { border-radius: var(--r-lg) var(--r-lg) 0 0; }
}

.sbox {
  background: var(--surface);
  padding: 0.85rem 0.75rem;
  text-align: center;
  transition: background 0.1s;
}

.sbox:hover { background: var(--bg-2); }
.sbox.primary { background: var(--ink); }
.sbox.primary .sn { color: var(--ink-fg); }
.sbox.primary .sl { color: rgba(250,250,248,0.5); }
.sbox.primary:hover { background: #2a2a28; }

.sn {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.sl {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--text-3);
  margin-top: 5px;
}

/* ===== Two-col panels ===== */
.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-top: 1.5rem;
}

@media (max-width: 640px) { .panels { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.panel-head {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-2);
}

.panel-body { padding: 0.85rem 1rem; }

/* Density */
.density-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.density-list::-webkit-scrollbar { width: 3px; }
.density-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.drow { display: flex; align-items: center; gap: 7px; }

.dword {
  min-width: 85px; max-width: 85px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.76rem; color: var(--text);
}

.dtrack { flex: 1; height: 3px; background: var(--bg-3); border-radius: 3px; overflow: hidden; }
.dbar   { height: 100%; background: var(--ink); border-radius: 3px; transition: width 0.2s ease; }
.dcnt   { font-size: 0.7rem; color: var(--text-2); min-width: 20px; text-align: right; font-variant-numeric: tabular-nums; }
.dpct   { font-size: 0.66rem; color: var(--text-3); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

.density-empty { font-size: 0.82rem; color: var(--text-3); text-align: center; padding: 3rem 0; }

/* Settings panel */
.settings-section + .settings-section {
  margin-top: 1rem; padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.settings-lbl {
  font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-3); margin-bottom: 0.5rem;
}

.lang-sel {
  font-family: inherit; font-size: 0.8rem;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r); color: var(--text);
  padding: 5px 9px; outline: none; cursor: pointer; width: 100%;
}

.lang-sel:focus { border-color: var(--border-2); }

.stopword-tags {
  display: flex; flex-wrap: wrap; gap: 4px;
  max-height: 90px; overflow-y: auto; margin-bottom: 0.6rem;
}

.sw-tag {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 100px; padding: 2px 7px;
  font-size: 0.66rem; color: var(--text-2);
}

.sw-tag button {
  background: none; border: none; color: var(--text-3);
  cursor: pointer; font-size: 0.68rem; padding: 0;
  line-height: 1; transition: color 0.1s;
}

.sw-tag button:hover { color: var(--red); }

.add-row { display: flex; gap: 5px; }

.add-row input {
  flex: 1; font-family: inherit; font-size: 0.78rem;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r); color: var(--text);
  padding: 5px 9px; outline: none;
}

.add-row input:focus { border-color: var(--border-2); }
.add-row input::placeholder { color: var(--text-3); }

.read-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }

.rcell {
  background: var(--bg-2); border-radius: var(--r);
  padding: 0.55rem 0.7rem; text-align: center;
}

.rcell .rv {
  font-size: 1.05rem; font-weight: 700;
  letter-spacing: -0.03em; color: var(--text);
  font-variant-numeric: tabular-nums;
}

.rcell .rl {
  font-size: 0.6rem; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--text-3);
  font-weight: 600; margin-top: 2px;
}

/* ===== SEO content ===== */
.seo {
  max-width: 960px; margin: 3.5rem auto 0;
  padding: 3rem 1.5rem 0; border-top: 1px solid var(--border);
}

.seo h2 {
  font-size: 1.25rem; font-weight: 700;
  letter-spacing: -0.02em; margin: 2rem 0 0.6rem;
  color: var(--text);
}

.seo h2:first-child { margin-top: 0; }

.seo p {
  font-size: 0.88rem; color: var(--text-2);
  line-height: 1.85; margin-bottom: 0.8rem;
}

details.faq {
  border: 1px solid var(--border); border-radius: var(--r);
  margin-bottom: 7px; overflow: hidden;
}

summary.faq-q {
  padding: 0.72rem 1rem; font-size: 0.87rem; font-weight: 500;
  cursor: pointer; list-style: none;
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); user-select: none; transition: background 0.1s;
}

summary.faq-q:hover { background: var(--bg-2); }
summary.faq-q::after { content: '+'; color: var(--text-3); flex-shrink: 0; }
details[open] summary.faq-q::after { content: '–'; }

.faq-a {
  padding: 0.75rem 1rem 1rem; font-size: 0.84rem;
  color: var(--text-2); line-height: 1.75;
  border-top: 1px solid var(--border); background: var(--bg);
}

/* ===== Footer ===== */
footer {
  border-top: 1px solid var(--border);
  padding: 1.75rem 2rem; text-align: center;
  color: var(--text-3); font-size: 0.77rem; margin-top: 4rem;
}

footer a { color: var(--text-2); text-decoration: none; }
footer a:hover { color: var(--text); }

.footer-links {
  display: flex; justify-content: center;
  gap: 1.25rem; margin-bottom: 0.6rem; flex-wrap: wrap;
}

/* ===== Legal pages ===== */
.legal-page {
  max-width: 720px; margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
}

.legal-page h1 {
  font-size: 1.9rem; font-weight: 700;
  letter-spacing: -0.03em; margin-bottom: 0.4rem;
}

.legal-date {
  font-size: 0.8rem; color: var(--text-3);
  margin-bottom: 2.5rem;
  display: block;
}

.legal-page h2 {
  font-size: 1.1rem; font-weight: 700;
  margin: 2rem 0 0.5rem;
}

.legal-page p, .legal-page li {
  font-size: 0.9rem; color: var(--text-2);
  line-height: 1.8; margin-bottom: 0.75rem;
}

.legal-page ul {
  padding-left: 1.25rem; margin-bottom: 0.75rem;
}

/* ===== Utils ===== */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: var(--ink); color: var(--ink-fg);
  border-radius: var(--r); padding: 8px 15px;
  font-size: 0.78rem; z-index: 9999;
  opacity: 0; transform: translateY(5px);
  transition: all 0.16s; pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }
