/* ===== Reset & base ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  font-size: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;       /* never allow horizontal scroll on body */
  -webkit-tap-highlight-color: transparent;
}
input, textarea, select, button { font-family: inherit; }
textarea { font-size: 16px; }  /* prevent iOS auto-zoom */
img, svg { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ===== Theme tokens ===== */
:root {
  --bg: #f8f9fc;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --border: #e4e8ef;
  --text: #1d2433;
  --muted: #5b6478;
  --accent: #0d6efd;          /* Bootstrap blue */
  --accent-hover: #0b5ed7;
  --accent-soft: rgba(13, 110, 253, 0.10);
  --accent-strong: #084ec0;
  --danger: #dc3545;
  --danger-soft: rgba(220, 53, 69, 0.10);
  --success: #198754;
  --success-soft: rgba(25, 135, 84, 0.10);
  --warning: #d97706;
  --shadow: 0 1px 1px rgba(20, 30, 50, .03);
  --radius: 12px;
  --radius-sm: 8px;
}
[data-theme="dark"] {
  --bg: #0f1218;
  --surface: #171a21;
  --surface-2: #1d2129;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #98a0b1;
  --accent: #4d9bff;
  --accent-hover: #6cabff;
  --accent-soft: rgba(77, 155, 255, 0.16);
  --accent-strong: #2a87ff;
  --shadow: 0 1px 1px rgba(0,0,0,.3);
}

/* ===== Layout shell ===== */
.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

/* ===== Header ===== */
.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
}
@media (min-width: 600px) { .header-inner { padding: 12px 16px; gap: 12px; } }
.menu-button, .icon-button {
  background: transparent;
  border: none;
  color: var(--muted);
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, color .15s ease;
  flex-shrink: 0;
}
.menu-button:hover, .icon-button:hover { background: var(--surface-2); color: var(--text); }
.menu-button:active, .icon-button:active { background: var(--border); }
.page-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: clamp(.95rem, 2.4vw, 1.35rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-actions { display: flex; align-items: center; gap: 8px; position: relative; }

/* Lang dropdown */
.lang-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 24px rgba(15,23,42,.10);
  padding: 6px;
  display: none;
  min-width: 180px;
  max-height: 60vh;
  overflow-y: auto;
  z-index: 60;
}
.lang-menu.open { display: block; }
[dir="rtl"] .lang-menu { right: auto; left: 0; }
.lang-menu a {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text);
  font-size: .95rem;
}
.lang-menu a:hover { background: var(--surface-2); text-decoration: none; }
.lang-menu a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ===== Sidebar drawer ===== */
.scrim {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(15, 23, 42, .55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 90;
}
.scrim.open { opacity: 1; pointer-events: auto; }
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 86vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform .25s cubic-bezier(.2,.7,.2,1);
  z-index: 100;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}
[dir="rtl"] .sidebar { left: auto; right: 0; border-right: none; border-left: 1px solid var(--border); transform: translateX(100%); }
.sidebar.open { transform: translateX(0); }
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-title { font-weight: 700; margin: 0; font-size: 1.05rem; }
.sidebar-body { padding: 10px; overflow-y: auto; flex: 1; }
.nav-section-title {
  text-transform: uppercase;
  font-size: .7rem;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 12px 10px 6px;
  margin: 0;
}
.nav-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  font-size: .94rem;
  border: 1px solid transparent;
}
.nav-list a:hover { background: var(--surface-2); text-decoration: none; }
.nav-list a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; border-color: transparent; }
.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
}

/* ===== Main ===== */
main {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  flex: 1;
  min-width: 0;
}
@media (max-width: 600px) {
  main { padding: 14px 12px 28px; }
}
@media (max-width: 380px) {
  main { padding: 12px 10px 24px; }
}

/* ===== Cards & UI ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}
@media (max-width: 600px) {
  .card { padding: 14px; border-radius: 10px; }
}
.card + .card { margin-top: 16px; }
.card-padded { padding: 24px; }
.flow > * + * { margin-top: 16px; }
@media (max-width: 600px) {
  .flow > * + * { margin-top: 12px; }
}

/* Stats — single horizontal row, scrolls if overflow, vertical dividers */
.stats {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  overflow-x: auto;
  scrollbar-width: thin;
  margin: -8px -4px;
}
.stat {
  flex: 1 0 auto;
  min-width: 96px;
  text-align: center;
  padding: 14px 14px;
  border-inline-end: 1px solid var(--border);
  background: transparent;
}
.stat:last-child { border-inline-end: none; }
.stat-value {
  font-size: clamp(1.25rem, 2.6vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--text);
  display: block;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: .8rem;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.25;
}
@media (max-width: 480px) {
  .stat { padding: 12px 10px; min-width: 88px; }
  .stat-label { font-size: .75rem; }
}

