*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
    font-family: 'Montserrat', sans-serif;
    font-size: 15px;
    background: #fff;
    color: #1a1a1a;
    line-height: 1.6;
}

/* ----------------------------------------------------------------
   Layout
---------------------------------------------------------------- */

header {
    padding: 18px 32px;
    border-bottom: 1px solid #eee;
}

main {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px 24px 80px;
}

footer {
    text-align: center;
    padding: 24px;
    color: #888;
    font-size: 13px;
    border-top: 1px solid #eee;
}

h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 24px;
}

h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;
}

section { margin-bottom: 8px; }

hr {
    border: none;
    border-top: 1px solid #eee;
    margin: 28px 0;
}

.caption {
    font-size: 13px;
    color: #666;
    margin-bottom: 14px;
}

/* ----------------------------------------------------------------
   Input
---------------------------------------------------------------- */

.input-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.input-group {
    flex: 1;
    min-width: 200px;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #444;
}

.input-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-family: inherit;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.input-group input:focus { border-color: #800080; }

/* ----------------------------------------------------------------
   Buttons
---------------------------------------------------------------- */

.btn-primary {
    background: #800080;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 10px 24px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.btn-primary:hover { background: #600060; }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }

.btn-large {
    padding: 14px 40px;
    font-size: 16px;
}

.center { text-align: center; }

/* ----------------------------------------------------------------
   Loading
---------------------------------------------------------------- */

#loading, #deep-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 0;
    color: #555;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 4px solid #eee;
    border-top-color: #800080;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------
   Alerts
---------------------------------------------------------------- */

.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-error { background: #fff0f0; border: 1px solid #fcc; color: #c00; }
.alert-success { background: #f0fff4; border: 1px solid #c3e6cb; color: #1a5c2a; }
.alert-info { background: #f0f4ff; border: 1px solid #c3d0f0; color: #1a3c8a; }

/* ----------------------------------------------------------------
   Familiarity
---------------------------------------------------------------- */

#familiarity-score-display {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 10px;
}

#familiarity-bar-wrap {
    background: #f0f0f0;
    border-radius: 6px;
    height: 18px;
    margin-bottom: 18px;
    overflow: hidden;
}

#familiarity-bar {
    height: 100%;
    border-radius: 6px;
    background: #800080;
    transition: width 0.6s ease;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 8px;
}

.two-col .col-label {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #444;
}

.two-col .col-body {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 14px;
    color: #333;
}

.two-col .col-body.grounded { border-color: #c3e6cb; background: #f0fff4; }

/* ----------------------------------------------------------------
   Word tokens
---------------------------------------------------------------- */

#uncertainty-output, #rarity-output {
    line-height: 2.2;
    margin-bottom: 14px;
}

#uncertainty-output span, #rarity-output span {
    display: inline-block;
    padding: 2px 6px;
    margin: 2px;
    border-radius: 4px;
    font-size: 14px;
}

/* ----------------------------------------------------------------
   Legends
---------------------------------------------------------------- */

.legend-wrap { margin-top: 8px; }

.legend {
    height: 14px;
    border-radius: 6px;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #666;
    margin-top: 4px;
}

.uncertainty-legend {
    background: linear-gradient(to right, rgba(255,165,0,0), rgba(255,165,0,0.5), rgba(255,165,0,1));
}

.rarity-legend {
    background: linear-gradient(to right, rgba(128,0,128,0), rgba(128,0,128,0.5), rgba(128,0,128,1));
}

/* ----------------------------------------------------------------
   Charts
---------------------------------------------------------------- */

.chart-wrap {
    position: relative;
    margin-top: 10px;
}

.chart-wrap-sm { max-height: 260px; }

/* ----------------------------------------------------------------
   Heatmap table
---------------------------------------------------------------- */

.heatmap-scroll { overflow-x: auto; }

.heatmap {
    border-collapse: collapse;
    font-size: 12px;
    min-width: 400px;
}

.heatmap th {
    background: #f5f5f5;
    padding: 6px 10px;
    font-weight: 600;
    text-align: center;
    border: 1px solid #e0e0e0;
    white-space: nowrap;
}

.heatmap td {
    padding: 4px 8px;
    border: 1px solid #e8e8e8;
    text-align: center;
    min-width: 70px;
}

.heatmap-token {
    font-weight: 600;
    background: #fafafa;
    text-align: left;
    white-space: nowrap;
}

/* ----------------------------------------------------------------
   Deep analysis
---------------------------------------------------------------- */

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.metric {
    background: #f9f9f9;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.metric-value {
    font-size: 26px;
    font-weight: 700;
    color: #800080;
}

.metric-label {
    font-size: 13px;
    color: #666;
    margin-top: 4px;
}

.interpretation-box {
    background: #fafafa;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 20px 24px;
    line-height: 1.8;
    font-size: 14px;
}

.interpretation-box h1,
.interpretation-box h2,
.interpretation-box h3 { margin: 16px 0 8px; }

.interpretation-box ul, .interpretation-box ol { padding-left: 20px; margin: 8px 0; }
.interpretation-box li { margin-bottom: 4px; }
.interpretation-box p { margin-bottom: 10px; }
.interpretation-box strong { font-weight: 700; }
.interpretation-box em { font-style: italic; }
.interpretation-box hr { margin: 12px 0; }

.branch {
    margin-bottom: 16px;
}

.branch p { font-size: 14px; margin-bottom: 4px; }
.branch hr { margin: 16px 0 0; }

/* ----------------------------------------------------------------
   Help tooltip
---------------------------------------------------------------- */

.help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: #ddd;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    color: #555;
    cursor: default;
    vertical-align: middle;
}

/* ----------------------------------------------------------------
   Responsive
---------------------------------------------------------------- */

@media (max-width: 600px) {
    .two-col { grid-template-columns: 1fr; }
    .metrics-grid { grid-template-columns: 1fr 1fr; }
}