/* ── Theme Variables ── */
[data-theme="light"] {
    --bg:             #f5f7fa;
    --surface:        #ffffff;
    --border:         #d1d9e0;
    --text-primary:   #1a1f2e;
    --text-secondary: #4a5568;
    --text-muted:     #5a6478;
    --accent:         #2563eb;
    --accent-hover:   #1d4ed8;
    --accent-text:    #ffffff;
    --btn-bg:         #2563eb;
    --btn-hover:      #1d4ed8;
    --response-bg:    #eef2ff;
    --response-border:#c7d2fe;
    --response-text:  #1e3a8a;
    --shadow:         0 2px 8px rgba(0,0,0,0.08);
    --toggle-bg:      #e2e8f0;
    --toggle-text:    #4a5568;
}

[data-theme="dark"] {
    --bg:             #0f1117;
    --surface:        #1a1d2e;
    --border:         #2d3148;
    --text-primary:   #e8eaf0;
    --text-secondary: #a0aec0;
    --text-muted:     #718096;
    --accent:         #60a5fa;
    --accent-hover:   #93c5fd;
    --accent-text:    #0f1117;
    --btn-bg:         #3b82f6;
    --btn-hover:      #60a5fa;
    --response-bg:    #1e2235;
    --response-border:#3b4270;
    --response-text:  #93c5fd;
    --shadow:         0 2px 12px rgba(0,0,0,0.4);
    --toggle-bg:      #2d3148;
    --toggle-text:    #a0aec0;
}

/* ── OS-Level Dark Mode (prevents flash on load) ── */
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) {
        --bg:             #0f1117;
        --surface:        #1a1d2e;
        --border:         #2d3148;
        --text-primary:   #e8eaf0;
        --text-secondary: #a0aec0;
        --text-muted:     #718096;
        --accent:         #60a5fa;
        --accent-hover:   #93c5fd;
        --accent-text:    #0f1117;
        --btn-bg:         #3b82f6;
        --btn-hover:      #60a5fa;
        --response-bg:    #1e2235;
        --response-border:#3b4270;
        --response-text:  #93c5fd;
        --shadow:         0 2px 12px rgba(0,0,0,0.4);
        --toggle-bg:      #2d3148;
        --toggle-text:    #a0aec0;
    }
}

/* ── Suppress transitions on initial paint ── */
.no-transition,
.no-transition * {
    transition: none !important;
}

/* ── Base ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    overflow-wrap: break-word;
}

html {
    font-size: 16px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

body {
    width: 90%;
    max-width: 640px;
    margin: 0 auto;
    padding: 2rem 1rem 0;
    font-family: 'Georgia', 'Times New Roman', serif;
    background-color: var(--bg);
    color: var(--text-primary);
    line-height: 1.7;
    transition: background-color 0.3s ease, color 0.3s ease;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main {
    flex: 1;
    padding-bottom: 2rem;
}

/* ── Skip Link ── */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0.5rem;
    background: var(--surface);
    color: var(--accent);
    padding: 0.5rem 1rem;
    border: 2px solid var(--accent);
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: 'Georgia', serif;
    z-index: 100;
    text-decoration: none;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0.5rem;
}

/* ── Focus Styles ── */
button:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

/* ── Site Navigation ── */
.site-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 2rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
    transition: border-color 0.3s ease;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 1.5rem;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-toggle {
    display: none;
    background: var(--toggle-bg);
    color: var(--toggle-text);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.4rem 0.75rem;
    font-size: 1rem;
    cursor: pointer;
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
}

.nav-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.site-nav a {
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-bottom: none;
    transition: color 0.2s ease;
}

.site-nav a:hover {
    color: var(--accent);
    border-bottom: none;
}

.site-nav a[aria-current="page"] {
    color: var(--accent);
    font-weight: 600;
}

@media (max-width: 600px) {
    .nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav-links {
        display: none;
        flex-direction: column;
        width: 100%;
        gap: 0;
        padding: 0.5rem 0;
        margin-top: 0.5rem;
        border-top: 1px solid var(--border);
        order: 1;
    }

    .nav-links.is-open {
        display: flex;
    }

    .nav-links a {
        display: block;
        padding: 0.5rem 0;
    }
}

/* ── Theme Toggle ── */

#themeToggle {
    background: var(--toggle-bg);
    color: var(--toggle-text);
    border: 1px solid var(--border);
    padding: 0.4rem 0.9rem;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Georgia', serif;

    /* Mobile touch improvements */
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

#themeToggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Typography ── */
h1 {
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1rem;
    line-height: 1.3;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 0.97rem;
}

a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
}

a:hover {
    border-bottom-color: var(--accent);
}

em {
    color: var(--text-muted);
    font-size: 0.9rem;
}

strong {
    color: var(--text-primary);
}

/* ── Box ── */
.box {
    margin: 2rem 0;
    padding: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* ── IP Button ── */
#ipButton {
    display: inline-block;
    padding: 0.55rem 1.4rem;
    background: var(--btn-bg);
    color: var(--accent-text);
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: 'Georgia', serif;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    margin-bottom: 1rem;

    /* Mobile touch improvements */
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

#ipButton:hover {
    background: var(--btn-hover);
}

#ipButton:active {
    transform: scale(0.97);
}

/* ── Response Box ── */
#response {
    padding: 0.75rem 1rem;
    background: var(--response-bg);
    border: 1px solid var(--response-border);
    border-radius: 6px;
    color: var(--response-text);
    font-size: 0.95rem;
    font-family: 'Courier New', monospace;
    min-height: 2.5rem;
    transition: background-color 0.3s ease, color 0.3s ease;
    word-break: break-all;
    overflow-wrap: break-word;
    overflow-x: auto;
}

/* ── Site Footer ── */
.site-footer {
    margin-top: auto;
    padding: 1.25rem 0 2rem;
    border-top: 1px solid var(--border);
    transition: border-color 0.3s ease;
}

/* ── Footer Row ── */
.footer-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
}

.footer-row p {
    margin-bottom: 0;
}

/* ── Mobile Optimizations ── */
@media (max-width: 600px) {
    #ipButton {
        display: block;
        width: 100%;
        padding: 0.85rem 1.4rem;
        font-size: 1.05rem;
        text-align: center;
    }

    #themeToggle {
        font-size: 0.85rem;
        padding: 0.5rem 1rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    .box {
        padding: 1.25rem;
    }
}
