/* ==========================================================================
   MHTC MATH & EDUCATION TOOLS - MASTER STYLESHEET
   Design System: Dark Observatory Theme
   Shared across Homepage & All Tool Pages
   ========================================================================== */

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

:root {
    /* DARK OBSERVATORY PALETTE */
    --bg: #0a0e1a;
    --bg-mid: #0f1525;
    --bg-card: rgba(22, 32, 52, 0.6);
    --bg-card-hover: rgba(30, 42, 66, 0.8);
    --bg-card-solid: #162134;
    --bg-glass: rgba(15, 21, 37, 0.7);
    --bg-input: rgba(15, 21, 37, 0.8);

    --text: #f1f5f9;
    --text-body: #cbd5e1;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --text-faint: #475569;

    --amber: #f59e0b;
    --amber-glow: rgba(245, 158, 11, 0.15);
    --amber-soft: rgba(245, 158, 11, 0.08);

    --mint: #10b981;
    --mint-glow: rgba(16, 185, 129, 0.15);
    --mint-soft: rgba(16, 185, 129, 0.08);

    --coral: #f43f5e;
    --coral-glow: rgba(244, 63, 94, 0.15);
    --coral-soft: rgba(244, 63, 94, 0.08);

    --sky: #0ea5e9;
    --sky-glow: rgba(14, 165, 233, 0.15);
    --sky-soft: rgba(14, 165, 233, 0.08);

    --violet: #8b5cf6;
    --violet-glow: rgba(139, 92, 246, 0.15);
    --violet-soft: rgba(139, 92, 246, 0.08);

    --rose: #ec4899;
    --rose-glow: rgba(236, 72, 153, 0.15);
    --rose-soft: rgba(236, 72, 153, 0.08);

    --lime: #84cc16;
    --lime-glow: rgba(132, 204, 22, 0.15);
    --lime-soft: rgba(132, 204, 22, 0.08);

    --orange: #fb923c;
    --orange-glow: rgba(251, 146, 60, 0.15);
    --orange-soft: rgba(251, 146, 60, 0.08);

    --border: rgba(148, 163, 184, 0.12);
    --border-hover: rgba(148, 163, 184, 0.25);
    --border-bright: rgba(148, 163, 184, 0.35);

    --radius: 16px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --shadow-glow: 0 0 40px;
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 12px 48px rgba(0, 0, 0, 0.4);
    --max-width: 1200px;
    --max-width-tool: 900px;

    --font-serif: 'Playfair Display', 'Georgia', serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
}

html {
    scroll-behavior: smooth;
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: hidden !important;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden !important;
    position: relative;
}

/* DOT GRID BACKGROUND */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: radial-gradient(circle, rgba(148, 163, 184, 0.07) 1px, transparent 1px);
    background-size: 28px 28px;
    pointer-events: none;
    z-index: 0;
}

/* AMBIENT GLOW */
body::after {
    content: '';
    position: fixed;
    top: -200px; left: 50%;
    transform: translateX(-50%);
    width: 800px; height: 600px;
    background: radial-gradient(ellipse, rgba(14, 165, 233, 0.05), transparent 70%);
    pointer-events: none;
    z-index: 0;
    filter: blur(60px);
}

a {
    color: inherit;
    text-decoration: none;
}

::selection {
    background: var(--sky-glow);
    color: var(--sky);
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ==========================================================================
   HEADER & NAVIGATION
   ========================================================================== */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10, 14, 26, 0.85);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border);
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
}

.header-inner {
    max-width: var(--max-width) !important;
    margin: 0 auto;
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    position: relative;
    z-index: 1;
    width: 100% !important;
    box-sizing: border-box;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-weight: 900;
    letter-spacing: -0.5px;
    white-space: nowrap;
    color: var(--text);
    flex-shrink: 0;
}

.logo-icon {
    font-size: 1.5rem;
    filter: drop-shadow(0 0 8px var(--sky-glow));
}

.logo .accent {
    color: var(--sky);
    font-style: italic;
}

