/* ============================================
   TextHelper AI — Design System
   Modern, AI-tool aesthetic. Indigo + accent.
   ============================================ */

:root {
  /* Brand */
  --indigo-50:  #eef2ff;
  --indigo-100: #e0e7ff;
  --indigo-200: #c7d2fe;
  --indigo-400: #818cf8;
  --indigo-500: #6366f1;
  --indigo-600: #4f46e5;
  --indigo-700: #4338ca;
  --indigo-800: #3730a3;

  --violet-500: #8b5cf6;
  --violet-600: #7c3aed;
  --emerald-500: #10b981;
  --rose-500:    #f43f5e;
  --amber-500:   #f59e0b;

  /* Ink */
  --ink-950: #0a0a0f;
  --ink-900: #111118;
  --ink-800: #1c1c25;
  --ink-700: #2a2a36;
  --ink-600: #44444f;
  --ink-500: #6b6b78;
  --ink-400: #9a9aab;
  --ink-300: #c2c2ce;
  --ink-200: #e5e5eb;
  --ink-100: #f4f4f7;
  --ink-50:  #fafafb;

  --bg:        #ffffff;
  --bg-soft:   #fafafb;
  --bg-muted:  #f4f4f7;
  --text:      var(--ink-900);
  --text-soft: var(--ink-500);
  --border:    #e8e8ed;

  /* Fonts */
  --font-display: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-sans:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Layout */
  --container:    1240px;
  --container-sm: 880px;
  --radius-sm:    8px;
  --radius:       14px;
  --radius-lg:    22px;
  --radius-xl:    28px;

  /* Motion */
  --ease: cubic-bezier(.2,.8,.2,1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0 0 0.5em;
  color: var(--text);
}
h1 { font-size: clamp(2.2rem, 5vw, 4rem); letter-spacing: -0.03em; }
h2 { font-size: clamp(1.7rem, 3.2vw, 2.6rem); }
h3 { font-size: clamp(1.2rem, 2vw, 1.5rem); font-weight: 600; }
h4 { font-size: 1.05rem; font-weight: 600; }
p  { margin: 0 0 1em; color: var(--ink-700); }
p.lead { font-size: clamp(1.05rem, 1.4vw, 1.25rem); color: var(--ink-600); max-width: 680px; }

.eyebrow {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--indigo-600);
  background: var(--indigo-50);
  padding: 6px 12px;
  border-radius: 999px;
  margin-bottom: 1.25rem;
}

.gradient-text {
  background: linear-gradient(120deg, var(--indigo-600), var(--violet-500));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 24px;
}
.container-sm { max-width: var(--container-sm); margin: 0 auto; padding: 0 24px; }
section { padding: clamp(60px, 8vw, 110px) 0; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
  gap: 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--ink-900);
}
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--indigo-500), var(--violet-600));
  display: grid; place-items: center;
  color: white;
  font-weight: 800;
  font-size: 0.95rem;
  box-shadow: 0 6px 16px -4px rgba(99, 102, 241, 0.4);
}
.brand-mark::before {
  content: "Tt";
  font-family: var(--font-display);
}

.nav-links {
  display: flex;
  gap: 28px;
  align-items: center;
}
.nav-links a {
  font-size: 0.93rem;
  font-weight: 500;
  color: var(--ink-700);
  transition: color 0.2s var(--ease);
}
.nav-links a:hover, .nav-links a.active { color: var(--indigo-600); }

.nav-actions { display: flex; align-items: center; gap: 14px; }

