:root {
    --blue: #1e5bd6;
    --blue-dark: #143984;
    --hero: #8f94f2;
    --hero-deep: #6d74e8;
    --paper: #fafafa;
    --ink: #1c1c1c;
    --muted: #5c5c5c;
    --line: rgba(28, 28, 28, 0.12);
    --ok: #15803d;
    --danger: #dc2626;
    --warn: #ca8a04;
    --font: "Outfit", sans-serif;
    --per: #38bdf8;
    --org: #a78bfa;
    --loc: #34d399;
    --misc: #fbbf24;
    --gpe: #2dd4bf;
    --fac: #fb7185;
    --norp: #c084fc;
    --date: #60a5fa;
    --time: #818cf8;
    --cardinal: #f59e0b;
    --ordinal: #f97316;
    --quantity: #84cc16;
    --percent: #14b8a6;
    --money: #4ade80;
    --event: #f472b6;
    --product: #22d3ee;
    --law: #e879f9;
    --language: #67e8f9;
    --art: #fda4af;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 5.5rem;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
}

body.is-home {
    background: var(--hero);
}

a {
    color: inherit;
    text-decoration: none;
}

button,
.product-card,
.logo,
.discover,
.ghost-btn,
.sample-chip,
.primary-btn,
.site-nav a,
.scroll-hint {
    cursor: pointer;
}

.site-header {
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0.85rem 1.25rem;
}

.is-home .site-header {
    position: fixed;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    width: auto;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0.85rem 1.4rem;
    background: #9b9ef3;
    color: #fff;
    border-radius: 6px;
}

.is-home .site-header::after {
    content: "";
}

.is-home .logo {
    justify-self: start;
}

.is-home .site-nav {
    margin: 0;
    justify-self: center;
}

.is-app .site-header {
    position: relative;
    flex-shrink: 0;
    width: 100%;
    min-height: 4.5rem;
    padding: 0.85rem 2rem;
    background: #fff;
    color: var(--ink);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 12px 32px rgba(20, 57, 132, 0.06);
}

.site-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-left: auto;
}

.is-app .site-nav {
    margin-left: 0.35rem;
}

.is-app .header-aside {
    margin-left: auto;
}

.site-nav a {
    padding: 0.52rem 0.95rem;
    border-radius: 999px;
    color: inherit;
    font-size: 0.92rem;
    font-weight: 500;
    line-height: 1;
    transition: background-color 180ms ease, color 180ms ease;
}

.is-home .site-nav a:hover,
.is-home .site-nav a:focus-visible {
    background: rgba(255, 255, 255, 0.2);
}

.is-home .site-nav a.is-active {
    background: #fff;
    color: var(--blue-dark);
}

.is-app .site-nav a:hover,
.is-app .site-nav a:focus-visible {
    background: #eef3ff;
}

.is-app .site-nav a.is-active {
    background: var(--blue);
    color: #fff;
}