.header-search {
    flex: 1;
    max-width: 380px;
    position: relative;
}

.header-search input {
    width: 100%;
    padding: 9px 14px 9px 38px;
    background: rgba(22, 32, 52, 0.6);
    border: 1px solid var(--border);
    border-radius: 100px;
    color: var(--text);
    font-size: 0.88rem;
    font-family: var(--font-sans);
    transition: all 0.2s;
}

.header-search input::placeholder { color: var(--text-dim); }

.header-search input:focus {
    outline: none;
    border-color: var(--sky);
    box-shadow: 0 0 0 3px var(--sky-soft);
    background: rgba(22, 32, 52, 0.9);
}

.header-search svg {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    stroke: var(--text-dim);
    fill: none;
    stroke-width: 2;
}

.header-nav { display: flex; gap: 24px; font-size: 0.88rem; flex-shrink: 0; }

.header-nav a {
    color: var(--text-muted);
    transition: color 0.2s;
    font-weight: 500;
    white-space: nowrap;
}

.header-nav a:hover { color: var(--text); }

/* MENU TOGGLE & MOBILE NAV */
.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 24px;
    height: 18px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 101;
}

.menu-toggle span {
    display: block;
    width: 100%;
    height: 2px;
    background-color: var(--text-body);
    border-radius: 2px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.menu-toggle.active span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
    background-color: var(--sky);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
    background-color: var(--sky);
}

.mobile-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(10, 14, 26, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border);
    padding: 24px 28px;
    flex-direction: column;
    gap: 16px;
    z-index: 99;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.mobile-nav.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.mobile-nav a {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-body);
    padding: 10px 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.05);
    transition: color 0.2s, padding-left 0.2s;
}

.mobile-nav a:hover {
    color: var(--sky);
    padding-left: 8px;
}


/* ==========================================================================
   HOMEPAGE SPECIFIC (HERO, CARDS, CATEGORIES, SEARCH, FEATURED)
   ========================================================================== */
.hero {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 80px 28px 56px;
    text-align: center;
    position: relative;
    z-index: 1;
    width: 100% !important;
    box-sizing: border-box;
}

.hero-symbols {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    overflow: hidden;
}

.hero-symbol {
    position: absolute;
    font-family: var(--font-serif);
    font-weight: 700;
    color: var(--text-faint);
    opacity: 0.15;
    user-select: none;
    animation: float 20s infinite ease-in-out;
}

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    33% { transform: translateY(-20px) rotate(5deg); }
    66% { transform: translateY(15px) rotate(-3deg); }
}

.hero-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 28px;
    letter-spacing: 0.3px;
    backdrop-filter: blur(10px);
}

.hero-eyebrow .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--mint);
    box-shadow: 0 0 10px var(--mint-glow);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.hero h1 {
    font-family: var(--font-serif);
    font-size: clamp(2.2rem, 5vw, 4rem);
    font-weight: 900;
    letter-spacing: -1px;
    line-height: 1.1;
    margin-bottom: 24px;
    color: var(--text);
    word-break: break-word;
}

.hero h1 em {
    font-style: italic;
    font-weight: 400;
    background: linear-gradient(135deg, var(--sky), var(--mint));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    color: var(--text-body);
    font-size: 1.1rem;
    max-width: 580px;
    margin: 0 auto 36px;
    line-height: 1.7;
    word-break: break-word;
}

.hero-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    flex-wrap: wrap;
}

.hero-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.hero-stat-num {
    font-family: var(--font-mono);
    font-size: 1.7rem;
    font-weight: 600;
    color: var(--sky);
    letter-spacing: -0.5px;
}

.hero-stat-label {
    font-size: 0.74rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 500;
}

/* SEARCH SECTION */
.search-section {
    max-width: 640px;
    margin: 0 auto 64px;
    padding: 0 28px;
    position: relative;
    z-index: 1;
    width: 100% !important;
    box-sizing: border-box;
}

