/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
    --c-bg:         #ffffff;
    --c-surface:    #f7f8fa;
    --c-border:     #e4e6ea;
    --c-text:       #1a1c1e;
    --c-muted:      #6b7280;
    --c-accent:     #2563eb;
    --c-accent-h:   #1d4ed8;
    --c-active-bg:  #eff6ff;
    --c-active:     #2563eb;
    --c-success:    #16a34a;
    --c-error:      #dc2626;

    --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono:    'SF Mono', 'Fira Code', 'Fira Mono', monospace;

    --radius:       6px;
    --radius-lg:    10px;
    --shadow-sm:    0 1px 3px rgba(0,0,0,.08);
    --shadow:       0 2px 8px rgba(0,0,0,.1);

    --header-h:     52px;
    --nav-w:        220px;
    --adsense-h:    70px;
    --max-content:  780px;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    color: var(--c-text);
    background: var(--c-bg);
    line-height: 1.6;
    padding-bottom: var(--adsense-h);
}
a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }

/* ── Header ─────────────────────────────────────────────────────────────── */
#site-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: var(--c-bg);
    border-bottom: 1px solid var(--c-border);
    z-index: 100;
}
#site-header .header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 1rem;
}
.site-logo {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--c-text);
    letter-spacing: -.02em;
}
.site-logo:hover { text-decoration: none; }

/* hamburger */
.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    padding: 4px;
}
.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--c-text);
    border-radius: 2px;
    transition: transform .2s, opacity .2s;
}
.nav-toggle.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.is-open span:nth-child(2) { opacity: 0; }
.nav-toggle.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Nav ─────────────────────────────────────────────────────────────────── */
#site-nav {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: var(--nav-w);
    overflow-y: auto;
    background: var(--c-surface);
    border-right: 1px solid var(--c-border);
    z-index: 90;
    padding: 1rem 0 2rem;
}
.nav-inner { display: flex; flex-direction: column; gap: .25rem; }

.nav-group { padding: .5rem 0; }
.nav-group-label {
    display: block;
    padding: .25rem 1rem;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--c-muted);
}
.nav-group ul { list-style: none; }
.nav-link {
    display: block;
    padding: .35rem 1rem .35rem 1.1rem;
    font-size: .875rem;
    color: var(--c-text);
    border-left: 3px solid transparent;
    transition: background .15s, border-color .15s;
    line-height: 1.4;
}
.nav-link:hover { background: var(--c-border); text-decoration: none; }
.nav-link.is-active {
    background: var(--c-active-bg);
    border-left-color: var(--c-active);
    color: var(--c-active);
    font-weight: 600;
}

/* ── Main layout ─────────────────────────────────────────────────────────── */
#main-content {
    margin-top: var(--header-h);
    margin-left: var(--nav-w);
    min-height: calc(100vh - var(--header-h) - 48px - var(--adsense-h));
    padding: 2rem 2rem 2.5rem;
}

/* ── Tool page ───────────────────────────────────────────────────────────── */
.tool-page { max-width: var(--max-content); }

.tool-header { margin-bottom: 1.75rem; }
.tool-header h1 { font-size: 1.6rem; font-weight: 700; line-height: 1.2; margin-bottom: .5rem; }
.tool-desc { color: var(--c-muted); font-size: .95rem; max-width: 60ch; }

/* shared tool UI */
.tool-area {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tool-textarea {
    width: 100%;
    min-height: 180px;
    padding: .75rem 1rem;
    font-family: var(--font-mono);
    font-size: .875rem;
    line-height: 1.6;
    color: var(--c-text);
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    resize: vertical;
    transition: border-color .15s;
}
.tool-textarea:focus { outline: none; border-color: var(--c-accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.tool-textarea[readonly] { background: var(--c-surface); cursor: default; }

/* buttons row */
.tool-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .45rem .9rem;
    font-size: .875rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}
.btn-primary { background: var(--c-accent); color: #fff; }
.btn-primary:hover { background: var(--c-accent-h); text-decoration: none; }
.btn-secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border); }
.btn-secondary:hover { background: var(--c-border); text-decoration: none; }
.btn-ghost { background: none; color: var(--c-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--c-surface); color: var(--c-text); text-decoration: none; }

/* options panel */
.tool-options-toggle {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-size: .8rem;
    color: var(--c-muted);
    background: none;
    border: none;
    padding: .2rem .4rem;
    border-radius: var(--radius);
    margin-left: auto;
    transition: color .15s;
}
.tool-options-toggle:hover { color: var(--c-text); background: var(--c-surface); }
.tool-options-toggle .arrow { transition: transform .2s; display: inline-block; }
.tool-options-toggle.is-open .arrow { transform: rotate(180deg); }

.tool-options {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: .75rem 1rem;
    display: none;
    gap: .75rem;
    flex-wrap: wrap;
    align-items: center;
}
.tool-options.is-visible { display: flex; }

.tool-option-item {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .875rem;
    cursor: pointer;
    user-select: none;
}
.tool-option-item input[type=checkbox],
.tool-option-item input[type=radio] { cursor: pointer; }

.tool-option-select {
    font-size: .875rem;
    padding: .3rem .5rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-bg);
    color: var(--c-text);
    cursor: pointer;
}