.header-aside {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.is-app .health-panel {
    background: #f4f7ff;
    border-color: color-mix(in srgb, var(--blue) 18%, white);
}

.logo {
    display: inline-flex;
    align-items: center;
    font-size: 1.85rem;
    font-weight: 400;
    letter-spacing: -0.04em;
    line-height: 1;
}

.logo-o {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.18rem;
    width: 0.72em;
    height: 0.9em;
    margin: 0 0.04em;
}

.logo-o i {
    display: block;
    width: 0.38em;
    height: 0.38em;
    margin: 0 auto;
    background: currentColor;
    border-radius: 50%;
}

.hero-screen {
    min-height: 100svh;
    display: grid;
    place-items: center;
    padding: 7rem 1.5rem 4rem;
    background:
        linear-gradient(180deg, rgba(30, 91, 214, 0.28), rgba(111, 118, 236, 0.2)),
        radial-gradient(circle at 50% 42%, #b7bbff 0%, var(--hero) 46%, #7a80ea 100%);
    color: #fff;
    text-align: center;
}

.hero-copy {
    display: grid;
    justify-items: center;
    text-align: center;
}

.hero-title {
    margin: 0;
    max-width: 16ch;
    font-size: clamp(2.6rem, 7vw, 5.4rem);
    font-weight: 400;
    letter-spacing: -0.045em;
    line-height: 1.08;
}

.hero-sub {
    margin: 1.4rem 0 0;
    max-width: 28ch;
    color: rgba(255, 255, 255, 0.9);
    font-size: clamp(1.05rem, 2.2vw, 1.25rem);
    line-height: 1.45;
}

.scroll-hint {
    position: absolute;
    bottom: 1.6rem;
    left: 0;
    right: 0;
    color: rgba(255, 255, 255, 0.82);
    font-size: 0.92rem;
}

.hero-screen {
    position: relative;
}

.modules-band,
.polarity-band,
.story-band,
.workspace {
    padding: 5rem 1.25rem;
}

.polarity-band {
    background: #fff;
}

.polarity-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
    max-width: 1180px;
    margin: 0 auto;
}

.polarity-card {
    min-height: 280px;
    padding: 2rem;
    border-radius: 8px;
}

.polarity-card.is-positive {
    background: #ecf8ef;
    color: #14532d;
}

.polarity-card.is-negative {
    background: #fdecec;
    color: #7f1d1d;
}

.polarity-kicker {
    margin: 0 0 0.8rem;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.polarity-card h2 {
    margin: 0 0 0.8rem;
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 400;
    letter-spacing: -0.04em;
}

.polarity-card p {
    margin: 0 0 1.4rem;
    max-width: 38ch;
    line-height: 1.6;
}

.polarity-tag {
    display: inline-block;
    padding: 0.45rem 0.7rem;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 6px;
    font-weight: 600;
}

.polarity-tag.is-negated {
    text-decoration: line-through;
}

.polarity-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.7rem 1rem;
    margin: 0.7rem 0 0.25rem;
}

.polarity-legend p {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.polarity-chip {
    display: inline-flex;
    padding: 0.28rem 0.7rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.polarity-chip.is-positive {
    color: #14532d;
    background: #dcfce7;
}

.polarity-chip.is-negative {
    color: #7f1d1d;
    background: #fee2e2;
    text-decoration: line-through;
}

.modules-band {
    background: var(--paper);
}

.band-kicker {
    margin: 0 0 1.5rem;
    color: var(--muted);
    font-size: 0.82rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.product-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
    max-width: 1180px;
    margin: 0 auto;
}

.product-card {
    min-height: 420px;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    background: var(--blue);
    color: #fff;
    border-radius: 8px;
    transition: background-color 200ms ease;
}

.product-card:hover {
    background: var(--blue-dark);
}

.product-index {
    margin: 0 0 auto;
    opacity: 0.7;
    font-size: 0.9rem;
}

.product-card h2 {
    margin: 0 0 0.8rem;
    font-size: clamp(2.2rem, 4vw, 3.4rem);
    font-weight: 400;
    letter-spacing: -0.04em;
}

.product-card p {
    margin: 0 0 2rem;
    max-width: 34ch;
    color: rgba(255, 255, 255, 0.88);
    line-height: 1.55;
}

.discover {
    margin-top: auto;
    font-weight: 500;
}

.story-band {
    background: var(--paper);
}

.story-band h2 {
    margin: 0 auto 2.5rem;
    max-width: 1180px;
    font-size: clamp(2rem, 4.5vw, 3.4rem);
    font-weight: 400;
    letter-spacing: -0.04em;
}

.story-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2rem;
    max-width: 1180px;
    margin: 0 auto;
}

.story-grid h3 {
    margin: 0 0 0.7rem;
    font-size: 1.4rem;
    font-weight: 500;
}

.story-grid p {
    margin: 0;
    color: var(--muted);
    line-height: 1.65;
}

.site-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.45rem 1.5rem;
    padding: 0.75rem 1.5rem;
    background: #fff;
    border-top: 1px solid var(--line);
}

.footer-copy {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.2rem 0.85rem;
}

.footer-copy p {
    margin: 0;
    max-width: none;
    font-size: 0.88rem;
    letter-spacing: 0;
}

.footer-copy .footer-legal,
.footer-copy .footer-powered {
    margin-top: 0;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 400;
}

.footer-meta {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    color: var(--muted);
    font-size: 0.8rem;
}

.footer-meta a:hover {
    color: var(--blue);
}

.is-app {
    height: 100svh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.is-app main {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1680px;
    margin: 0 auto;
    padding: 1.15rem 2rem 0.75rem;
    min-height: 0;
    overflow: hidden;
}

.is-app .workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 0;
    overflow: hidden;
}

.is-app .site-footer {
    flex-shrink: 0;
    padding: 0.45rem 2rem;
}

.is-app .footer-copy p:first-child {
    font-size: 0.8rem;
}

.workspace-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
}

