/* Theme tokens
   Adjust these first if you want to change the overall look quickly. */
:root {
    --bg: #f5f2ea;
    --bg-accent: #ece7db;
    --surface: rgba(255, 255, 255, 0.88);
    --surface-strong: #ffffff;
    --line: #ddd6c8;
    --line-strong: #cfc4b2;
    --text: #172033;
    --muted: #667085;
    --accent: #1f4e46;
    --accent-soft: #e6efec;
    --accent-contrast: #ffffff;
    --good-bg: #e6f5ef;
    --good-text: #15634e;
    --shadow-soft: 0 10px 30px rgba(23, 32, 51, 0.06);
    --shadow-strong: 0 14px 34px rgba(23, 32, 51, 0.08);
}

/* Base reset */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 34%),
        linear-gradient(180deg, var(--bg-accent), var(--bg));
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: inherit;
}

/* Page shell and card chrome */
.page-shell {
    width: min(960px, calc(100% - 24px));
    margin: 0 auto;
    padding: 24px 0 48px;
}

.card,
#site-header,
#global-controls,
#live-preview,
#results,
#site-footer,
#ad-top {
    background: var(--surface);
    backdrop-filter: blur(12px);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
}

/* Shared vertical rhythm */
#site-header,
.how-it-works,
#global-controls,
#live-preview,
#results,
.seo-copy,
.faq-block,
.share-block,
#site-footer,
#ad-top {
    margin-bottom: 16px;
}

#site-header,
.how-it-works,
#global-controls,
#live-preview,
#results,
.seo-copy,
.faq-block,
.share-block,
#site-footer {
    padding: 20px;
}

/* Shared section content width */
.card > .section-kicker,
.card > h2,
.card > h3,
.card > p,
.card > .seo-text,
.card > .faq-list,
.card > .share-actions,
.card > .results-summary {
    max-width: 62ch;
    margin-left: 0;
    margin-right: auto;
}

/* Small uppercase section labels */
.site-eyebrow,
.section-kicker {
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* Core heading styles */
#site-header h1,
.how-it-works h2,
#results h2,
#live-preview h3 {
    margin: 0;
}

#site-header h1 {
    font-size: clamp(2rem, 5vw, 2.8rem);
    line-height: 1.05;
    letter-spacing: -0.03em;
}

.site-title {
    text-decoration: none;
}

.tagline,
.version,
.context-note,
.row-hint,
.footer-meta,
.muted,
.results-summary,
.preview-summary {
    color: var(--muted);
}

.tagline {
    margin: 8px 0 4px;
}

.version,
.context-note,
.row-hint,
.footer-meta,
.muted,
.results-summary,
.preview-summary {
    font-size: 0.92rem;
}

.build-id,
.build-timestamp {
    display: block;
}

.build-timestamp {
    margin-top: 2px;
    font-size: 0.72rem;
    line-height: 1.3;
}

/* Introductory text cards */
.how-it-works h2 {
    font-size: 1.45rem;
    margin-bottom: 10px;
    letter-spacing: -0.02em;
}

.how-it-works p,
.results-summary,
.preview-summary {
    margin: 0;
}

.seo-copy p {
    margin: 0 0 10px;
    color: var(--muted);
}

.seo-copy p:last-child {
    margin-bottom: 0;
}

.faq-list {
    display: grid;
    gap: 12px;
}

.faq-item {
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.faq-item:first-child {
    padding-top: 0;
    border-top: 0;
}

.faq-item summary {
    cursor: pointer;
    list-style: none;
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    padding-right: 18px;
    position: relative;
}

.faq-item p {
    margin: 10px 0 0;
    color: var(--muted);
}

.faq-item summary::-webkit-details-marker {
    display: none;
}

.faq-item summary::after {
    content: "+";
    position: absolute;
    right: 0;
    top: 0;
    color: var(--muted);
    font-weight: 600;
}

.faq-item[open] summary::after {
    content: "−";
}

/* Share block */
.share-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    align-items: center;
    justify-content: center;
}

.share-block .section-kicker,
.share-block h2,
.share-block .share-actions {
    margin-left: auto;
    margin-right: auto;
}

.share-block .section-kicker,
.share-block h2 {
    text-align: center;
}

.share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-strong);
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    flex: 0 0 auto;
    box-shadow: 0 6px 14px rgba(23, 32, 51, 0.06);
    transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.share-native {
    background: var(--accent);
    color: var(--accent-contrast);
}

.share-icon {
    font-size: 1.05rem;
}

.share-native span,
.share-icon span {
    line-height: 1;
}