/* Form controls */
.field { display: flex; flex-direction: column; gap: 6px; }
.label, label { font-size: .9rem; font-weight: 600; color: var(--text); }
.input, .select, .textarea {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 1rem;
  width: 100%;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea {
  min-height: 200px;
  resize: vertical;
  line-height: 1.55;
  font-family: inherit;
}
.textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: .95rem; }
.textarea[readonly], .input[readonly] { background: var(--surface-2); }

/* Textarea wrap = single unified field, textarea on top, action toolbar at bottom */
.textarea-wrap { position: relative; }

.textarea-wrap.has-actions {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
  overflow: hidden;
}
.textarea-wrap.has-actions:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea-wrap.has-actions:has(.textarea[readonly]) {
  background: var(--surface-2);
}

/* The inner textarea inherits look & feel from the wrap */
.textarea-wrap.has-actions .textarea {
  border: none;
  background: transparent;
  border-radius: 0;
  resize: none;
  min-height: auto;
  padding: 14px 16px 8px;
  font-size: 1rem;
}
.textarea-wrap.has-actions .textarea:focus {
  outline: none;
  box-shadow: none;
}
@media (max-width: 480px) {
  .textarea-wrap.has-actions .textarea { padding: 12px 12px 6px; }
}

/* The bottom toolbar */
.textarea-actions {
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  justify-content: flex-end;
  background: transparent;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
@media (max-width: 480px) {
  .textarea-actions { padding: 6px 8px; }
}

/* Pill-style action buttons in the toolbar */
.ta-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.ta-action:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.ta-action:active { transform: scale(.97); }
.ta-action svg { width: 14px; height: 14px; flex-shrink: 0; }
@media (max-width: 380px) {
  .ta-action .ta-label { display: none; }
  .ta-action { padding: 0 10px; }
}

/* Modifier classes from earlier are obsolete (no top-padding needed) — keep no-ops */
.textarea-wrap.actions-1, .textarea-wrap.actions-2 { /* no-op */ }
.range { width: 100%; accent-color: var(--accent); }
.checkbox-row { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.checkbox-row input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: .95rem;
  background: var(--surface-2);
  color: var(--text);
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--border); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { filter: brightness(.92); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: .85rem; }
@media (max-width: 480px) {
  .btn { padding: 9px 14px; font-size: .9rem; }
  .btn-row { gap: 8px; }
}
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon svg { width: 16px; height: 16px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn-row.right { justify-content: flex-end; }

/* Tabs (in-page like keyword density tabs) */
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.subtab {
  background: transparent;
  border: none;
  padding: 8px 14px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-size: .9rem;
  cursor: pointer;
}
@media (max-width: 480px) {
  .subtab { padding: 7px 10px; font-size: .85rem; }
}
.subtab:hover { color: var(--text); }
.subtab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); font-size: .92rem; }
[dir="rtl"] .table th, [dir="rtl"] .table td { text-align: right; }
.table tr:nth-child(even) { background: var(--surface-2); }
.badge { display: inline-block; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 999px; font-size: .8rem; font-weight: 600; }
@media (max-width: 480px) {
  .table th, .table td { padding: 6px 8px; font-size: .85rem; }
}

/* Article block */
.article h2 { margin: 28px 0 10px; font-size: 1.2rem; letter-spacing: -.01em; }
.article h3 { margin: 18px 0 6px; font-size: 1rem; }
.article p { color: var(--muted); margin: 0; }
.article > * + * { margin-top: 6px; }
@media (max-width: 480px) {
  .article h2 { margin: 22px 0 8px; font-size: 1.1rem; }
}

/* Cheat sheet (clean, no nested cards) */
.cheat-block h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 16px 0 8px;
  color: var(--text);
}
.cheat-block h3:first-child { margin-top: 0; }
.cheat-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}
.cheat-list li {
  padding: 8px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .92rem;
}
.cheat-list li:first-child { border-top: none; }

/* Two columns helper */
.cols-2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px) { .cols-2 { grid-template-columns: 1fr 1fr; gap: 16px; } }
.cols-3 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px) { .cols-3 { grid-template-columns: 1fr 1fr; gap: 16px; } }
@media (min-width: 900px) { .cols-3 { grid-template-columns: repeat(3, 1fr); } }

