/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --ink: #1a1714;
    --paper: #f5f0e8;
    --cream: #ede7d9;
    --rust: #b84a2e;
    --rust-light: #d4614a;
    --gold: #c8923a;
    --muted: #7a7268;
    --border: #cfc8ba;
    --shadow: rgba(26,23,20,0.12);
    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'IBM Plex Sans', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
}

html { font-size: 16px; }

body {
    background-color: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-weight: 300;
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

img { max-width: 100%; }

/* ── Background texture ── */
.page-bg {
    position: fixed; inset: 0; z-index: 0;
    background-image:
        radial-gradient(ellipse 80% 60% at 10% 20%, rgba(200,146,58,0.07) 0%, transparent 60%),
        radial-gradient(ellipse 60% 80% at 90% 80%, rgba(184,74,46,0.06) 0%, transparent 60%);
    pointer-events: none;
}

/* ── Container ── */
.container {
    position: relative; z-index: 1;
    max-width: 860px;
    margin: 0 auto;
    padding: 3rem 2rem 4rem;
}

/* ── Header ── */
header { text-align: center; margin-bottom: 3rem; }

.logo-block {
    display: inline-block;
    margin-bottom: 1rem;
}
.logo-it {
    font-family: var(--font-display);
    font-size: 2.8rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.02em;
}
.logo-5 {
    font-family: var(--font-mono);
    font-size: 2.8rem;
    font-weight: 500;
    color: var(--rust);
}

h1 {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 400;
    font-style: italic;
    color: var(--muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 1rem;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--muted);
    max-width: 560px;
    margin: 0 auto;
    line-height: 1.7;
}

/* ── Task Tabs ── */
.task-tabs {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 2rem;
    background: var(--cream);
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 0.75rem;
    background: transparent;
    border: none;
    border-right: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    gap: 0.25rem;
}
.tab-btn:last-child { border-right: none; }
.tab-btn:hover { background: rgba(184,74,46,0.06); }
.tab-btn.active {
    background: var(--rust);
    color: #fff;
}

.tab-icon { font-size: 1.2rem; line-height: 1; }
.tab-label {
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 0.8rem;
    letter-spacing: 0.03em;
}
.tab-desc {
    font-size: 0.7rem;
    opacity: 0.7;
    font-style: italic;
}
.tab-btn.active .tab-desc { opacity: 0.85; }

/* ── Task Panels ── */
.task-panel { display: none; }
.task-panel.active { display: block; }

.panel-title {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}
.panel-title > span:first-child {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--ink);
}
.panel-hint {
    font-size: 0.8rem;
    color: var(--muted);
    font-style: italic;
}

/* ── Fields Grid ── */
.fields-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.field-group { display: flex; flex-direction: column; gap: 0.4rem; }
.field-group.full-width { grid-column: 1 / -1; }

.field-group label {
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ink);
}

.req-star { color: var(--rust); }
.opt-label {
    font-size: 0.68rem;
    font-weight: 400;
    color: var(--muted);
    text-transform: none;
    letter-spacing: 0;
    font-style: italic;
    margin-left: 0.25rem;
}

.field-group input[type="text"],
.field-group select,
.field-group textarea {
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 300;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    color: var(--ink);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.field-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a7268' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus {
    border-color: var(--rust);
    box-shadow: 0 0 0 3px rgba(184,74,46,0.1);
}

.field-group textarea { resize: vertical; min-height: 80px; }

.field-hint {
    font-size: 0.72rem;
    color: var(--muted);
    font-style: italic;
}

/* ── Form Footer ── */
.form-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 1.25rem 0;
    border-top: 1px solid var(--border);
    margin-bottom: 1rem;
}

/* Submit button */
#submitButton {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.8rem;
    background: var(--ink);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
}
#submitButton:hover { background: var(--rust); }
#submitButton:active { transform: scale(0.97); }
.btn-arrow { font-size: 1rem; transition: transform 0.2s; }
#submitButton:hover .btn-arrow { transform: translateX(4px); }

/* ── Prompt Preview ── */
.prompt-preview {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--cream);
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 0.5rem;
}
.preview-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    flex-shrink: 0;
    margin-top: 0.05rem;
}
.preview-text {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--ink);
    word-break: break-word;
}

/* ── Results ── */
.results-section {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 2px solid var(--ink);
}

.results-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.results-header h2 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
}

.results-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.2rem;
}
.meta-prompt {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--muted);
    font-style: italic;
    max-width: 400px;
    text-align: right;
    word-break: break-word;
}
.meta-task {
    font-size: 0.72rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--rust);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
}