/* Language switcher */
.lang-switch {
  position: relative;
}
.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-700);
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.lang-toggle:hover { border-color: var(--indigo-200); background: var(--indigo-50); }
.lang-toggle svg { width: 14px; height: 14px; }
.lang-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  min-width: 160px;
  box-shadow: 0 12px 32px -8px rgba(0,0,0,0.12);
  display: none;
  z-index: 60;
}
.lang-switch.open .lang-menu { display: block; }
.lang-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink-700);
}
.lang-menu a:hover { background: var(--indigo-50); color: var(--indigo-700); }
.lang-menu a.current { background: var(--indigo-50); color: var(--indigo-700); }
.flag {
  width: 18px; height: 13px;
  border-radius: 2px;
  background-size: cover;
  background-position: center;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.06);
}
.flag-uk { background: linear-gradient(to bottom, #005BBB 50%, #FFD500 50%); }
.flag-ru { background: linear-gradient(to bottom, #fff 33%, #0039A6 33% 66%, #D52B1E 66%); }
.flag-pl { background: linear-gradient(to bottom, #fff 50%, #DC143C 50%); }
.flag-en { background: linear-gradient(135deg, #012169 25%, #fff 25% 35%, #C8102E 35% 45%, #fff 45% 55%, #012169 55%); }
.flag-de { background: linear-gradient(to bottom, #000 33%, #DD0000 33% 66%, #FFCE00 66%); }

.menu-toggle {
  display: none;
  background: none;
  border: 0;
  width: 40px; height: 40px;
  padding: 0;
  color: var(--ink-800);
}
.menu-toggle svg { width: 22px; height: 22px; margin: 0 auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 500;
  font-size: 0.95rem;
  border: 0;
  transition: transform 0.2s var(--ease), background 0.2s var(--ease), box-shadow 0.2s var(--ease);
  white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(120deg, var(--indigo-600), var(--violet-600));
  color: white;
  box-shadow: 0 10px 24px -8px rgba(99,102,241,0.5);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 28px -8px rgba(99,102,241,0.6); }
.btn-secondary {
  background: var(--bg);
  color: var(--ink-900);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { border-color: var(--indigo-400); color: var(--indigo-700); }
.btn-ghost {
  background: var(--indigo-50);
  color: var(--indigo-700);
}
.btn-ghost:hover { background: var(--indigo-100); }

/* ---------- Hero ---------- */
.hero {
  padding: clamp(60px, 8vw, 110px) 0 clamp(50px, 6vw, 80px);
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at top, rgba(99,102,241,0.08), transparent 60%),
    radial-gradient(ellipse at 80% 30%, rgba(139,92,246,0.06), transparent 50%);
  pointer-events: none;
}
.hero > .container { position: relative; }
.hero h1 { max-width: 920px; margin-left: auto; margin-right: auto; }
.hero .lead { margin-left: auto; margin-right: auto; margin-top: 1.25rem; }
.hero-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-top: 2.2rem;
  flex-wrap: wrap;
}

/* ---------- Tools grid ---------- */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-top: 56px;
}
@media (max-width: 980px) { .tools-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 580px) { .tools-grid { grid-template-columns: 1fr; } }

.tool-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 26px;
  transition: transform 0.25s var(--ease), border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
  position: relative;
  overflow: hidden;
}
.tool-card:hover {
  transform: translateY(-3px);
  border-color: var(--indigo-200);
  box-shadow: 0 18px 38px -18px rgba(99,102,241,0.3);
}
.tool-card .icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--indigo-50), var(--indigo-100));
  display: grid; place-items: center;
  margin-bottom: 18px;
  transition: background 0.25s var(--ease);
}
.tool-card:hover .icon { background: linear-gradient(135deg, var(--indigo-100), var(--indigo-200)); }
.tool-card .icon svg { width: 24px; height: 24px; color: var(--indigo-600); }
.tool-card h3 {
  font-size: 1.15rem;
  margin-bottom: 6px;
}
.tool-card p {
  font-size: 0.92rem;
  color: var(--ink-500);
  margin: 0;
}
.tool-card .badge {
  position: absolute;
  top: 18px; right: 18px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--violet-600);
  color: white;
}

/* ---------- Tool workbench (interactive page) ---------- */
.tool-page {
  padding: 56px 0 80px;
}
.tool-header { text-align: center; margin-bottom: 40px; }
.tool-header h1 { font-size: clamp(2rem, 4vw, 3rem); margin-bottom: 16px; }
.tool-header p { max-width: 640px; margin: 0 auto; color: var(--ink-500); }

.workbench {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px;
  box-shadow: 0 20px 50px -25px rgba(15,15,40,0.15);
}
.workbench-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 28px;
  align-items: start;
}
@media (max-width: 900px) {
  .workbench-grid { grid-template-columns: 1fr; }
}

.text-area {
  width: 100%;
  min-height: 320px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  font: inherit;
  font-size: 1rem;
  line-height: 1.65;
  resize: vertical;
  background: var(--bg-soft);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.text-area:focus {
  outline: none;
  border-color: var(--indigo-400);
  box-shadow: 0 0 0 4px var(--indigo-100);
  background: var(--bg);
}

.stats-panel {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
}
.stat-row:last-child { border-bottom: 0; padding-bottom: 0; }
.stat-row .label {
  font-size: 0.85rem;
  color: var(--ink-500);
  font-weight: 500;
}
.stat-row .value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--indigo-700);
}

.tool-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}
.tool-actions .btn { font-size: 0.9rem; padding: 10px 18px; }

