/* ============ TOKENS ============ */
:root{
  --bg:#f6f7fb;
  --bg-alt:#ffffff;
  --surface:#ffffff;
  --surface-2:#eef0f6;
  --border:#dde1ec;
  --text:#141826;
  --text-dim:#57607a;
  --text-faint:#8993ad;
  --navy:#0b1220;
  --navy-2:#111a30;
  --accent:#3b5bfd;
  --accent-2:#00c2a8;
  --accent-soft:rgba(59,91,253,.12);
  --danger:#e5484d;
  --ok:#1fb27a;
  --radius:14px;
  --radius-sm:8px;
  --shadow:0 8px 30px rgba(20,24,38,.08);
  --font-display:"Outfit",sans-serif;
  --font-body:"Inter",sans-serif;
  --font-mono:"SFMono-Regular",Consolas,"Liberation Mono",Menlo,monospace;
}
[data-theme="dark"]{
  --bg:#0b1220;
  --bg-alt:#0e1626;
  --surface:#111a30;
  --surface-2:#16203a;
  --border:#233052;
  --text:#eef1fa;
  --text-dim:#a6afca;
  --text-faint:#727e9e;
  --accent:#5b7cff;
  --accent-2:#22d3bd;
  --accent-soft:rgba(91,124,255,.16);
  --shadow:0 8px 30px rgba(0,0,0,.35);
}

*,*::before,*::after{box-sizing:border-box;}
html{scroll-behavior:smooth;}
body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:var(--font-body);
  line-height:1.55;
  overflow-x:hidden;
  transition:background .25s ease,color .25s ease;
}
h1,h2,h3,h4{font-family:var(--font-display);color:var(--text);margin:0 0 .5em;}
p{color:var(--text-dim);}
a{color:inherit;text-decoration:none;}
img{max-width:100%;display:block;}
.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;}
button{font-family:inherit;}

/* ============ HEADER ============ */
.site-header{
  position:sticky;top:0;z-index:100;
  background:color-mix(in srgb, var(--bg-alt) 88%, transparent);
  backdrop-filter:blur(10px);
  border-bottom:1px solid var(--border);
}
.nav-container{
  max-width:1280px;margin:0 auto;padding:0 20px;
  display:flex;align-items:center;justify-content:space-between;
  height:64px;
}
.brand{display:flex;align-items:center;gap:10px;font-family:var(--font-display);font-weight:700;}
.brand-mark{
  background:linear-gradient(135deg,var(--accent),var(--accent-2));
  color:#fff;width:34px;height:34px;border-radius:9px;
  display:flex;align-items:center;justify-content:center;font-size:.75rem;letter-spacing:.5px;
}
.brand-name{font-size:1.05rem;color:var(--text);}
.main-nav ul{display:flex;gap:6px;list-style:none;margin:0;padding:0;}
.nav-link{
  background:none;border:none;color:var(--text-dim);font-size:.92rem;font-weight:500;
  display:flex;align-items:center;gap:5px;padding:10px 12px;border-radius:8px;cursor:pointer;
}
.nav-link:hover{color:var(--text);background:var(--surface-2);}
.has-mega{position:relative;}
.mega-dropdown{
  position:absolute;top:100%;left:0;
  min-width:520px;background:var(--surface);border:1px solid var(--border);
  border-radius:var(--radius);box-shadow:var(--shadow);
  padding:18px;opacity:0;visibility:hidden;transform:translateY(6px);
  transition:opacity .18s ease,transform .18s ease,visibility .18s;
  z-index:50;
}
.mega-dropdown--sm{min-width:260px;}
.has-mega:hover .mega-dropdown,.has-mega:focus-within .mega-dropdown{
  opacity:1;visibility:visible;transform:translateY(4px);
}
.mega-grid{display:grid;grid-template-columns:1fr 1fr;gap:4px 18px;}
.mega-dropdown--sm .mega-grid{grid-template-columns:1fr;}
.mega-grid a{padding:7px 8px;border-radius:6px;color:var(--text-dim);font-size:.88rem;}
.mega-grid a:hover{background:var(--surface-2);color:var(--accent);}
.mega-grid a.active{color:var(--accent);font-weight:600;}
.chev{transition:transform .18s ease;}
.has-mega:hover .chev{transform:rotate(180deg);}