.result-card {
    padding: 0.85rem 1rem;
    background: var(--card-color, #fff);
    border: 1px solid var(--border);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    transition: transform 0.15s, box-shadow 0.15s;
}
.result-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.result-word {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
    word-break: break-word;
}
.result-prob {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--muted);
}

/* ── Loading overlay ── */
#loading-overlay {
    position: fixed; inset: 0; z-index: 999;
    background: rgba(245,240,232,0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
    backdrop-filter: blur(4px);
}
.loading-inner {
    display: flex; flex-direction: column; align-items: center; gap: 1rem;
}
.loading-inner img { width: 48px; }
.loading-inner p {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--muted);
    letter-spacing: 0.06em;
}

/* ── Back link ── */
.back-link {
    display: inline-block;
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: var(--muted);
    text-decoration: none;
    margin-bottom: 1.5rem;
    transition: color 0.2s;
}
.back-link:hover { color: var(--rust); }

/* ── Mode badge ── */
.mode-badge {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 0.2rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--muted);
    margin-bottom: 0.75rem;
}
.mode-badge.neo-badge {
    border-color: var(--rust);
    color: var(--rust);
    background: rgba(184,74,46,0.06);
}

/* ── Character counter ── */
.char-counter {
    font-size: 0.68rem;
    color: var(--muted);
    font-family: var(--font-mono);
    text-align: right;
    transition: color 0.2s;
}
.char-counter.at-limit { color: var(--rust); font-weight: 500; }

/* ── Landing page ── */
.landing-container { max-width: 900px; }

.landing-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-top: 2.5rem;
    margin-bottom: 3rem;
}

.landing-card {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1.75rem 1.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    text-decoration: none;
    color: var(--ink);
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
}
.landing-card:hover {
    border-color: var(--rust);
    box-shadow: 0 4px 16px var(--shadow);
    transform: translateY(-2px);
}
.landing-card.neo-card { background: rgba(184,74,46,0.03); }
.landing-card.neo-card:hover { border-color: var(--rust); }

.landing-card-icon {
    font-size: 1.8rem;
    flex-shrink: 0;
    line-height: 1;
}

.landing-card-body { flex: 1; }
.landing-card-body h2 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 0.35rem;
    color: var(--ink);
}
.landing-card-body p {
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.55;
}

.landing-card-arrow {
    font-size: 1.2rem;
    color: var(--muted);
    flex-shrink: 0;
    transition: transform 0.2s, color 0.2s;
}
.landing-card:hover .landing-card-arrow {
    transform: translateX(4px);
    color: var(--rust);
}

/* ── Tom Select overrides ── */
.ts-wrapper { width: 100%; }

.ts-wrapper .ts-control {
    border: 1px solid var(--border) !important;
    border-radius: 4px !important;
    background: #fff !important;
    padding: 0.4rem 0.6rem !important;
    font-family: var(--font-body) !important;
    font-size: 0.9rem !important;
    font-weight: 300 !important;
    color: var(--ink) !important;
    box-shadow: none !important;
    min-height: unset !important;
    transition: border-color 0.2s, box-shadow 0.2s !important;
    cursor: text;
}
.ts-wrapper.focus .ts-control {
    border-color: var(--rust) !important;
    box-shadow: 0 0 0 3px rgba(184,74,46,0.1) !important;
}

.ts-control input {
    font-family: var(--font-body) !important;
    font-size: 0.9rem !important;
    font-weight: 300 !important;
    color: var(--ink) !important;
}

.ts-control .item {
    background: var(--cream) !important;
    border: 1px solid var(--border) !important;
    border-radius: 3px !important;
    color: var(--ink) !important;
    padding: 1px 22px 1px 6px !important;
    font-size: 0.82rem !important;
    font-weight: 400 !important;
    margin: 2px !important;
}

.ts-dropdown {
    font-family: var(--font-body) !important;
    font-size: 0.88rem !important;
    border: 1px solid var(--border) !important;
    border-radius: 4px !important;
    box-shadow: 0 4px 12px var(--shadow) !important;
    background: #fff !important;
    color: var(--ink) !important;
}
.ts-dropdown .option {
    padding: 0.45rem 0.85rem !important;
    color: var(--ink) !important;
}
.ts-dropdown .option:hover,
.ts-dropdown .option.active {
    background: rgba(184,74,46,0.08) !important;
    color: var(--ink) !important;
}
.ts-dropdown .option.selected {
    background: rgba(184,74,46,0.14) !important;
}