/* Tabs strip (multi-tab character counter) */
.tabs-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 4px 0 6px;
}
.tab-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .88rem;
  font-weight: 600;
  white-space: nowrap;
  max-width: 220px;
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
  flex-shrink: 0;
}
@media (max-width: 480px) {
  .tab-pill { padding: 6px 10px; font-size: .82rem; }
  .tab-pill .pill-name { max-width: 110px; }
}
.tab-pill .pill-name {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
  line-height: 1.3;
}
.tab-pill .pill-count {
  font-size: .72rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
}
.tab-pill:hover { background: var(--surface-2); color: var(--text); border-color: var(--accent); }
.tab-pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.tab-pill.active .pill-count { background: rgba(255,255,255,.2); color: #fff; }
.tab-pill.active:hover { background: var(--accent-hover); }
.tab-close {
  background: transparent;
  border: none;
  color: inherit;
  padding: 0;
  border-radius: 50%;
  opacity: .55;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity .15s, background .15s;
}
.tab-close svg {
  width: 12px;
  height: 12px;
  display: block;
}
.tab-pill:hover .tab-close { opacity: .85; }
.tab-close:hover { opacity: 1 !important; background: rgba(0,0,0,.10); }
.tab-pill.active .tab-close { color: #fff; opacity: .8; }
.tab-pill.active .tab-close:hover { background: rgba(255,255,255,.22); opacity: 1 !important; }
.tab-add {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color .15s, border-color .15s, border-style .15s;
}
.tab-add svg { width: 14px; height: 14px; }
.tab-add:hover { color: var(--accent); border-color: var(--accent); border-style: solid; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 1000;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Footer */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px;
  display: grid;
  gap: 16px;
}
.footer-tools, .footer-static {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: center;
  list-style: none;
  padding: 0;
  margin: 0;
}
.footer-tools a, .footer-static a {
  color: var(--muted);
  font-size: .88rem;
}
.footer-tools a:hover, .footer-static a:hover { color: var(--accent); }
.footer-copy { text-align: center; color: var(--muted); font-size: .85rem; }
@media (max-width: 600px) {
  .footer-inner { padding: 20px 12px; gap: 12px; }
  .footer-tools, .footer-static { gap: 6px 12px; }
  .footer-tools a, .footer-static a { font-size: .82rem; }
}

/* Share section */
.share { padding-top: 24px; margin-top: 32px; border-top: 1px solid var(--border); }
.share h3 { margin: 0 0 14px; font-size: 1.15rem; }
.share-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.share-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .15s, transform .05s;
  flex-shrink: 0;
}
.share-btn:hover { background: var(--surface-2); transform: translateY(-1px); }
.share-btn svg { width: 28px; height: 28px; }
@media (max-width: 480px) {
  .share-btn { width: 40px; height: 40px; }
  .share-btn svg { width: 24px; height: 24px; }
}
.bookmark-tip { color: var(--muted); font-size: .9rem; margin-top: 14px; }
kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem;
}

/* 404 */
.not-found {
  text-align: center;
  padding: 40px 16px;
}
.not-found .code {
  font-size: clamp(4rem, 12vw, 7rem);
  font-weight: 800;
  letter-spacing: -.05em;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent), #ec4899);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 0;
}
.not-found p { color: var(--muted); margin: 12px 0 22px; }
.lang-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  max-width: 600px;
  margin: 24px auto 0;
}
.lang-grid a {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 600;
  font-size: .9rem;
}
.lang-grid a:hover { background: var(--surface-2); border-color: var(--accent); text-decoration: none; }

/* Utility */
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; }
.hide-on-mobile { }
@media (max-width: 600px) { .hide-on-mobile { display: none; } }

/* Sun/moon icon swap */
.theme-icon-sun, .theme-icon-moon { width: 20px; height: 20px; }
[data-theme="dark"] .theme-icon-sun { display: none; }
[data-theme="dark"] .theme-icon-moon { display: block; }
.theme-icon-sun { display: block; }
.theme-icon-moon { display: none; }

/* Diff (text-compare) */
.diff-output {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  background: var(--surface-2);
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  min-height: 80px;
  font-size: .9rem;
}
.diff-add { background: var(--success-soft); color: var(--success); padding: 1px 2px; border-radius: 2px; }
.diff-del { background: var(--danger-soft); color: var(--danger); padding: 1px 2px; border-radius: 2px; text-decoration: line-through; }