/* Generator panel (password) */
.gen-output {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--ink-900);
  color: white;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  word-break: break-all;
  min-height: 60px;
}
.gen-output button {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  margin-left: auto;
  white-space: nowrap;
}
.gen-output button:hover { background: rgba(255,255,255,0.1); }

.controls { display: grid; gap: 18px; margin-top: 20px; }
.control-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.control-row label { font-weight: 500; color: var(--ink-700); font-size: 0.95rem; }
.control-row .range-wrap { display: flex; align-items: center; gap: 12px; flex: 1; max-width: 320px; }
input[type="range"] {
  flex: 1;
  accent-color: var(--indigo-600);
}
input[type="number"] {
  width: 60px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  color: var(--ink-700);
  cursor: pointer;
  user-select: none;
}
.checkbox input { width: 18px; height: 18px; accent-color: var(--indigo-600); }

.strength-bar {
  height: 6px;
  background: var(--ink-200);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 12px;
}
.strength-bar > div {
  height: 100%;
  width: 0%;
  background: var(--rose-500);
  transition: width 0.3s var(--ease), background 0.3s var(--ease);
  border-radius: 3px;
}

/* ---------- Section copy ---------- */
.section-intro { text-align: center; max-width: 720px; margin: 0 auto 56px; }
.section-intro h2 { margin-bottom: 14px; }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}
@media (max-width: 900px) { .feature-grid { grid-template-columns: 1fr; } }
.feature {
  padding: 22px;
}
.feature .ico {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--indigo-50);
  color: var(--indigo-600);
  display: grid; place-items: center;
  margin-bottom: 14px;
}
.feature .ico svg { width: 22px; height: 22px; }
.feature h3 { font-size: 1.05rem; margin-bottom: 6px; }
.feature p { font-size: 0.93rem; color: var(--ink-500); margin: 0; }

/* ---------- CTA Strip ---------- */
.cta-strip {
  background: linear-gradient(120deg, var(--indigo-700), var(--violet-700, var(--violet-600)));
  color: white;
  border-radius: var(--radius-lg);
  padding: clamp(40px, 6vw, 72px);
  text-align: center;
  position: relative;
  overflow: hidden;
}
.cta-strip::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 0%, rgba(255,255,255,0.15), transparent 50%);
  pointer-events: none;
}
.cta-strip h2 { color: white; position: relative; }
.cta-strip p { color: rgba(255,255,255,0.85); margin-bottom: 24px; position: relative; max-width: 560px; margin-left: auto; margin-right: auto; }
.cta-strip .btn { position: relative; background: white; color: var(--indigo-700); }
.cta-strip .btn:hover { background: var(--indigo-50); }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--ink-950);
  color: var(--ink-300);
  padding: 72px 0 28px;
  margin-top: 60px;
}
.footer-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr 1fr 0.8fr;
  gap: 32px;
  margin-bottom: 40px;
}
@media (max-width: 1100px) { .footer-grid { grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 28px; } }
@media (max-width: 900px) { .footer-grid { grid-template-columns: 1fr 1fr; gap: 24px; } }
@media (max-width: 600px) {
  .site-footer { padding: 32px 0 16px !important; margin-top: 30px !important; }
  .footer-grid { grid-template-columns: 1fr; gap: 18px; margin-bottom: 24px !important; }
  .footer-brand p { font-size: .85rem !important; }
  .footer-grid h4 { font-size: .75rem !important; margin-bottom: 12px !important; letter-spacing: .12em !important; }
  .footer-grid li { margin-bottom: 7px !important; }
  .footer-grid a { font-size: .87rem !important; }
  /* Make sections collapsible-style: shorter visual height */
  .footer-grid > div:not(.footer-brand) { padding-top: 4px; }
  .footer-bottom { padding-top: 18px !important; font-size: .78rem !important; }
}
.footer-brand p { color: var(--ink-400); font-size: 0.92rem; max-width: 320px; }
.footer-brand .brand { color: white; margin-bottom: 16px; }
.footer-grid h4 {
  color: white;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 18px;
}
.footer-grid ul { list-style: none; padding: 0; margin: 0; }
.footer-grid li { margin-bottom: 10px; }
.footer-grid a {
  color: var(--ink-400);
  font-size: 0.92rem;
  transition: color 0.2s var(--ease);
}
.footer-grid a:hover { color: white; }
.footer-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 26px;
  border-top: 1px solid rgba(255,255,255,0.07);
  font-size: 0.85rem;
  color: var(--ink-500);
  flex-wrap: wrap;
  gap: 12px;
}

