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

:root {
    --primary: #5b4cff;
    --primary-hover: #4338ca;
    --primary-soft: #ede9fe;
    --bg: #fafafa;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --border: #e8e8e8;
    --border-hover: #d1d5db;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 2px 8px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
    --shadow-hover: 0 8px 24px rgba(91,76,255,0.08), 0 2px 8px rgba(0,0,0,0.04);
    --max-width: 1280px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-soft: #1e1b4b;
    --bg: #09090b;
    --surface: #18181b;
    --surface-raised: #1f1f23;
    --text: #fafafa;
    --text-muted: #a1a1aa;
    --border: #27272a;
    --border-hover: #3f3f46;
    --shadow: 0 2px 8px rgba(0,0,0,0.2);
    --shadow-hover: 0 8px 24px rgba(129,140,248,0.1), 0 2px 8px rgba(0,0,0,0.2);
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 24px;
}

/* === Header === */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    background: rgba(255,255,255,0.85);
}

[data-theme="dark"] .header {
    background: rgba(24,24,27,0.85);
}

.header .container {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.tagline {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* === Hero === */
.hero {
    text-align: center;
    padding: 56px 0 36px;
}

.hero h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 10px;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--text) 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    color: var(--text-muted);
    font-size: 1.05rem;
    margin-bottom: 28px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.search-box {
    max-width: 420px;
    margin: 0 auto;
}

.search-box input {
    width: 100%;
    padding: 13px 22px;
    border: 1px solid var(--border);
    border-radius: 50px;
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: all 0.2s;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

/* === Tools Grid === */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    padding-bottom: 48px;
}

.tool-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-decoration: none;
    color: var(--text);
    transition: all 0.2s ease;
    display: block;
    position: relative;
    overflow: hidden;
}

.tool-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary);
    opacity: 0;
    transition: opacity 0.2s;
}

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

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

.tool-icon {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 10px;
}

.tool-card h2 {
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.01em;
}

.tool-card p {
    color: var(--text-muted);
    font-size: 0.76rem;
    line-height: 1.4;
}

/* === Ad Slots === */
.ad-slot {
    max-width: var(--max-width);
    margin: 16px auto;
    padding: 0 24px;
}

.ad-placeholder {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.ad-banner .ad-placeholder {
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-mid .ad-placeholder {
    min-height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-sidebar .ad-placeholder {
    min-height: 600px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* === Tool Page Layout === */
.tool-page {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 24px;
    padding: 28px 0;
}

.tool-content {
    min-width: 0;
}

.tool-sidebar {
    position: sticky;
    top: 80px;
    align-self: start;
}

.tool-header {
    margin-bottom: 20px;
}

.tool-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

.tool-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.breadcrumb {
    margin-bottom: 12px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.breadcrumb a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

/* === Form Elements === */
.tool-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 16px;
}

.tool-panel h3 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 14px;
}

label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    margin-bottom: 5px;
    color: var(--text);
}

input[type="text"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: all 0.15s;
    background: var(--surface);
    color: var(--text);
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea {
    resize: vertical;
    min-height: 100px;
    font-family: var(--mono);
    font-size: 0.82rem;
    line-height: 1.5;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 3px rgba(91,76,255,0.2);
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 2px 8px rgba(91,76,255,0.25);
}

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

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

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

/* === Utility === */
.output-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 13px 14px;
    font-family: var(--mono);
    font-size: 0.82rem;
    word-break: break-all;
    min-height: 42px;
    position: relative;
    color: var(--text);
    line-height: 1.5;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 3px 9px;
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

.output-box:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background: var(--primary-hover);
}

.range-group {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.range-group input[type="range"] {
    flex: 1;
    padding: 0;
    border: none;
    height: 4px;
    accent-color: var(--primary);
}

.range-group .range-value {
    min-width: 40px;
    text-align: right;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--mono);
    color: var(--text-muted);
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    border-radius: 4px;
}

.color-preview {
    width: 100%;
    height: 120px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 16px;
}

/* === Toast notification === */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--text);
    color: var(--bg);
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    opacity: 0;
    transform: translateY(8px);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

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

/* === Footer === */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 20px 0;
    margin-top: 48px;
}

.footer .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

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

.footer-links {
    display: flex;
    gap: 16px;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 500;
}

.footer-links a:hover {
    color: var(--primary);
}

/* === Dark Mode Toggle === */
.theme-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    margin-left: auto;
    transition: all 0.15s;
}

.theme-toggle:hover {
    border-color: var(--border-hover);
    background: var(--bg);
}

/* === Dark mode overrides for inline elements === */
[data-theme="dark"] .tool-panel pre {
    background: var(--bg) !important;
    color: var(--text) !important;
}

[data-theme="dark"] #regexHighlight {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text);
}

[data-theme="dark"] .perm-header,
[data-theme="dark"] .perm-label {
    background: var(--bg) !important;
}

[data-theme="dark"] .diff-same {
    color: var(--text-muted) !important;
}

/* === Responsive === */
@media (max-width: 768px) {
    .hero h1 {
        font-size: 1.75rem;
    }

    .hero p {
        font-size: 0.95rem;
    }

    .tools-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .tool-card {
        padding: 14px;
    }

    .tool-page {
        grid-template-columns: 1fr;
    }

    .tool-sidebar {
        position: static;
    }

    .header .container {
        gap: 10px;
    }

    .tagline {
        display: none;
    }

    .footer .container {
        flex-direction: column;
        text-align: center;
    }
}

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