/* output label */
.output-label {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--c-muted);
    margin-bottom: .25rem;
}

/* status / feedback */
.tool-status {
    font-size: .8rem;
    color: var(--c-muted);
    min-height: 1.2em;
}
.tool-status.ok  { color: var(--c-success); }
.tool-status.err { color: var(--c-error); }

/* stats row (word counter etc.) */
.stat-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
}
.stat-item { display: flex; flex-direction: column; align-items: flex-start; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .75rem; color: var(--c-muted); margin-top: .15rem; }

/* diff specific */
.diff-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.diff-output {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: .75rem 1rem;
    font-family: var(--font-mono);
    font-size: .82rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-all;
    min-height: 180px;
    overflow-y: auto;
}
.diff-add  { background: #dcfce7; color: #15803d; }
.diff-del  { background: #fee2e2; color: #b91c1c; }
.diff-same { color: var(--c-muted); }

/* color preview */
.color-preview {
    width: 100%;
    height: 60px;
    border-radius: var(--radius);
    border: 1px solid var(--c-border);
    margin-top: .5rem;
    transition: background .2s;
}

/* regex highlight */
.regex-highlight mark {
    background: #fef08a;
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

/* ── Home page ───────────────────────────────────────────────────────────── */
.home-hero {
    max-width: 560px;
    margin-bottom: 2.5rem;
}
.home-hero h1 { font-size: 2rem; font-weight: 800; margin-bottom: .4rem; }
.home-tagline { font-size: 1.1rem; color: var(--c-muted); margin-bottom: .75rem; }
.home-intro { font-size: .9rem; color: var(--c-muted); }

.home-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: .75rem;
}
.home-card {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    padding: .9rem 1rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    background: var(--c-surface);
    color: var(--c-text);
    transition: border-color .15s, box-shadow .15s;
}
.home-card:hover {
    border-color: var(--c-accent);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
}
.home-card strong { font-size: .9rem; font-weight: 600; }
.home-card span { font-size: .78rem; color: var(--c-muted); line-height: 1.4; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
#site-footer {
    margin-left: var(--nav-w);
    border-top: 1px solid var(--c-border);
    padding: .75rem 2rem;
    font-size: .8rem;
    color: var(--c-muted);
}
#site-footer .footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
}
.footer-links { display: flex; gap: 1rem; }
.footer-links a { color: var(--c-muted); }
.footer-links a:hover { color: var(--c-text); }

/* ── AdSense fixed bar ───────────────────────────────────────────────────── */
#adsense-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--adsense-h);
    background: var(--c-bg);
    border-top: 1px solid var(--c-border);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
#adsense-bar .adsbygoogle { width: 100%; max-width: 970px; height: 66px; }

/* ── Static pages (imprint / privacy) ───────────────────────────────────── */
.static-page {
    max-width: var(--max-content);
}
.static-page h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}
.static-page h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 1.75rem 0 .5rem;
}
.static-page p {
    margin-bottom: .9rem;
    color: var(--c-text);
    font-size: .95rem;
    line-height: 1.7;
}
.static-page a { color: var(--c-accent); }
.static-page ul {
    margin: .5rem 0 .9rem 1.25rem;
    font-size: .95rem;
    line-height: 1.8;
}
.static-page .legal-block {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    :root { --nav-w: 0px; }

    .nav-toggle { display: flex; }

    #site-nav {
        left: -260px;
        width: 260px;
        transition: left .25s ease;
        box-shadow: none;
    }
    #site-nav.is-open {
        left: 0;
        box-shadow: 4px 0 20px rgba(0,0,0,.12);
    }

    #main-content {
        margin-left: 0;
        padding: 1.25rem 1rem 2rem;
    }
    #site-footer { margin-left: 0; }

    .tool-header h1 { font-size: 1.35rem; }

    .diff-grid { grid-template-columns: 1fr; }

    #adsense-bar { height: 60px; }
    :root { --adsense-h: 60px; }
}

@media (max-width: 480px) {
    .home-grid { grid-template-columns: 1fr 1fr; }
    .stat-row { gap: .75rem; }
}