/* ---------- Misc ---------- */
.fade-in { opacity: 0; transform: translateY(14px); transition: opacity 0.6s var(--ease), transform 0.6s var(--ease); }
.fade-in.visible { opacity: 1; transform: translateY(0); }

.muted { color: var(--ink-500); }
.hidden { display: none !important; }

:focus-visible {
  outline: 3px solid var(--indigo-400);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Tablet/Mobile nav */
@media (max-width: 880px) {
  .nav-links {
    display: none;
    position: absolute;
    top: 68px; left: 0; right: 0;
    flex-direction: column;
    gap: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px 20px;
    box-shadow: 0 20px 30px -16px rgba(0,0,0,0.1);
  }
  .nav-links.open { display: flex; }
  .nav-links a { width: 100%; padding: 12px 0; border-bottom: 1px solid var(--border); }
  .nav-links a:last-child { border-bottom: 0; }
  .menu-toggle { display: grid; place-items: center; }
}

/* ============================================
   New Header v2 — chip-nav + flag circles
   ============================================ */

.header-v2 {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.header-v2 .container {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding-top: 14px;
  padding-bottom: 0;
}

/* Brand row */
.brand-row {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}
.brand-row .brand {
  font-size: 1.25rem;
}

/* Chip nav — flat horizontal scrolling chips */
.chip-nav {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
  max-width: 100%;
}
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-700);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s var(--ease);
  white-space: nowrap;
}
.chip:hover {
  border-color: var(--indigo-300);
  color: var(--indigo-700);
  background: var(--indigo-50);
}
.chip.primary {
  background: var(--indigo-600);
  color: white;
  border-color: var(--indigo-600);
  box-shadow: 0 4px 10px -4px rgba(99, 102, 241, 0.4);
}
.chip.primary:hover {
  background: var(--indigo-700);
  border-color: var(--indigo-700);
  color: white;
}
.chip svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}
.chip .badge-sm {
  margin-left: 2px;
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--violet-600);
  color: white;
  font-weight: 700;
}
.chip.primary .badge-sm {
  background: white;
  color: var(--indigo-700);
}

/* Mega-menu dropdown */
.chip-dropdown {
  position: relative;
}
.chip-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  min-width: 280px;
  box-shadow: 0 20px 50px -20px rgba(15,15,40,0.25);
  display: none;
  z-index: 60;
}
.chip-dropdown.open .chip-menu {
  display: block;
  animation: chipMenuIn 0.18s var(--ease) forwards;
}
@keyframes chipMenuIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.chip-menu a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.93rem;
  font-weight: 500;
  color: var(--ink-700);
  text-decoration: none;
  transition: background 0.15s var(--ease);
}
.chip-menu a:hover { background: var(--indigo-50); color: var(--indigo-700); }
.chip-menu .chip-menu-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--indigo-50);
  color: var(--indigo-600);
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.chip-menu .chip-menu-icon svg { width: 16px; height: 16px; }
.chip-menu .badge-sm {
  margin-left: auto;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--violet-600);
  color: white;
  font-weight: 700;
}

