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

body {
    font-family: system-ui, -apple-system, sans-serif;
    color: #1a1a1a;
    background: #b0bec5;
    min-height: 100vh;
}

/* ── App header / page navigation ── */
.app-header {
    background: #0c090a;
    color: #e5e4e2;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 2rem;
    height: 48px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    position: relative;
    z-index: 2;
}

.app-title {
    font-variant: small-caps;
    font-size: 1.5rem;
    font-weight: 700;
    white-space: nowrap;
}

.page-nav {
    display: flex;
    gap: 0.25rem;
}

.page-link {
    color: #aaa;
    text-decoration: none;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    border-radius: 4px 4px 0 0;
    white-space: nowrap;
    transition: color 0.15s, background 0.15s;
}

.page-link:hover {
    color: #fff;
    background: rgba(255,255,255,0.08);
}

.page-link.active {
    color: #fff;
    background: rgba(255,255,255,0.14);
    font-weight: 600;
}

/* ── Body layout: sidebar + page ── */
.app-body {
    display: flex;
    min-height: calc(100vh - 48px);
}

.tool-sidebar {
    flex: 0 0 160px;
    background: #1c1b1d;
    padding: 0.75rem 0;
    box-shadow: 2px 0 6px rgba(0,0,0,0.25);
}

.tool-nav {
    display: flex;
    flex-direction: column;
}

.tool-link {
    color: #aaa;
    text-decoration: none;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    white-space: nowrap;
    border-left: 3px solid transparent;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.tool-link:hover {
    color: #fff;
    background: rgba(255,255,255,0.06);
}

.tool-link.active {
    color: #fff;
    background: rgba(255,255,255,0.12);
    border-left-color: #2563eb;
    font-weight: 600;
}

.page {
    flex: 1;
    min-width: 0;
}

.page[hidden] {
    display: none;
}

/* ── About page ── */
.about-container {
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    background: #fff;
    border: 1px solid #d4d0c8;
    box-shadow: 2px 5px 10px #888;
    border-radius: 4px;
    margin-top: 1rem;
}

.about-container h1 {
    margin-bottom: 0.75rem;
}

.about-container h2 {
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.about-container p {
    margin-bottom: 0.75rem;
    line-height: 1.6;
    color: #333;
}

/* ── Main tool container ── */
.tool-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* ── Ad slots ──
   Reserved containers for ad units. They live in normal document flow
   (not absolute/fixed) so an injected ad pushes surrounding content instead
   of overlapping the canvas. Empty slots collapse to zero height via :empty. */
.ad-slot {
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    /* Ad networks sometimes inject iframes wider than the viewport; clip them
       so the layout never grows a horizontal scrollbar. */
    max-width: 100%;
}

.ad-slot:empty {
    display: none;
}

.ad-slot-top {
    margin-bottom: 1rem;
    /* Leaderboard-ish default; the ad script can resize this. */
    min-height: 90px;
}

.ad-slot-bottom {
    margin-top: 1rem;
    min-height: 90px;
}

.venn-layout {
    display: flex;
    gap: 1rem;
    background: #fff;
    border: 1px solid #d4d0c8;
    box-shadow: 2px 5px 10px #888;
    border-radius: 4px;
    overflow: hidden;
}

/* ── Left: Input panel ── */
.input-panel {
    flex: 0 0 380px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    max-height: calc(100vh - 80px);
}

.instructions {
    font-size: 0.85rem;
    color: #555;
    line-height: 1.6;
}

.instructions p {
    margin-bottom: 0.1rem;
}

.case-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.delimiter-label {
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-left: auto;
}

.delimiter-label select {
    padding: 0.2rem 0.3rem;
    font-size: 0.8rem;
    border: 1px solid #999;
    border-radius: 2px;
}

/* Font-size slider for diagram count/percentage labels. Lives next to the
   delimiter dropdown so all text-related controls are grouped together. */
.font-size-label {
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    width: 100%;
}

.font-size-label input[type="range"] {
    flex: 1;
    min-width: 80px;
    accent-color: #666;
    cursor: pointer;
}

.font-size-label span {
    min-width: 2.6em;
    text-align: right;
    color: #666;
    font-variant-numeric: tabular-nums;
}

.btn-small {
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
    background: #d4d0c8;
    border: 1px outset #d4d0c8;
    cursor: pointer;
    font-family: sans-serif;
}

.btn-small:active {
    border-style: inset;
}

/* ── List inputs grid ── */
.lists-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.list-group {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.list-header {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* ── Color swatch + picker ── */
.color-swatch-wrap {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.color-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid rgba(0,0,0,0.2);
    cursor: pointer;
    flex-shrink: 0;
}

.color-picker {
    width: 20px;
    height: 16px;
    padding: 0;
    border: none;
    border-radius: 2px;
    cursor: pointer;
    background: none;
    flex-shrink: 0;
    /* hide the native color swatch frame */
    -webkit-appearance: none;
    appearance: none;
    overflow: hidden;
}

.color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker::-webkit-color-swatch {
    border: 1px solid rgba(0,0,0,0.2);
    border-radius: 2px;
}

.alpha-slider {
    width: 44px;
    height: 12px;
    padding: 0;
    cursor: pointer;
    accent-color: #666;
    flex-shrink: 0;
}

.list-name {
    font-weight: 700;
    font-size: 0.85rem;
    border: 1px solid #ccc;
    padding: 0.15rem 0.3rem;
    width: 100%;
    max-width: 100px;
    border-radius: 2px;
    min-width: 0;
}

.element-count {
    font-size: 0.75rem;
    color: #888;
    white-space: nowrap;
}

.list-input {
    width: 100%;
    padding: 0.35rem;
    font-family: monospace;
    font-size: 0.8rem;
    border: 1px solid #ccc;
    border-radius: 2px;
    resize: vertical;
    min-height: 80px;
}

.btn-clear {
    align-self: flex-end;
    font-size: 0.75rem;
    color: #2563eb;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.btn-clear:hover {
    color: #1d4ed8;
}

/* ── Results ── */
.results-section {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.results-section label {
    font-size: 0.85rem;
    font-weight: 600;
}

.results-area {
    width: 100%;
    padding: 0.4rem;
    font-family: monospace;
    font-size: 0.8rem;
    border: 1px solid #ccc;
    border-radius: 2px;
    resize: vertical;
    background: #fafafa;
}

/* ── Right: Diagram panel ── */
.diagram-panel {
    flex: 1;
    background: #d4d0c8;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.diagram-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    font-size: 0.85rem;
    background: #d4d0c8;
    padding: 0.25rem 0.5rem;
    width: 100%;
    flex-wrap: wrap;
}

.proportional-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
}

.save-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: auto;
}

.save-group select {
    padding: 0.2rem 0.4rem;
    font-size: 0.8rem;
    border: 1px solid #999;
    border-radius: 2px;
}

.canvas-wrapper {
    position: relative;
    background: #fff;
    display: inline-block;
    line-height: 0;
}

canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.loading {
    font-size: 0.9rem;
    color: #555;
    padding: 1rem;
}

/* ── Tooltip ── */
.venn-tooltip {
    position: absolute;
    background: rgba(30, 30, 30, 0.88);
    color: #fff;
    font-size: 0.78rem;
    padding: 4px 8px;
    border-radius: 3px;
    pointer-events: none;
    white-space: nowrap;
    z-index: 10;
    max-width: 220px;
    white-space: normal;
    line-height: 1.3;
}

.venn-tooltip[hidden] {
    display: none;
}

/* ── Info overlay ──
   Floats over the canvas inside .canvas-wrapper (which is already
   position:relative). The toggle button sits in the top-right corner of the
   diagram; the overlay fills the wrapper so the canvas stays visible behind
   the semi-transparent backdrop and the page layout never reflows. */
.info-toggle {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid #999;
    background: #fff;
    color: #333;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    z-index: 11;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.info-toggle:hover {
    background: #f0f0f0;
    border-color: #666;
}

.info-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.96);
    z-index: 12;
    overflow-y: auto;
    line-height: normal;
}

.info-overlay[hidden] {
    display: none;
}

.info-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid #999;
    background: #fff;
    color: #333;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.info-close:hover {
    background: #f0f0f0;
    border-color: #666;
}