/* Global controls */
.controls-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.controls-row label {
    font-size: 0.9rem;
    font-weight: 600;
}

.validation-message {
    margin-top: 12px;
    padding: 10px 12px;
    border: 1px solid #fecaca;
    border-radius: 10px;
    background: #fef2f2;
    color: #b91c1c;
    font-size: 0.9rem;
}

select,
input,
button {
    font: inherit;
}

select,
input {
    width: 100%;
    margin-top: 6px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--text);
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

select:focus,
input:focus {
    outline: 2px solid transparent;
    border-color: color-mix(in srgb, var(--accent) 42%, white);
    box-shadow: 0 0 0 4px rgba(31, 78, 70, 0.08);
    background: var(--surface-strong);
}

input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
}

/* Calculator, preview, and results tables */
#calculator {
    margin-top: 16px;
}

#calculator table,
.preview-table,
.results-table {
    width: 100%;
    border-collapse: collapse;
}

.input-table {
    table-layout: fixed;
}

.preview-table {
    min-width: 460px;
    table-layout: fixed;
}

.results-table {
    min-width: 640px;
    table-layout: fixed;
}

#calculator th,
#calculator td,
.preview-table th,
.preview-table td,
.results-table th,
.results-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

#calculator th,
.preview-table th,
.results-table th {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    text-align: left;
}

#calculator .th-main,
.preview-table .th-main,
.results-table .th-main {
    display: block;
    color: var(--text);
    font-size: 0.85rem;
}

#calculator .th-sub,
.preview-table .th-sub,
.results-table .th-sub {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
}

#calculator th:nth-child(1),
#calculator td:nth-child(1) {
    width: 42%;
}

#calculator th:nth-child(2),
#calculator td:nth-child(2),
#calculator th:nth-child(3),
#calculator td:nth-child(3) {
    width: 22%;
}

#calculator th:nth-child(4),
#calculator td:nth-child(4) {
    width: 14%;
}

#calculator td:nth-child(2),
#calculator td:nth-child(3),
#calculator th:nth-child(2),
#calculator th:nth-child(3) {
    text-align: right;
}

#calculator th:nth-child(4),
#calculator td:nth-child(4) {
    text-align: right;
}

#calculator td input {
    margin-top: 0;
    min-height: 42px;
}

#calculator td:nth-child(2) input,
#calculator td:nth-child(3) input {
    text-align: right;
}

.row-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.btn-row {
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1;
}

.btn-remove-row {
    color: #b91c1c;
}

.row-invalid input {
    border-color: #fca5a5;
    background: #fff5f5;
}

.preview-table th:nth-child(n+2),
.preview-table td:nth-child(n+2),
.results-table th:nth-child(n+2),
.results-table td:nth-child(n+2) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.preview-table th:nth-child(1),
.preview-table td:nth-child(1) {
    width: 28%;
    max-width: 0;
}

.preview-table th:nth-child(2),
.preview-table td:nth-child(2),
.preview-table th:nth-child(3),
.preview-table td:nth-child(3) {
    width: 36%;
}

.preview-table td:nth-child(1) {
    overflow: hidden;
    text-overflow: ellipsis;
}

.results-table th:nth-child(1),
.results-table td:nth-child(1) {
    width: 24%;
}

.results-table th:nth-child(2),
.results-table td:nth-child(2),
.results-table th:nth-child(3),
.results-table td:nth-child(3),
.results-table th:nth-child(4),
.results-table td:nth-child(4),
.results-table th:nth-child(5),
.results-table td:nth-child(5),
.results-table th:nth-child(6),
.results-table td:nth-child(6) {
    width: 15.2%;
}

.preview-table tr.best-value td,
.results-table tr.best-value td {
    background: var(--good-bg);
    color: var(--good-text);
    font-weight: 600;
}

/* Primary actions */
.calculator-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

button {
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-contrast);
    font-weight: 600;
    box-shadow: 0 10px 22px rgba(31, 78, 70, 0.18);
}

.btn-reset {
    background: var(--accent-soft);
    color: var(--text);
    border-color: color-mix(in srgb, var(--accent) 16%, var(--line));
    font-weight: 600;
}

button:hover,
.share-btn:hover {
    transform: translateY(-1px);
}

.btn-primary:hover {
    box-shadow: 0 14px 26px rgba(31, 78, 70, 0.24);
}

#live-preview,
#results {
    overflow-x: auto;
    transition: opacity 0.2s ease;
}

#results {
    position: relative;
}