.search-bar {
    width: 100%;
    padding: 18px 24px 18px 56px;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1.05rem;
    font-family: var(--font-sans);
    transition: all 0.25s;
    backdrop-filter: blur(10px);
}

.search-bar::placeholder { color: var(--text-dim); }

.search-bar:focus {
    outline: none;
    border-color: var(--sky);
    box-shadow: 0 0 0 4px var(--sky-soft), 0 0 30px var(--sky-glow);
}

.search-section > svg {
    position: absolute;
    left: 46px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    stroke: var(--text-dim);
    fill: none;
    stroke-width: 2;
}

.search-hint {
    position: absolute;
    right: 42px;
    top: 50%;
    transform: translateY(-50%);
    padding: 3px 10px;
    background: var(--bg-card-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    font-size: 0.75rem;
    color: var(--text-dim);
    font-family: var(--font-mono);
    pointer-events: none;
}

.search-results-info {
    text-align: center;
    margin-top: 14px;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: none;
}

.search-results-info.visible { display: block; }

/* CATEGORIES */
.categories {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 28px 80px;
    position: relative;
    z-index: 1;
    width: 100% !important;
    box-sizing: border-box;
}

.category {
    margin-bottom: 64px;
    scroll-margin-top: 80px;
}

.category-header {
    display: flex;
    align-items: baseline;
    gap: 14px;
    margin-bottom: 28px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.category-symbol {
    font-family: var(--font-serif);
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xs);
    flex-shrink: 0;
}

.category-header h2 {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text);
}

.category-desc {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-left: 4px;
}

.category-count {
    margin-left: auto;
    font-size: 0.76rem;
    color: var(--text-muted);
    background: var(--bg-card);
    padding: 4px 14px;
    border-radius: 100px;
    border: 1px solid var(--border);
    font-weight: 500;
    font-family: var(--font-mono);
    backdrop-filter: blur(10px);
}

/* TOOL CARDS GRID */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    width: 100%;
}

.tool-card.featured {
    grid-column: span 2;
    grid-row: span 2;
}

.tool-card.wide {
    grid-column: span 2;
}

.tool-card {
    display: flex;
    flex-direction: column;
    padding: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    width: 100% !important;
    box-sizing: border-box;
}

.tool-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--card-accent, var(--sky)), transparent 70%);
    opacity: 0;
    transition: opacity 0.3s;
}

.tool-card::after {
    content: '';
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: radial-gradient(circle at 50% 0%, var(--card-glow, var(--sky-glow)), transparent 50%);
    opacity: 0;
    transition: opacity 0.4s;
    pointer-events: none;
}

.tool-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.tool-card:hover::before { opacity: 1; }
.tool-card:hover::after { opacity: 1; }

.tool-card-top {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    position: relative;
    z-index: 1;
}

.tool-card-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg-soft, var(--sky-soft));
    border-radius: var(--radius-xs);
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--card-accent, var(--sky));
    line-height: 1;
    flex-shrink: 0;
}

.tool-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.2px;
    color: var(--text);
    line-height: 1.3;
    word-break: break-word;
}

.tool-card-desc {
    font-size: 0.83rem;
    color: var(--text-muted);
    line-height: 1.55;
    flex-grow: 1;
    margin-bottom: 14px;
    position: relative;
    z-index: 1;
    word-break: break-word;
}

.tool-card.featured .tool-card-desc {
    font-size: 0.92rem;
    line-height: 1.7;
}

.tool-card.featured .tool-card-title {
    font-size: 1.2rem;
    font-family: var(--font-serif);
    font-weight: 700;
}

.tool-card.featured .tool-card-icon {
    width: 48px;
    height: 48px;
    font-size: 1.4rem;
}

.tool-card-arrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--card-accent, var(--sky));
    text-transform: uppercase;
    letter-spacing: 0.6px;
    position: relative;
    z-index: 1;
}

.tool-card-arrow svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    transition: transform 0.2s;
}

.tool-card:hover .tool-card-arrow svg {
    transform: translateX(4px);
}

.tool-card.hidden { display: none; }