/* ── Top bar ── */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.lab-logo img {
    height: 36px;
    opacity: 0.8;
    transition: opacity 0.2s;
    display: block;
}
.lab-logo:hover img { opacity: 1; }

.info-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.38rem 1rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: var(--muted);
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.2s, color 0.2s;
}
.info-btn:hover { border-color: var(--rust); color: var(--rust); }

/* ── Info modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(26,23,20,0.52);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.modal-overlay.open { display: flex; }

.modal-box {
    background: var(--paper);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-width: 680px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 2.5rem;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1.25rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
    padding: 0;
}
.modal-close:hover { color: var(--ink); }

.modal-box > h2 {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 1.75rem;
    padding-right: 2rem;
}

.modal-section { margin-bottom: 1.75rem; }

.modal-section h3 {
    font-family: var(--font-body);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--rust);
    margin-bottom: 0.6rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}

.modal-section p,
.modal-section li {
    font-size: 0.87rem;
    color: var(--muted);
    line-height: 1.7;
}

.modal-section ul { padding-left: 1.2rem; margin-top: 0.4rem; }
.modal-section li { margin-bottom: 0.4rem; }

.modal-section a { color: var(--rust); text-decoration: none; }
.modal-section a:hover { text-decoration: underline; }

.modal-section code {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    background: var(--cream);
    padding: 0.1em 0.4em;
    border-radius: 3px;
}

/* ── Task overview boxes ── */
.task-overview { margin: 1.5rem 0 0.5rem; }

.task-overview-title {
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.85rem;
}

.task-boxes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.85rem;
}

.task-box {
    padding: 1.1rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--cream);
}

.task-box-tag {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--rust);
    margin-bottom: 0.3rem;
}

.task-box h3 {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 0.4rem;
}

.task-box p {
    font-size: 0.78rem;
    color: var(--muted);
    line-height: 1.5;
}

.task-example {
    margin-top: 0.55rem;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--muted);
    background: rgba(26,23,20,0.05);
    padding: 0.3rem 0.5rem;
    border-radius: 3px;
}

/* ── Citation box ── */
.citation-box {
    margin-top: 2rem;
    padding: 0.85rem 1.1rem;
    background: var(--cream);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.78rem;
    color: var(--muted);
    line-height: 1.65;
}
.citation-box a { color: var(--rust); text-decoration: none; }
.citation-box a:hover { text-decoration: underline; }

/* ── Footer ── */
footer {
    margin-top: 3rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--muted);
    letter-spacing: 0.04em;
}
footer a { color: var(--muted); text-decoration: none; }
footer a:hover { color: var(--rust); }

/* ── Responsive ── */
@media (max-width: 768px) {
    .container { padding: 2rem 1.25rem 3rem; }
    .task-boxes { grid-template-columns: 1fr; }
    .landing-cards { grid-template-columns: 1fr; }
    .landing-container { max-width: 100%; }
}

@media (max-width: 600px) {
    .container { padding: 1.5rem 1rem 2.5rem; }

    /* Header */
    .logo-it, .logo-5 { font-size: 2.2rem; }
    .subtitle { font-size: 0.85rem; }

    /* Top bar */
    .top-bar { margin-bottom: 1.25rem; }
    .lab-logo img { height: 28px; }

    /* Task tabs — horizontal scroll instead of column stack */
    .task-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        border-radius: 0;
    }
    .tab-btn {
        min-width: 110px;
        flex-shrink: 0;
        padding: 0.75rem 0.5rem;
    }
    .tab-label { font-size: 0.72rem; }
    .tab-desc { font-size: 0.62rem; }

    /* Fields */
    .fields-grid { grid-template-columns: 1fr; }
    .field-group.full-width { grid-column: auto; }
    .panel-title { flex-direction: column; gap: 0.25rem; }

    /* Results */
    .results-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    .results-header { flex-direction: column; }
    .results-meta { align-items: flex-start; }

    /* Landing */
    .task-boxes { grid-template-columns: 1fr; }
    .landing-cards { grid-template-columns: 1fr; }
    .landing-card { padding: 1.25rem 1rem; gap: 0.85rem; }
    .landing-card-icon { font-size: 1.4rem; }

    /* Modal */
    .modal-overlay { padding: 0.75rem; align-items: flex-end; }
    .modal-box { padding: 1.5rem 1.1rem; max-height: 92vh; border-radius: 8px 8px 0 0; }

    /* Citation */
    .citation-box { font-size: 0.73rem; }

    /* Footer */
    footer { font-size: 0.7rem; line-height: 1.8; }
}