/* Flag row */
.flag-row {
  display: flex;
  gap: 18px;
  justify-content: center;
  align-items: flex-start;
  padding: 14px 0 18px;
  border-top: 1px solid var(--ink-100);
  overflow-x: auto;
  scrollbar-width: none;
}
.flag-row::-webkit-scrollbar { display: none; }
.flag-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  flex: 0 0 auto;
  transition: transform 0.2s var(--ease);
}
.flag-item:hover { transform: translateY(-2px); }
.flag-circle {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  background-size: cover;
  background-position: center;
}
.flag-item.active .flag-circle::before {
  content: "";
  position: absolute;
  inset: -4px;
  border: 2px solid var(--indigo-600);
  border-radius: 50%;
}
.flag-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-500);
}
.flag-item.active .flag-label { color: var(--indigo-700); }

/* Flag designs (CSS-based) */
.flag-circle.fc-uk { background: linear-gradient(to bottom, #005BBB 50%, #FFD500 50%); }
.flag-circle.fc-ru { background: linear-gradient(to bottom, #fff 33%, #0039A6 33% 66%, #D52B1E 66%); }
.flag-circle.fc-pl { background: linear-gradient(to bottom, #fff 50%, #DC143C 50%); }
.flag-circle.fc-en {
  background: #012169;
}
.flag-circle.fc-en::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, transparent 45%, #fff 45%, #fff 55%, transparent 55%),
    linear-gradient(to right, transparent 45%, #fff 45%, #fff 55%, transparent 55%),
    linear-gradient(to bottom, transparent 47%, #C8102E 47%, #C8102E 53%, transparent 53%),
    linear-gradient(to right, transparent 47%, #C8102E 47%, #C8102E 53%, transparent 53%);
}
.flag-circle.fc-de { background: linear-gradient(to bottom, #000 33%, #DD0000 33% 66%, #FFCE00 66%); }
.flag-circle.fc-es { background: linear-gradient(to bottom, #C60B1E 25%, #FFC400 25% 75%, #C60B1E 75%); }
.flag-circle.fc-fr { background: linear-gradient(to right, #002395 33%, #fff 33% 66%, #ED2939 66%); }
.flag-circle.fc-it { background: linear-gradient(to right, #009246 33%, #fff 33% 66%, #CE2B37 66%); }
.flag-circle.fc-pt { background: linear-gradient(to right, #006600 40%, #FF0000 40%); }
.flag-circle.fc-tr { background: #E30A17; position: relative; }
.flag-circle.fc-tr::after {
  content: "☪";
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 18px;
  line-height: 1;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  /* CRITICAL: remove backdrop-filter on mobile — it creates a stacking context
     that traps position:fixed children (chip-menu) inside the header. */
  .header-v2 {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: var(--bg) !important;
  }
  .header-v2 .container {
    padding-top: 12px;
    padding-left: 16px;
    padding-right: 16px;
  }
  .brand-row { margin-bottom: 10px; }
  .brand-row .brand { font-size: 1.1rem; }
  .brand-row .brand-mark { width: 28px; height: 28px; }

  /* Chip-nav scrolls horizontally on mobile */
  .chip-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    padding: 2px 16px 6px;
    margin: 0 -16px 8px;
    scrollbar-width: none;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
  }
  .chip-nav::-webkit-scrollbar { display: none; }
  /* Bigger touch targets on mobile (44px+ tall) */
  .chip {
    padding: 9px 13px;
    font-size: 0.85rem;
    min-height: 38px;
  }
  .chip svg { width: 15px; height: 15px; }

  /* Mega-menu becomes bottom-sheet on mobile — works for both nested (rare)
     and portaled (default on mobile, moved to body by JS) menu. */
  body > .chip-menu,
  .chip-menu {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    transform: translateY(100%) !important;
    min-width: 0;
    border-radius: 18px 18px 0 0;
    padding: 16px 14px calc(24px + env(safe-area-inset-bottom, 0px));
    max-height: 75vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    box-shadow: 0 -16px 48px -16px rgba(15,15,40,0.35);
    z-index: 200 !important;
    transition: transform 0.28s var(--ease);
    display: none !important;
    background: var(--bg);
  }
  body > .chip-menu.open,
  .chip-dropdown.open > .chip-menu {
    display: block !important;
    transform: translateY(0) !important;
  }
  .chip-menu::before {
    content: "";
    display: block;
    width: 44px;
    height: 4px;
    background: var(--ink-200);
    border-radius: 999px;
    margin: 0 auto 14px;
  }
  .chip-menu a {
    padding: 14px 12px;
    font-size: 1rem;
    min-height: 56px;
  }
  .chip-menu .chip-menu-icon { width: 36px; height: 36px; }
  /* Mobile-only backdrop when sheet open */
  .chip-backdrop {
    display: block !important;
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 40, 0.5);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
  }
  .chip-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }
  body.menu-open { overflow: hidden; }

  /* Flag row — bigger circles, easier to tap */
  .flag-row {
    gap: 16px;
    padding: 12px 16px 16px;
    margin: 0 -16px;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
  }
  .flag-circle { width: 40px; height: 40px; }
  .flag-item.active .flag-circle::before { inset: -3px; }
  .flag-label { font-size: 0.7rem; margin-top: 2px; }

  /* Compact tool page on mobile */
  .tool-page { padding: 40px 0 60px !important; }
  .tool-header { margin-bottom: 24px !important; }
  .tool-header h1 { font-size: clamp(1.6rem, 6vw, 2rem) !important; margin-bottom: 10px !important; }
  .tool-header p { font-size: .95rem !important; padding: 0 8px; }

  /* Compact workbench (the card around the textarea) */
  .workbench {
    padding: 16px !important;
    border-radius: 16px !important;
    box-shadow: 0 8px 24px -12px rgba(15,15,40,0.12) !important;
  }
  .workbench-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  /* Compact textarea — much shorter on mobile */
  .text-area {
    min-height: 160px !important;
    padding: 12px 14px !important;
    font-size: .95rem !important;
    line-height: 1.5 !important;
    border-radius: 12px !important;
  }
  /* Override inline min-height from paraphraser etc. */
  [class*="text-area"][style*="min-height"] {
    min-height: 160px !important;
  }

  /* Compact buttons inside tools */
  .btn { padding: 10px 18px !important; font-size: .95rem !important; }

  /* Stats card on word counter compact */
  .stats-grid { gap: 8px !important; }
  .stat-card { padding: 10px 12px !important; }
  .stat-card .v { font-size: 1.4rem !important; }
  .stat-card .k { font-size: .72rem !important; }
}

/* Very narrow phones (≤380px) — compact further */
@media (max-width: 380px) {
  .chip { padding: 9px 12px; font-size: 0.83rem; }
  .flag-circle { width: 38px; height: 38px; }
  .flag-row { gap: 14px; }
}

/* Backdrop — hidden on desktop, used as dimming layer on mobile (see @media below) */
.chip-backdrop { display: none; }

/* ============================================
   Calculator mobile shrink + responsive
   ============================================ */
@media (max-width: 600px) {
  /* Simple calculator */
  .calc-display { padding: 18px 16px !important; min-height: 80px !important; font-size: 2rem !important; }
  .calc-history { font-size: .85rem !important; }
  .calc-keys { gap: 6px !important; margin-top: 12px !important; }
  .key { padding: 14px 8px !important; font-size: 1.05rem !important; }

  /* Online calculator */
  .expr-input { padding: 14px 16px !important; font-size: 1.1rem !important; }
  .expr-result { padding: 18px !important; margin-top: 12px !important; }
  .expr-result .v { font-size: 1.8rem !important; }
  .ex-chip { padding: 5px 10px !important; font-size: .78rem !important; }

  /* Percentage / VAT — calc rows */
  .calc-row { flex-direction: column !important; gap: 10px !important; }
  .calc-field input { font-size: 1rem !important; padding: 12px 14px !important; }
  .calc-result { padding: 14px !important; }
  .calc-result .value { font-size: 1.5rem !important; }
  .op { font-size: 1rem !important; padding: 4px 0 !important; }

  /* VAT grid */
  .vat-grid { grid-template-columns: 1fr !important; gap: 10px !important; }

  /* Tool header inside calc pages */
  .tool-header h1 { font-size: clamp(1.4rem, 6vw, 1.9rem) !important; }
  .tool-header p { font-size: 0.95rem !important; }
  .workbench { padding: 14px !important; }
  .tool-page .container { padding-left: 14px !important; padding-right: 14px !important; }
}