.no-results {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-dim);
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-style: italic;
    display: none;
}

.no-results.visible { display: block; }

/* FEATURED BANNER */
.featured-banner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 28px 64px;
    position: relative;
    z-index: 1;
    width: 100% !important;
    box-sizing: border-box;
}

.featured-inner {
    background: linear-gradient(135deg, rgba(22, 32, 52, 0.8), rgba(15, 21, 37, 0.9));
    border: 1px solid var(--border-bright);
    border-radius: var(--radius);
    padding: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 40px;
    position: relative;
    overflow: hidden;
    width: 100% !important;
    box-sizing: border-box;
}

.featured-inner::before {
    content: '∑';
    position: absolute;
    right: -20px;
    bottom: -40px;
    font-family: var(--font-serif);
    font-size: 18rem;
    font-weight: 900;
    color: var(--sky);
    opacity: 0.04;
    pointer-events: none;
    line-height: 1;
}

.featured-content { flex: 1; position: relative; z-index: 1; }

.featured-label {
    display: inline-block;
    padding: 4px 12px;
    background: var(--sky-glow);
    border: 1px solid var(--sky);
    border-radius: 100px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--sky);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
}

.featured-content h3 {
    font-family: var(--font-serif);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
    letter-spacing: -0.5px;
    word-break: break-word;
}

.featured-content p {
    color: var(--text-body);
    font-size: 0.95rem;
    line-height: 1.7;
    margin-bottom: 20px;
    max-width: 520px;
    word-break: break-word;
}

.featured-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: var(--sky);
    color: var(--bg);
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.featured-link:hover {
    background: #38bdf8;
    transform: translateY(-2px);
    box-shadow: 0 4px 20px var(--sky-glow);
}

/* SEO CONTENT SECTION */
.seo-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 80px 28px;
    position: relative;
    z-index: 1;
    width: 100% !important;
    box-sizing: border-box;
}

.seo-content h2 {
    font-family: var(--font-serif);
    font-size: 1.7rem;
    font-weight: 700;
    margin-bottom: 20px;
    letter-spacing: -0.5px;
    color: var(--text);
    word-break: break-word;
}

.seo-content h3 {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 600;
    margin: 36px 0 14px;
    color: var(--text);
    word-break: break-word;
}

.seo-content p {
    color: var(--text-body);
    margin-bottom: 18px;
    font-size: 0.97rem;
    line-height: 1.85;
    word-break: break-word;
}

.seo-content strong { color: var(--text); font-weight: 600; }

.seo-content a {
    color: var(--sky);
    text-decoration: underline;
    text-decoration-color: var(--sky-soft);
    text-underline-offset: 2px;
}

.seo-content a:hover { text-decoration-color: var(--sky); }

.seo-content ul {
    margin: 14px 0 22px 20px;
    color: var(--text-body);
}

.seo-content li {
    margin-bottom: 10px;
    font-size: 0.94rem;
    line-height: 1.7;
    word-break: break-word;
}

.seo-content code {
    background: var(--sky-soft);
    color: var(--sky);
    padding: 2px 7px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85em;
    word-break: break-all;
}

/* ==========================================================================
   TOOL PAGE SPECIFIC LAYOUT CONTAINERS & BREADCRUMBS
   ========================================================================== */
.container {
    max-width: var(--max-width-tool);
    margin: 0 auto;
    padding: 32px 28px 60px;
    position: relative;
    z-index: 1;
    width: 100% !important;
    box-sizing: border-box;
}

.container-wide {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 32px 28px 60px;
    position: relative;
    z-index: 1;
    width: 100% !important;
    box-sizing: border-box;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-bottom: 24px;
    flex-wrap: wrap;
    word-break: break-word;
}

.breadcrumb a {
    color: var(--text-dim);
    transition: color 0.2s;
}

.breadcrumb a:hover { color: var(--sky); }
.breadcrumb span { color: var(--text-faint); }

/* ==========================================================================
   TOOL BOX & INTERACTIVE WIDGETS
   ========================================================================== */