.nav-actions{display:flex;align-items:center;gap:8px;}
.icon-btn{
  background:var(--surface-2);border:1px solid var(--border);color:var(--text-dim);
  width:38px;height:38px;border-radius:9px;display:flex;align-items:center;justify-content:center;cursor:pointer;
}
.icon-btn:hover{color:var(--accent);}
.icon-moon{display:none;}
[data-theme="dark"] .icon-sun{display:none;}
[data-theme="dark"] .icon-moon{display:block;}
.hamburger{display:none;flex-direction:column;justify-content:center;gap:4px;width:38px;height:38px;background:var(--surface-2);border:1px solid var(--border);border-radius:9px;cursor:pointer;}
.hamburger span{width:16px;height:2px;background:var(--text-dim);margin:0 auto;border-radius:2px;}

.mobile-nav{display:none;}

@media (max-width:920px){
  .main-nav{display:none;}
  .hamburger{display:flex;}
  .mobile-nav{
    display:none;flex-direction:column;padding:8px 20px 18px;border-top:1px solid var(--border);
    background:var(--bg-alt);
  }
  .mobile-nav.open{display:flex;}
  .mobile-nav details{border-bottom:1px solid var(--border);padding:10px 0;}
  .mobile-nav summary{cursor:pointer;font-weight:600;color:var(--text);list-style:none;}
  .mobile-nav summary::-webkit-details-marker{display:none;}
  .mobile-links{display:flex;flex-direction:column;gap:2px;margin-top:8px;padding-left:6px;}
  .mobile-links a{padding:8px 6px;color:var(--text-dim);font-size:.9rem;}
  .mobile-top-link{padding:12px 6px;font-weight:600;color:var(--text);}
}

/* ============ BREADCRUMB ============ */
.breadcrumb{max-width:1280px;margin:0 auto;padding:14px 20px 0;}
.breadcrumb ol{display:flex;flex-wrap:wrap;gap:6px;list-style:none;margin:0;padding:0;font-size:.82rem;color:var(--text-faint);}
.breadcrumb li:not(:last-child)::after{content:"/";margin-left:6px;color:var(--text-faint);}
.breadcrumb a:hover{color:var(--accent);}
.breadcrumb li[aria-current]{color:var(--text-dim);}

/* ============ HERO ============ */
.hero{max-width:1280px;margin:0 auto;padding:28px 20px 10px;}
.hero-inner{max-width:760px;}
.eyebrow{
  display:inline-block;font-size:.78rem;font-weight:600;letter-spacing:.06em;text-transform:uppercase;
  color:var(--accent);background:var(--accent-soft);padding:5px 12px;border-radius:100px;margin-bottom:14px;
}
.hero h1{font-size:clamp(1.9rem,4vw,2.7rem);font-weight:700;letter-spacing:-.01em;}
.hero-sub{font-size:1.05rem;max-width:620px;}
.hero-stats{display:flex;gap:28px;margin-top:20px;flex-wrap:wrap;}
.hero-stats div{display:flex;flex-direction:column;}
.hero-stats strong{font-family:var(--font-display);font-size:1.4rem;color:var(--text);}
.hero-stats span{font-size:.78rem;color:var(--text-faint);}

/* ============ TOOL SHELL ============ */
.tool-shell{
  margin-top:26px;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);
  box-shadow:var(--shadow);overflow:hidden;
}
.tool-toolbar{
  display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;
  padding:14px 18px;border-bottom:1px solid var(--border);background:var(--surface-2);
}
.tool-toolbar-left{display:flex;align-items:center;gap:6px;}
#docTitle{
  background:transparent;border:1px solid transparent;color:var(--text);font-family:var(--font-mono);
  font-size:.88rem;padding:6px 8px;border-radius:6px;width:140px;
}
#docTitle:hover,#docTitle:focus{border-color:var(--border);outline:none;background:var(--surface);}
.ext-badge{font-family:var(--font-mono);font-size:.8rem;color:var(--text-faint);}
.tool-toolbar-right{display:flex;gap:8px;flex-wrap:wrap;}
select{
  background:var(--surface);border:1px solid var(--border);color:var(--text-dim);font-size:.85rem;
  padding:7px 10px;border-radius:8px;cursor:pointer;
}

.editor-grid{display:grid;grid-template-columns:1fr 1fr;min-height:440px;}
.pane{display:flex;flex-direction:column;min-width:0;}
.pane-editor{border-right:1px solid var(--border);}
.pane-head{
  display:flex;justify-content:space-between;align-items:center;padding:10px 16px;
  font-size:.78rem;font-weight:600;color:var(--text-faint);text-transform:uppercase;letter-spacing:.04em;
  border-bottom:1px solid var(--border);
}
.char-count{text-transform:none;letter-spacing:0;font-weight:400;}
#latexInput{
  flex:1;resize:none;border:none;outline:none;background:var(--bg-alt);color:var(--text);
  font-family:var(--font-mono);font-size:.88rem;line-height:1.6;padding:16px;min-height:340px;
}
.validation-bar{
  min-height:34px;font-size:.8rem;padding:8px 16px;border-top:1px solid var(--border);
  color:var(--text-faint);
}
.validation-bar.is-error{color:var(--danger);}
.validation-bar.is-ok{color:var(--ok);}