.workspace-head > div {
    flex: 1;
}

.eyebrow {
    margin: 0 0 0.6rem;
    color: var(--blue);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.workspace h1 {
    margin: 0 0 0.75rem;
    font-size: clamp(2.4rem, 4vw, 4.2rem);
    font-weight: 400;
    letter-spacing: -0.04em;
}

.is-app .workspace h1 {
    margin: 0 0 0.3rem;
    font-size: clamp(1.55rem, 2.2vw, 2.2rem);
}

.is-app .lede {
    font-size: 0.95rem;
}

.lede {
    margin: 0;
    max-width: 72ch;
    color: var(--muted);
    font-size: 1.08rem;
    line-height: 1.65;
}

.health-panel {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.65rem 0.9rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 999px;
    white-space: nowrap;
}

.health-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
}

.health-dot[data-health="ok"] { background: var(--ok); }
.health-dot[data-health="loading"] { background: var(--warn); }
.health-dot[data-health="down"] { background: var(--danger); }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.35rem 0 0.65rem;
    padding: 0;
    list-style: none;
}

.type-pill {
    display: inline-flex;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    background: #e8eefc;
    color: var(--blue-dark);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.workspace-head,
.polarity-legend,
.legend {
    flex-shrink: 0;
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.25rem;
    flex: 1;
    min-height: 0;
    align-items: stretch;
    overflow: hidden;
}

.panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 1.35rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.9rem;
    flex-shrink: 0;
}

.panel-head h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 500;
}

textarea {
    width: 100%;
    flex: 1;
    min-height: 0;
    padding: 1.1rem 1.2rem;
    resize: none;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 10px;
    font: 1rem/1.65 var(--font);
}

textarea:focus,
.primary-btn:focus-visible,
.ghost-btn:focus-visible,
.sample-chip:focus-visible,
.product-card:focus-visible,
.logo:focus-visible,
.site-nav a:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 3px;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.9rem;
}

.sample-chip,
.ghost-btn {
    padding: 0.45rem 0.8rem;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 999px;
    font: 0.8rem/1 var(--font);
    font-weight: 500;
    transition: border-color 200ms ease, background-color 200ms ease;
}

.sample-chip:hover,
.ghost-btn:hover {
    background: #eef3ff;
    border-color: color-mix(in srgb, var(--blue) 40%, white);
}

.actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.primary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 148px;
    min-height: 46px;
    padding: 0.8rem 1.2rem;
    color: #fff;
    background: var(--blue);
    border: 0;
    border-radius: 999px;
    font: 0.95rem/1 var(--font);
    font-weight: 600;
    transition: background-color 200ms ease;
}

.primary-btn:hover {
    background: var(--blue-dark);
}

.primary-btn:disabled {
    cursor: wait;
    opacity: 0.7;
}

.btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.hint,
.form-status,
.empty-state p {
    margin: 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.form-status {
    min-height: 1.2rem;
    margin-top: 0.8rem;
}

.form-status.is-error {
    color: var(--danger);
}

.stats {
    display: flex;
    gap: 1rem;
    color: var(--muted);
    font-size: 0.85rem;
}

.stats strong {
    color: var(--ink);
}

.empty-state {
    flex: 1;
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
    text-align: center;
}

.empty-state p {
    max-width: 42ch;
}

#composer {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

#results,
.table-wrap {
    flex: 1 1 0%;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
}

.annotated {
    flex: 1 1 0%;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 1.1rem 1.2rem;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 10px;
    line-height: 1.9;
    font-size: 1.05rem;
}

.entity-chip,
.entity-anchor {
    scroll-margin: 2.4rem 0;
}

.entity-chip {
    padding: 0.05rem 0.28rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
}

.entity-chip.is-active {
    outline: 2px solid var(--blue);
    box-shadow: 0 0 0 3px rgba(30, 91, 214, 0.22);
}

.entity-chip.is-negated {
    text-decoration: line-through;
    outline: 2px solid var(--danger);
}

.table-wrap {
    margin-top: 0;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.results-table th,
.results-table td {
    padding: 0.75rem 0.55rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.results-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #fff;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.entity-row {
    cursor: pointer;
    transition: background-color 160ms ease;
}

.entity-row:hover {
    background: #f4f7ff;
}

.entity-row.is-active {
    background: #e8eefc;
}

.neg-yes { color: var(--danger); font-weight: 700; }
.neg-no { color: var(--ok); font-weight: 700; }

[hidden] { display: none !important; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.type-PER, .type-PERSON { color: #082f49; background: var(--per); }
.type-ORG { color: #2e1065; background: var(--org); }
.type-LOC { color: #064e3b; background: var(--loc); }
.type-MISC { color: #451a03; background: var(--misc); }
.type-GPE { color: #042f2e; background: var(--gpe); }
.type-FAC { color: #4c0519; background: var(--fac); }
.type-NORP { color: #3b0764; background: var(--norp); }
.type-DATE { color: #1e3a8a; background: var(--date); }
.type-TIME { color: #312e81; background: var(--time); }
.type-CARDINAL { color: #451a03; background: var(--cardinal); }
.type-ORDINAL { color: #431407; background: var(--ordinal); }
.type-QUANTITY { color: #1a2e05; background: var(--quantity); }
.type-PERCENT { color: #134e4a; background: var(--percent); }
.type-MONEY { color: #052e16; background: var(--money); }
.type-EVENT { color: #500724; background: var(--event); }
.type-PRODUCT { color: #083344; background: var(--product); }
.type-LAW { color: #4a044e; background: var(--law); }
.type-LANGUAGE { color: #083344; background: var(--language); }
.type-WORK_OF_ART { color: #4c0519; background: var(--art); }

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 900px) {
    .product-row,
    .polarity-grid,
    .story-grid,
    .workspace-grid,
    .workspace-head {
        grid-template-columns: 1fr;
        display: grid;
    }

    .product-card {
        min-height: 320px;
    }

    .workspace-grid {
        min-height: 0;
        overflow: auto;
    }

    textarea {
        min-height: 180px;
    }
}

@media (max-width: 640px) {
    .is-home .site-header {
        left: 0.7rem;
        right: 0.7rem;
        padding: 0.7rem 0.9rem;
        width: auto;
        max-width: none;
    }

    .is-app .site-header {
        padding: 0.7rem 1rem;
        min-height: 0;
        flex-wrap: wrap;
        row-gap: 0.55rem;
    }

    .is-app .site-nav {
        width: 100%;
        margin-left: 0;
        order: 3;
    }

    .is-app .header-aside {
        margin-left: auto;
    }

    .site-nav a {
        font-size: 0.82rem;
        padding: 0.42rem 0.7rem;
    }

    .modules-band,
    .polarity-band,
    .story-band {
        padding: 3.2rem 1rem;
    }

    .is-app main {
        padding: 0.85rem 1rem 0.75rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