.tool-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px;
    margin-bottom: 48px;
    box-shadow: var(--shadow-card);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
    width: 100% !important;
    box-sizing: border-box;
}

.tool-header {
    margin-bottom: 28px;
    position: relative;
    z-index: 1;
}

.tool-header h1 {
    font-family: var(--font-serif);
    font-size: clamp(1.4rem, 4.5vw, 2.1rem);
    font-weight: 900;
    letter-spacing: -0.5px;
    line-height: 1.2;
    margin-bottom: 12px;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.tool-header p {
    color: var(--text-muted);
    font-size: 0.98rem;
    line-height: 1.6;
    word-break: break-word;
}

.tool-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.tool-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: var(--bg-card-solid);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: 0.76rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.tool-badge .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* MODE TABS */
.mode-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 4px;
    position: relative;
    z-index: 1;
    flex-wrap: wrap;
    width: 100% !important;
    box-sizing: border-box;
}

.mode-tab {
    flex: 1;
    min-width: 120px;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-sans);
    text-align: center;
}

.mode-tab:hover { color: var(--text); }
.mode-tab.active {
    background: var(--sky);
    color: var(--bg);
    font-weight: 600;
}

/* FRACTION SPECIFIC LAYOUT */
.fraction-input-group {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    background: rgba(22, 32, 52, 0.4);
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    min-height: 120px;
    max-width: 100% !important;
    box-sizing: border-box;
}

.fraction-whole-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.fraction-line-group {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.fraction-divider {
    width: 65px;
    height: 2px;
    background: var(--text-muted);
}

/* INPUT CONTROLS & FORMS */
.calc-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
    width: 100% !important;
    box-sizing: border-box;
}

.calc-text {
    font-size: 1.1rem;
    font-family: var(--font-mono);
    color: var(--text);
    user-select: none;
}

.calc-input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 100%;
}

.calc-input-group label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

.calc-input {
    width: 100px;
    max-width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-size: 1.1rem;
    font-family: var(--font-mono);
    font-weight: 500;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.calc-input:focus {
    outline: none;
    border-color: var(--sky);
    box-shadow: 0 0 0 3px var(--sky-soft);
}

.calc-input::placeholder { color: var(--text-faint); }

.calc-input.whole-input {
    width: 75px;
}

.operator-select {
    width: 80px;
    max-width: 100%;
    padding: 10px 8px;
    font-size: 1.1rem;
    font-family: var(--font-mono);
    border-radius: var(--radius-xs);
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    color: var(--text);
    cursor: pointer;
    text-align: center;
    box-sizing: border-box;
}

.operator-select:focus {
    outline: none;
    border-color: var(--sky);
    box-shadow: 0 0 0 3px var(--sky-soft);
}

.input-area {
    position: relative;
    z-index: 1;
    margin-bottom: 20px;
    width: 100% !important;
    box-sizing: border-box;
}

.input-area label {
    display: block;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
}

.data-textarea {
    width: 100% !important;
    min-height: 120px;
    padding: 16px 20px;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
    font-family: var(--font-mono);
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s;
    line-height: 1.7;
    box-sizing: border-box;
}

.data-textarea:focus {
    outline: none;
    border-color: var(--sky);
    box-shadow: 0 0 0 3px var(--sky-soft);
}

.data-textarea::placeholder { color: var(--text-faint); }

.input-hint {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-top: 8px;
    word-break: break-word;
}

/* RESULT DISPLAYS */
.result-box {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 24px 28px;
    margin-top: 28px;
    position: relative;
    z-index: 1;
    transition: all 0.2s;
    width: 100% !important;
    box-sizing: border-box;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.result-box.has-result {
    border-color: var(--sky);
    box-shadow: 0 0 20px var(--sky-soft);
}

.result-label {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 12px;
}

.result-math {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-mono);
    font-size: clamp(1.3rem, 5vw, 2.2rem);
    color: var(--sky);
    word-break: break-all;
    flex-wrap: wrap;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 16px;
    width: 100% !important;
    box-sizing: border-box;
}

.stat-card {
    background: var(--bg-card-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 16px;
    text-align: center;
    transition: all 0.2s;
    width: 100% !important;
    box-sizing: border-box;
}

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.stat-card .stat-value {
    font-family: var(--font-mono);
    font-size: clamp(1.2rem, 4vw, 1.6rem);
    font-weight: 700;
    color: var(--sky);
    margin-bottom: 4px;
    word-break: break-all;
}

.stat-card .stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    word-break: break-word;
}

.result-steps {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-dim);
    line-height: 1.8;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.result-steps h4 {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-family: var(--font-sans);
    font-weight: 600;
}

.result-steps div {
    margin-bottom: 6px;
    padding-left: 12px;
    border-left: 2px solid var(--border);
    word-break: break-word;
}

.result-empty {
    color: var(--text-faint);
    font-style: italic;
    font-size: 0.95rem;
    font-family: var(--font-sans);
}

.error-message {
    color: var(--coral);
    background: var(--coral-soft);
    border: 1px solid rgba(244, 63, 94, 0.2);
    padding: 12px 18px;
    border-radius: var(--radius-xs);
    margin-top: 20px;
    font-size: 0.9rem;
    display: none;
    align-items: center;
    gap: 8px;
    word-break: break-word;
}

/* BUTTONS */
.tool-buttons {
    display: flex;
    gap: 10px;
    margin-top: 24px;
    justify-content: center;
    position: relative;
    z-index: 1;
    flex-wrap: wrap;
    width: 100% !important;
    box-sizing: border-box;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-sans);
}

