:root {
    /* Light theme (muted, with clearer contrast between background and panels) */
    --bg: #e2e8f0; /* page background: slate-200 */
    --panel: #ffffff; /* card / panel background: crisp white */
    --text: #020617; /* primary text: near-black for clarity */
    --muted: #64748b; /* help/caption text: slate-500 */
    --border: #cbd5e1; /* panel and control borders: slate-300 */
    --accent: #2563eb; /* primary accent (buttons, focus) */
    --accent-contrast: #ffffff; /* text on accent backgrounds */
    --secondary: #4b5563; /* secondary button text */
    --success: #16a34a;
    --error: #dc2626;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 10px rgba(15, 23, 42, 0.04);
    --control: #f9fafb; /* inputs, textareas */
    --control-border: #cbd5e1;
    --focus-ring: rgba(37, 99, 235, 0.25);
    /* Shared textarea height to keep Input and Output exactly the same size.
       Clamp keeps height relative to viewport but prevents it from becoming huge. */
    --textarea-h: clamp(220px, 35vh, 420px);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg: #0b0f14;
        --panel: #0f1720;
        --text: #e5e7eb;
        --muted: #9aa4b2;
        --border: #1d2733;
        --accent: #60a5fa;
        --accent-contrast: #0b0f14;
        --secondary: #94a3b8;
        --success: #22c55e;
        --error: #ef4444;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.25);
        --control: #0b141d;
        --control-border: #243040;
        --focus-ring: rgba(96, 165, 250, 0.35);
    }
}

/* Explicit dark theme override when toggled via data-theme */
:root[data-theme="dark"] {
    --bg: #0b0f14;
    --panel: #0f1720;
    --text: #e5e7eb;
    --muted: #9aa4b2;
    --border: #1d2733;
    --accent: #60a5fa;
    --accent-contrast: #0b0f14;
    --secondary: #94a3b8;
    --success: #22c55e;
    --error: #ef4444;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.25);
    --control: #0b141d;
    --control-border: #243040;
    --focus-ring: rgba(96, 165, 250, 0.35);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.25rem;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(6px);
}

.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-title {
    font-size: 1.5rem;
    margin: 0.25rem 0;
    text-align: center;
}

.main-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    align-items: start;
    grid-template-areas:
    "input"
    "output"
    "cta"
    "notice";
}

@media (min-width: 900px) {
    .main-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
      "notice notice" /* Heads-up spans full row */
      "input output"  /* Input and Output split 50/50 */
      "cta cta";
        /* Ensure panels in the same row have equal height */
        align-items: stretch;
    }

    /* Place sections explicitly to avoid awkward empty gaps */
    section[aria-labelledby="input-section-title"] {
        grid-area: input;
    }

    .panel-notice {
        grid-area: notice;
    }

    section[aria-labelledby="output-section-title"] {
        grid-area: output;
    }

    .panel-cta {
        grid-area: cta;
    }
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 1.2rem;
    margin: 0;
}

.panel-body {
    padding: 1rem;
}

/* Let grid children panels stretch to equalize column heights and allow inner body to fill */
.main-grid > .panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.main-grid > .panel .panel-body {
    flex: 1 1 auto;
}

.field-label {
    display: block;
    font-size: 0.9rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

.m-top {
    margin-top: 0.75rem;
}

.select, .textarea {
    width: 100%;
    background: var(--control);
    color: var(--text);
    border: 1px solid var(--control-border);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
}

.select {
    appearance: none;
}

.select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.textarea {
    /* Keep both textareas equal height regardless of content */
    height: var(--textarea-h);
    resize: vertical;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    line-height: 1.4;
}

.actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* Inline controls next to selects (e.g., Detect/Swap) */
.inline-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, transform 60ms ease;
}

.btn:hover {
    border-color: var(--muted);
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-contrast);
    border-color: var(--accent);
}

.btn-primary:hover {
    filter: brightness(1.05);
}

.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.btn-compact {
    padding: 0.45rem 0.6rem;
    font-weight: 500;
}

/* Busy state indicator for primary actions */
.btn.is-busy {
    position: relative;
}

.btn.is-busy::after {
    content: "";
    width: 1em;
    height: 1em;
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-top-color: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 0.5rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.btn-secondary {
    background: transparent;
    color: var(--secondary);
}

.btn-theme-toggle {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.theme-toggle-icon {
    font-size: 1rem;
}

.panel-cta .panel-body {
    display: flex;
    flex-direction: column; /* Stack button and status vertically */
    align-items: center; /* Center content horizontally */
    gap: 0.5rem; /* Space between button and status text */
}

.panel-cta .panel-body .cta-row {
    display: flex;
    justify-content: center;
    width: 100%;
}

/* Make the convert bar easy to reach on mobile */
@media (max-width: 899px) {
    .panel-cta {
        position: sticky;
        bottom: 0;
        z-index: 5;
        border-radius: 0;
        backdrop-filter: blur(6px);
    }

    .panel-cta .panel-body {
        justify-content: center;
    }
}


/* Accessible focus outline */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Visually hidden (screen-reader only) utility */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Skip link styles */
.skip-link {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.skip-link:focus {
    position: fixed;
    left: 1rem;
    top: 1rem;
    width: auto;
    height: auto;
    padding: 0.5rem 0.75rem;
    z-index: 1000;
    background: var(--accent);
    color: var(--accent-contrast);
    border-radius: 6px;
    box-shadow: var(--shadow);
}

/* Help text under fields */
.help-text {
    font-size: 0.85rem;
    color: var(--muted);
    margin: 0.25rem 0 0 0;
}

.status {
    min-height: 1.25rem; /* prevent layout jump when status appears */
    font-size: 0.9rem;
    color: var(--muted);
    text-align: center;
}

.status.info {
    color: var(--muted);
}

.status.success {
    color: var(--success);
}

.status.error {
    color: var(--error);
}

/* --- Notice panel (Heads‑up) layout & compact styling --- */
.panel-notice {
    /* Subtle background to differentiate without feeling heavy */
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.06), rgba(59, 130, 246, 0.03));
}

.panel-notice .panel-header {
    padding: 0.5rem 0.75rem;
}

.panel-notice .panel-header h2 {
    font-size: 1rem;
    margin: 0;
}

.panel-notice .panel-body {
    padding: 0.75rem;
}

.panel-notice .notice-text {
    margin: 0;
}

.panel-notice .notice-links {
    margin: 0.5rem 0 0 0;
    font-size: 0.9rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.notice-links-label {
    font-weight: 600;
}

.notice-link {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: var(--control);
    border: 1px solid var(--control-border);
    text-decoration: none;
    color: var(--text);
    font-size: 0.85rem;
}

.notice-link:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Drag & drop styles for input text area wrapper */
.textarea-wrap {
    border-radius: 8px;
}

.textarea-wrap.is-dragover {
    outline: 2px dashed var(--accent);
    outline-offset: 4px;
    background: rgba(59, 130, 246, 0.06);
}