#results::after {
    content: "";
    position: sticky;
    right: 0;
    top: 0;
    display: block;
    width: 18px;
    height: 100%;
    margin-left: auto;
    pointer-events: none;
    background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(247, 247, 245, 0.95));
}

#live-preview h3,
#results h2 {
    margin-bottom: 6px;
    font-size: 1rem;
}

.preview-summary,
.results-summary {
    margin-bottom: 12px;
}

.winner-card {
    margin-bottom: 16px;
    padding: 16px;
    border: 1px solid color-mix(in srgb, var(--accent) 20%, white);
    border-radius: 14px;
    background: var(--good-bg);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.winner-card h2 {
    margin-bottom: 6px;
    color: var(--good-text);
}

.winner-note {
    margin: 0;
    color: #166534;
    font-size: 0.92rem;
}

.results-stale {
    opacity: 0.6;
}

.cpc-ad {
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(246, 242, 234, 0.8));
    border-radius: 16px;
    overflow: hidden;
}

#site-footer {
    text-align: center;
}

/* Desktop-specific layout tuning */
@media (min-width: 768px) {
    .page-shell {
        width: min(1120px, calc(100% - 40px));
    }

    #site-header,
    .how-it-works,
    .seo-copy,
    .faq-block,
    .share-block,
    #global-controls,
    #live-preview,
    #results,
    #site-footer {
        padding: 24px 28px;
    }

    .card > .section-kicker,
    .card > h2,
    .card > h3,
    .card > p,
    .card > .seo-text,
    .card > .faq-list,
    .card > .share-actions,
    .card > .results-summary {
        max-width: none;
        margin-left: 8px;
    }

    .share-block .section-kicker,
    .share-block h2,
    .share-block .share-actions {
        margin-left: auto;
        margin-right: auto;
    }

    .calculator-actions {
        justify-content: center;
        align-items: center;
        margin-top: 20px;
        margin-bottom: 24px;
    }

    .calculator-actions .btn-primary,
    .calculator-actions .btn-reset {
        min-width: 132px;
    }
}

/* Mobile-specific layout tuning */
@media (max-width: 640px) {
    .page-shell {
        width: calc(100% - 16px);
        padding-top: 16px;
    }

    #site-header,
    .how-it-works,
    .seo-copy,
    .faq-block,
    .share-block,
    #global-controls,
    #live-preview,
    #results,
    #site-footer {
        padding: 16px;
    }

    .calculator-actions {
        flex-direction: column;
    }

    .share-actions {
        flex-wrap: nowrap;
    }

    #calculator {
        overflow-x: auto;
    }

    #calculator table {
        min-width: 100%;
    }

    #calculator th,
    #calculator td,
    .preview-table th,
    .preview-table td,
    .results-table th,
    .results-table td {
        padding: 8px 6px;
    }

    #calculator .th-main,
    .preview-table .th-main,
    .results-table .th-main {
        font-size: 0.78rem;
    }

    #calculator .th-sub,
    .preview-table .th-sub,
    .results-table .th-sub {
        font-size: 0.68rem;
    }

    #calculator th,
    .results-table th,
    #calculator td,
    .results-table td {
        white-space: nowrap;
    }

    #calculator th:nth-child(1),
    #calculator td:nth-child(1) {
        width: 40%;
    }

    #calculator th:nth-child(2),
    #calculator td:nth-child(2) {
        width: 24%;
    }

    #calculator th:nth-child(4),
    #calculator td:nth-child(4) {
        width: 12%;
    }

    #calculator td input {
        min-height: 36px;
        padding: 8px 9px;
        font-size: 0.92rem;
    }

    #calculator td:nth-child(1) input {
        text-align: left;
    }

    .row-actions {
        justify-content: center;
    }

    .btn-row {
        min-width: 32px;
        min-height: 32px;
        font-size: 0.9rem;
    }

    #results,
    #live-preview {
        overflow-x: auto;
    }

    .preview-table {
        min-width: 0;
        width: 100%;
        table-layout: fixed;
    }

    .preview-table th,
    .preview-table td {
        white-space: normal;
    }

    .preview-table .th-sub {
        display: none;
    }

    .preview-table th:nth-child(1),
    .preview-table td:nth-child(1) {
        width: 30%;
        max-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .preview-table th:nth-child(2),
    .preview-table td:nth-child(2),
    .preview-table th:nth-child(3),
    .preview-table td:nth-child(3) {
        width: 35%;
    }

    .results-table {
        min-width: 540px;
    }

    #results::before {
        content: "Swipe table";
        display: block;
        margin-bottom: 8px;
        color: var(--muted);
        font-size: 0.78rem;
        text-align: right;
    }
}