.btn-primary {
    background: var(--sky);
    color: var(--bg);
}

.btn-primary:hover {
    background: #38bdf8;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--sky-glow);
}

.btn-secondary {
    background: var(--bg-card-solid);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
}

.btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* ==========================================================================
   ARTICLE & CONTENT TYPOGRAPHY
   ========================================================================== */
.article {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 44px;
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 1;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
    word-break: break-word;
    overflow-x: hidden; /* Prevent article body from spilling */
}

.article h2 {
    font-family: var(--font-serif);
    font-size: clamp(1.3rem, 4vw, 1.6rem);
    font-weight: 700;
    margin: 40px 0 16px;
    letter-spacing: -0.5px;
    color: var(--text);
    scroll-margin-top: 80px;
    word-break: break-word;
}

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

.article h3 {
    font-family: var(--font-sans);
    font-size: 1.1rem;
    font-weight: 600;
    margin: 28px 0 12px;
    color: var(--text);
    word-break: break-word;
}

.article p {
    color: var(--text-body);
    margin-bottom: 16px;
    line-height: 1.8;
    font-size: 0.96rem;
    word-break: break-word;
}

.article p strong { color: var(--text); font-weight: 600; }
.article p em { font-style: italic; color: var(--text); }

.article code {
    background: var(--sky-soft);
    color: var(--sky);
    padding: 2px 7px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85em;
    word-break: break-all;
}

.article pre {
    background: var(--bg-mid);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 20px 24px;
    margin: 16px 0;
    overflow-x: auto !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

.article pre code {
    background: none;
    color: #e4e6eb;
    padding: 0;
    font-size: 0.88rem;
    line-height: 1.7;
    font-family: var(--font-mono);
}

.article blockquote {
    border-left: 4px solid var(--coral);
    background: var(--coral-soft);
    padding: 14px 20px;
    margin: 16px 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    word-break: break-word;
}

.article blockquote p { margin: 0; color: var(--text); }
.article blockquote strong { color: var(--coral); }

/* ROBUST TABLE CONTAINER & CELL WRAPPING */
.article table {
    width: 100% !important;
    max-width: 100% !important;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 0.88rem;
    table-layout: auto;
    box-sizing: border-box;
}

.article th, .article td {
    border: 1px solid var(--border);
    padding: 10px 12px;
    text-align: left;
    white-space: normal !important; /* CRITICAL FIX: allow cell text to wrap */
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
}

.article th {
    background: var(--bg-mid);
    font-weight: 600;
    color: var(--text);
}

.article td { color: var(--text-body); }

.article ul {
    margin: 12px 0 20px 20px;
    color: var(--text-body);
}

.article li {
    margin-bottom: 8px;
    font-size: 0.93rem;
    line-height: 1.65;
    word-break: break-word;
}

.article a {
    color: var(--sky);
    text-decoration: underline;
    text-decoration-color: var(--sky-soft);
    text-underline-offset: 2px;
}

.article a:hover { text-decoration-color: var(--sky); }

.article .toc {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 20px 24px;
    margin-bottom: 32px;
    width: 100% !important;
    box-sizing: border-box;
}

.article .toc-title {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text);
}