.info-overlay-content {
    padding: 1.5rem 1.25rem;
    /* Leave room for the close button so the heading doesn't run under it. */
    padding-right: 2.5rem;
    font-size: 0.9rem;
    color: #333;
}

.info-overlay-content h1 {
    font-size: 1.15rem;
    margin-bottom: 0.75rem;
}

.info-overlay-content h2 {
    font-size: 1rem;
    margin-top: 1rem;
    margin-bottom: 0.4rem;
}

.info-overlay-content p {
    margin-bottom: 0.6rem;
    line-height: 1.55;
}

/* ── Responsive / mobile ── */
@media (max-width: 860px) {
    .app-body {
        flex-direction: column;
    }

    .tool-sidebar {
        flex: none;
        padding: 0;
    }

    .tool-nav {
        flex-direction: row;
        overflow-x: auto;
    }

    .tool-link {
        border-left: none;
        border-bottom: 3px solid transparent;
    }

    .tool-link.active {
        border-left: none;
        border-bottom-color: #2563eb;
    }

    .venn-layout {
        flex-direction: column;
    }

    .input-panel {
        flex: none;
        max-height: none;
    }

    .diagram-panel {
        order: -1;
    }

    .canvas-wrapper {
        width: 100%;
    }

    canvas {
        width: 100% !important;
        height: auto !important;
    }
}

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

    .app-header {
        flex-direction: column;
        height: auto;
        padding: 0.5rem 1rem;
        gap: 0.25rem;
    }

    .input-panel {
        flex: none;
        padding: 0.75rem;
    }

    .delimiter-label {
        margin-left: 0;
        width: 100%;
    }
}

/* ── SEO Content Block ── */
.seo-content-block {
    max-width: 800px;
    margin: 3rem auto;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.seo-content-block h1 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #1a1a1a;
}

.seo-content-block h2 {
    font-size: 1.25rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: #1a1a1a;
}

.seo-content-block p {
    margin-bottom: 1rem;
    line-height: 1.6;
    color: #333;
}