.preview-scroll{flex:1;overflow:auto;background:var(--bg-alt);}
.preview-surface{
  padding:32px;min-height:340px;font-family:"Latin Modern Roman","Georgia",serif;color:#1a1a1a;
  background:#fff;margin:16px;box-shadow:0 2px 14px rgba(0,0,0,.08);max-width:100%;
}
[data-theme="dark"] .preview-surface{box-shadow:0 2px 20px rgba(0,0,0,.5);}
.preview-surface h1,.preview-surface h2,.preview-surface h3{color:#1a1a1a;font-family:inherit;}
.preview-placeholder{color:#9099b3;font-family:var(--font-body);font-style:italic;}
.badge-live{
  font-size:.72rem;padding:3px 9px;border-radius:100px;background:var(--surface-2);color:var(--text-faint);
  text-transform:none;letter-spacing:0;font-weight:600;
}
.badge-live.is-live{background:rgba(31,178,122,.14);color:var(--ok);}

.tool-actions{
  display:flex;align-items:center;gap:14px;padding:16px 18px;border-top:1px solid var(--border);flex-wrap:wrap;
}
.tool-hint{font-size:.8rem;color:var(--text-faint);}

@media (max-width:800px){
  .editor-grid{grid-template-columns:1fr;}
  .pane-editor{border-right:none;border-bottom:1px solid var(--border);}
  #latexInput,.preview-scroll{min-height:280px;}
}

/* ============ BUTTONS ============ */
.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:8px;
  padding:11px 20px;border-radius:9px;font-size:.9rem;font-weight:600;cursor:pointer;border:1px solid transparent;
  transition:transform .12s ease,opacity .12s ease,background .18s;
}
.btn:active{transform:scale(.97);}
.btn-primary{background:linear-gradient(135deg,var(--accent),var(--accent-2));color:#fff;}
.btn-primary:hover{opacity:.92;}
.btn-primary:disabled{opacity:.55;cursor:not-allowed;transform:none;}
.btn-secondary{background:var(--surface-2);color:var(--text);border-color:var(--border);}
.btn-secondary:hover{background:var(--surface);}
.btn-ghost{background:transparent;color:var(--text-dim);border-color:var(--border);}
.btn-ghost:hover{color:var(--text);background:var(--surface-2);}
.btn-spinner{display:none;width:14px;height:14px;border-radius:50%;border:2px solid rgba(255,255,255,.4);border-top-color:#fff;animation:spin .7s linear infinite;}
.is-loading .btn-spinner{display:inline-block;}
.is-loading .btn-label{opacity:.8;}
@keyframes spin{to{transform:rotate(360deg);}}

/* ============ RESULTS ============ */
.results-section{max-width:1280px;margin:40px auto 0;padding:0 20px;scroll-margin-top:80px;}
.results-inner{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:28px;box-shadow:var(--shadow);}
.results-empty p{margin:0;text-align:center;color:var(--text-faint);padding:30px 0;}
.results-head h2{margin-bottom:4px;font-size:1.3rem;}
#resultsMeta{font-size:.85rem;color:var(--text-faint);margin-bottom:18px;}
.results-preview{border:1px solid var(--border);border-radius:10px;overflow:hidden;background:#525659;height:520px;}
.results-preview iframe{width:100%;height:100%;border:none;background:#fff;}
.results-buttons{display:flex;gap:10px;margin-top:18px;flex-wrap:wrap;}

@media (max-width:600px){
  .results-preview{height:380px;}
}

/* ============ STRIP / RANDOM TOOLS ============ */
.strip-section{max-width:1280px;margin:56px auto 0;padding:0 20px;}
.strip-title{font-size:1.05rem;color:var(--text-faint);text-transform:uppercase;letter-spacing:.05em;margin-bottom:14px;}
.strip-scroll{display:flex;gap:10px;overflow-x:auto;padding-bottom:8px;scrollbar-width:thin;}
.chip{
  flex:0 0 auto;padding:9px 16px;border:1px solid var(--border);border-radius:100px;font-size:.83rem;
  color:var(--text-dim);background:var(--surface);white-space:nowrap;
}
.chip:hover{border-color:var(--accent);color:var(--accent);}

/* ============ FEATURES ============ */
.features-section{max-width:1280px;margin:64px auto 0;padding:0 20px;text-align:center;}
.section-sub{max-width:560px;margin:0 auto 36px;}
.features-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:18px;text-align:left;}
.feature-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:24px;}
.feature-icon{font-size:1.5rem;margin-bottom:10px;}
.feature-card h3{font-size:1.02rem;}
.feature-card p{font-size:.88rem;margin:0;}
@media (max-width:900px){.features-grid{grid-template-columns:1fr 1fr;}}
@media (max-width:600px){.features-grid{grid-template-columns:1fr;}}

/* ============ HOW IT WORKS ============ */
.how-section{max-width:1280px;margin:64px auto 0;padding:0 20px;text-align:center;}
.how-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:18px;text-align:left;margin-top:30px;}
.how-step{padding:20px;}
.how-num{
  display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:50%;
  background:var(--accent-soft);color:var(--accent);font-weight:700;font-family:var(--font-display);margin-bottom:12px;
}
.how-step h3{font-size:.98rem;}
.how-step p{font-size:.86rem;margin:0;}
@media (max-width:900px){.how-grid{grid-template-columns:1fr 1fr;}}
@media (max-width:560px){.how-grid{grid-template-columns:1fr;}}

/* ============ CONTENT SECTION ============ */
.content-section{max-width:820px;margin:64px auto 0;padding:0 20px;}
.content-section h2{font-size:1.5rem;}
.content-section p{margin-bottom:1.1em;font-size:.96rem;}
.content-section code{background:var(--surface-2);padding:2px 6px;border-radius:4px;font-family:var(--font-mono);font-size:.85em;}

/* ============ FAQ ============ */
.faq-section{max-width:820px;margin:64px auto 0;padding:0 20px;}
.faq-section h2{text-align:center;margin-bottom:26px;}
.faq-item{border:1px solid var(--border);border-radius:10px;padding:16px 18px;margin-bottom:10px;background:var(--surface);}
.faq-item summary{cursor:pointer;font-weight:600;list-style:none;}
.faq-item summary::-webkit-details-marker{display:none;}
.faq-item summary::after{content:"+";float:right;color:var(--text-faint);}
.faq-item[open] summary::after{content:"−";}
.faq-item p{margin:10px 0 0;font-size:.9rem;}

/* ============ CTA ============ */
.cta-section{
  max-width:1000px;margin:70px auto 0;padding:48px 32px;text-align:center;border-radius:var(--radius);
  background:linear-gradient(135deg,var(--navy),var(--navy-2));color:#fff;
}
.cta-section h2{color:#fff;}
.cta-section p{color:#c6cbe0;margin-bottom:24px;}
.cta-buttons{display:flex;justify-content:center;gap:14px;flex-wrap:wrap;}
.cta-section .btn-secondary{background:rgba(255,255,255,.1);color:#fff;border-color:rgba(255,255,255,.25);}
.cta-section .btn-secondary:hover{background:rgba(255,255,255,.18);}

/* ============ FOOTER ============ */
.site-footer{margin-top:80px;border-top:1px solid var(--border);background:var(--bg-alt);padding:48px 20px 24px;}
.footer-grid{max-width:1280px;margin:0 auto;display:grid;grid-template-columns:1.4fr repeat(5,1fr);gap:24px;}
.footer-col h4{font-size:.82rem;text-transform:uppercase;letter-spacing:.05em;color:var(--text-faint);margin-bottom:12px;}
.footer-col a{display:block;font-size:.85rem;color:var(--text-dim);padding:4px 0;}
.footer-col a:hover{color:var(--accent);}
.footer-brand p{font-size:.85rem;margin-top:10px;}
.footer-bottom{max-width:1280px;margin:32px auto 0;border-top:1px solid var(--border);padding-top:18px;}
.footer-bottom p{font-size:.78rem;color:var(--text-faint);margin:0 0 8px;}
@media (max-width:1000px){.footer-grid{grid-template-columns:1fr 1fr 1fr;}}
@media (max-width:640px){.footer-grid{grid-template-columns:1fr 1fr;}}

/* ============ COOKIE BANNER ============ */
.cookie-banner{
  position:fixed;bottom:16px;left:16px;right:16px;max-width:520px;margin:0 auto;
  background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow);
  padding:18px 20px;display:none;z-index:200;
}
.cookie-banner.show{display:block;}
.cookie-banner p{font-size:.85rem;margin:0 0 12px;}
.cookie-actions{display:flex;gap:10px;justify-content:flex-end;}

/* ============ MISC ============ */
::selection{background:var(--accent-soft);}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px;}
@media (prefers-reduced-motion:reduce){*{animation:none !important;transition:none !important;}}