.article .toc ol { margin: 0; padding-left: 20px; }
.article .toc li { margin-bottom: 6px; }
.article .toc a { color: var(--text-body); text-decoration: none; word-break: break-word; }
.article .toc a:hover { color: var(--sky); }

.article .meta-block {
    background: var(--bg-mid);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 20px;
    margin-top: 36px;
    word-break: break-all;
    width: 100% !important;
    box-sizing: border-box;
}

.article .meta-block code {
    background: none;
    color: var(--text-body);
    font-size: 0.82rem;
    line-height: 1.8;
    font-family: var(--font-mono);
    white-space: pre-wrap !important;
    word-break: break-all !important;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
footer {
    background: var(--bg-mid);
    border-top: 1px solid var(--border);
    padding: 56px 28px 32px;
    position: relative;
    z-index: 1;
    width: 100% !important;
    box-sizing: border-box;
}

.footer-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 40px;
    width: 100% !important;
    box-sizing: border-box;
}

.footer-brand .logo { margin-bottom: 14px; font-size: 1.2rem; }

.footer-brand p {
    color: var(--text-muted);
    font-size: 0.88rem;
    line-height: 1.7;
    max-width: 280px;
}

.footer-col h4 {
    font-size: 0.76rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-dim);
    margin-bottom: 16px;
}

.footer-col ul { list-style: none; }
.footer-col li { margin-bottom: 10px; }

.footer-col a {
    color: var(--text-body);
    font-size: 0.88rem;
    transition: color 0.2s;
}

.footer-col a:hover { color: var(--sky); }

.footer-bottom {
    max-width: var(--max-width);
    margin: 40px auto 0;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    width: 100% !important;
    box-sizing: border-box;
}

.footer-bottom p {
    color: var(--text-dim);
    font-size: 0.8rem;
}

/* ==========================================================================
   ROBUST RESPONSIVE DESIGN MEDIA QUERIES
   ========================================================================== */
@media (max-width: 1024px) {
    .tool-grid { grid-template-columns: repeat(3, 1fr); }
    .tool-card.featured { grid-column: span 2; grid-row: span 1; }
    .tool-card.wide { grid-column: span 2; }
    .featured-inner { flex-direction: column; text-align: center; padding: 32px; }
    .featured-content p { margin: 0 auto 20px; }
}

@media (max-width: 768px) {
    .header-nav { display: none; }
    .header-search { display: none !important; }
    .menu-toggle { display: flex !important; }
    .mobile-nav { display: flex; }
    .footer-inner { grid-template-columns: 1fr 1fr; }
    .tool-box { padding: 24px 18px; border-radius: var(--radius-sm); }
    .article { padding: 24px 16px; border-radius: var(--radius-sm); }
    
    /* Responsive Table Container on Tablet/Mobile */
    .article table {
        display: block !important;
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        white-space: normal !important;
    }
    
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .tool-grid { grid-template-columns: repeat(2, 1fr); }
    .tool-card.featured, .tool-card.wide { grid-column: span 2; }
    .hero-stats { gap: 24px; }
    .search-hint { display: none; }
}