/* Fancy text grid + transformation list — vertical card with label on top, preview, then action row */
.fancy-grid, .xform-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.fancy-item, .xform-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  transition: border-color .15s;
}
.fancy-item:hover, .xform-item:hover {
  border-color: var(--accent);
}
.fancy-item .label, .xform-item .label {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.fancy-item .text, .xform-item .text {
  font-size: 1.15rem;
  line-height: 1.4;
  word-break: break-word;
  color: var(--text);
  cursor: pointer;
  user-select: all;
  min-height: 1.4em;
  padding: 4px 0;
}
.fancy-item .text:empty::before, .xform-item .text:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  opacity: .55;
  cursor: default;
}
.fancy-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 2px;
}
.fancy-actions .btn {
  padding: 6px 14px;
  font-size: .82rem;
}

/* Typing test */
.typing-board {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  font-size: 1.4rem;
  line-height: 1.85;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  user-select: none;
  cursor: text;
  min-height: 160px;
  letter-spacing: 0.01em;
  color: var(--muted);
  word-break: break-word;
}
@media (max-width: 600px) {
  .typing-board { padding: 18px 14px; font-size: 1.15rem; line-height: 1.7; min-height: 140px; }
}
.typing-board:focus-within { border-color: var(--accent); }
.typing-board span.correct { color: var(--text); }
.typing-board span.incorrect { color: var(--danger); background: var(--danger-soft); border-radius: 2px; }
.typing-board span.current {
  position: relative;
  color: var(--accent);
}
.typing-board span.current::before {
  content: "";
  position: absolute;
  left: -2px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0; } }

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

/* Hero result (big focal output) */
.hero-output {
  font-size: clamp(1.2rem, 4.5vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.25;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}
@media (max-width: 480px) {
  .hero-output { padding: 16px 12px; }
}

/* Segmented control */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
  flex-wrap: wrap;
  max-width: 100%;
}
.segmented label {
  position: relative;
  margin: 0;
  flex: 1 0 auto;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
  text-align: center;
}
@media (max-width: 480px) {
  .segmented span { padding: 7px 10px; font-size: .85rem; }
}
.segmented input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.segmented label:hover span { color: var(--text); }

/* Strength bar */
.strength-bar {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}
.strength-bar > div {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  transition: background .25s;
}
.strength-bar.s-1 > div:nth-child(1) { background: var(--danger); }
.strength-bar.s-2 > div:nth-child(-n+2) { background: var(--warning); }
.strength-bar.s-3 > div:nth-child(-n+3) { background: var(--accent); }
.strength-bar.s-4 > div { background: var(--success); }

/* Effect chip (strikethrough live previews etc.) */
.effect-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.effect-chip {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: border-color .15s, color .15s, background .15s;
}
@media (max-width: 480px) {
  .effect-chip { padding: 7px 12px; font-size: .88rem; }
}
.effect-chip:hover { border-color: var(--accent); }
.effect-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.effect-chip input { display: none; }

/* Letter pad — tap-to-insert grid (gematria, abjad) */
.letter-pad {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}
.letter-pad button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .05s;
  min-width: 0;
}
.letter-pad button:hover { border-color: var(--accent); background: var(--accent-soft); }
.letter-pad button:active { transform: scale(.96); }
.letter-pad .lp-glyph {
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}
.letter-pad .lp-name {
  font-size: .72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.letter-pad .lp-value {
  font-size: .8rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
@media (max-width: 480px) {
  .letter-pad { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 6px; }
  .letter-pad button { padding: 8px 4px; }
  .letter-pad .lp-glyph { font-size: 1.35rem; }
  .letter-pad .lp-name { font-size: .68rem; }
}

/* <details> styled like a card — used by invisible-character */
details > summary { -webkit-tap-highlight-color: transparent; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary > span:last-child { transform: rotate(180deg); }
details > summary > span:last-child { transition: transform .2s; display: inline-block; }

/* Invisible character grid */
.invis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.invis-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .05s;
  text-align: start;
}
.invis-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.invis-card:active { transform: scale(.98); }
.invis-name { font-weight: 600; color: var(--text); font-size: .92rem; }
.invis-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); font-size: .8rem; }
.invis-action {
  margin-top: 4px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.invis-card.copied .invis-action::after { content: " ✓"; color: var(--success); }

/* Inline input + button group */
.input-group {
  display: flex;
  align-items: stretch;
}
.input-group .input, .input-group .textarea, .input-group .select {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}
.input-group .btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  white-space: nowrap;
}
[dir="rtl"] .input-group .input, [dir="rtl"] .input-group .textarea, [dir="rtl"] .input-group .select {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  border-right: 1px solid var(--border);
  border-left: none;
}
[dir="rtl"] .input-group .btn { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