@media (max-width: 600px) {
    .header-inner { padding: 12px 14px !important; gap: 8px !important; }
    .logo { font-size: 1.2rem !important; }
    .logo-icon { font-size: 1.3rem !important; }

    /* Override inline styles on inputs and grids */
    .calc-input, .base-input, .operator-select, select, input[type="text"], input[type="number"] {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    .base-grid {
        grid-template-columns: 1fr !important;
    }

    .sci-keypad {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 6px !important;
    }
}

@media (max-width: 480px) {
    .header-inner { padding: 10px 12px !important; justify-content: space-between !important; }
    .container, .container-wide { padding: 16px 10px 36px !important; }
    .tool-box { padding: 18px 12px !important; margin-bottom: 24px !important; }
    .tool-header { margin-bottom: 20px !important; }
    .tool-header h1 { font-size: 1.3rem !important; line-height: 1.25 !important; margin-bottom: 8px !important; }
    .tool-header p { font-size: 0.88rem !important; }
    .hero { padding: 36px 10px 24px !important; }
    .hero h1 { font-size: 1.75rem !important; margin-bottom: 16px !important; }
    .hero p { font-size: 0.9rem !important; margin-bottom: 24px !important; }
    .search-section { padding: 0 10px !important; margin-bottom: 32px !important; }
    .search-bar { padding: 12px 16px 12px 40px !important; font-size: 0.9rem !important; }
    .search-section > svg { left: 22px !important; width: 16px !important; height: 16px !important; }
    .categories { padding: 0 10px 36px !important; }
    .footer-inner { grid-template-columns: 1fr !important; gap: 24px !important; text-align: center !important; }
    .footer-brand .logo { justify-content: center !important; }
    .footer-brand p { margin: 0 auto !important; }
    .footer-bottom { flex-direction: column !important; text-align: center !important; align-items: center !important; gap: 6px !important; }
    
    .mode-tabs { flex-direction: column !important; gap: 4px !important; padding: 4px !important; }
    .mode-tab { width: 100% !important; padding: 10px 8px !important; font-size: 0.82rem !important; }
    
    .calc-row { flex-direction: column !important; align-items: stretch !important; gap: 10px !important; }
    .calc-input-group { width: 100% !important; align-items: center !important; }
    .calc-input { width: 100% !important; max-width: 100% !important; text-align: center !important; }
    .calc-text { text-align: center !important; }
    .operator-select { width: 100% !important; }
    
    .tool-buttons { flex-direction: column !important; gap: 8px !important; width: 100% !important; }
    .btn { width: 100% !important; justify-content: center !important; }
    
    .stats-grid { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
    .stat-card { padding: 10px 4px !important; }
    .stat-card .stat-value { font-size: 1.1rem !important; }
    
    .result-box { padding: 14px 10px !important; }
    .result-math { font-size: 1.25rem !important; }
    .result-steps { font-size: 0.76rem !important; padding-top: 12px !important; margin-top: 12px !important; }
    
    .tool-grid { grid-template-columns: 1fr !important; gap: 14px !important; }
    .tool-card.featured, .tool-card.wide { grid-column: span 1 !important; }
    .tool-card { padding: 16px !important; }
    .tool-card-title { font-size: 1.05rem !important; }
    .tool-card.featured .tool-card-title { font-size: 1.15rem !important; }
    
    .seo-content { padding: 32px 10px !important; }
    .featured-banner { padding: 0 10px 28px !important; }
    .featured-inner { padding: 18px 14px !important; text-align: center !important; }
    .hero-symbol { display: none !important; }
    
    .article { padding: 18px 12px !important; }
    .article h2 { font-size: 1.2rem !important; margin: 24px 0 10px !important; }
    .article p, .article li { font-size: 0.88rem !important; line-height: 1.6 !important; }
    .article .toc { padding: 14px 10px !important; }
}

@media (max-width: 380px) {
    .logo { font-size: 1.1rem !important; }
    .stats-grid { grid-template-columns: 1fr !important; }
    .tool-header h1 { font-size: 1.15rem !important; }
}
