@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&family=Source+Sans+3:wght@400;600;700&display=swap');

:root {
    --bg-a: #09141f;
    --bg-b: #142737;
    --bg-c: #1f3f48;
    --surface: rgba(10, 26, 34, 0.72);
    --surface-strong: rgba(14, 33, 42, 0.86);
    --surface-soft: rgba(7, 20, 29, 0.8);
    --border: rgba(203, 238, 255, 0.2);
    --text: #eef8ff;
    --muted: rgba(238, 248, 255, 0.72);
    --accent: #50d3c6;
    --accent-strong: #f5bf50;
    --ok: #47d796;
    --bad: #ff8b79;
    --meter-bg: rgba(15, 42, 52, 0.95);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 22px;
    color: var(--text);
    font-family: "Space Grotesk", "Avenir Next", sans-serif;
    background: linear-gradient(145deg, var(--bg-a), var(--bg-b) 50%, var(--bg-c));
    line-height: 1.55;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: -30%;
    background:
        radial-gradient(45% 45% at 12% 20%, rgba(80, 211, 198, 0.2), transparent 68%),
        radial-gradient(40% 42% at 83% 23%, rgba(245, 191, 80, 0.16), transparent 70%),
        radial-gradient(42% 40% at 50% 78%, rgba(110, 178, 255, 0.14), transparent 70%);
    pointer-events: none;
    z-index: 0;
}

.page-shell {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.hero,
.generator,
.stats-area,
.quiz-area {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 22px;
    backdrop-filter: blur(8px);
}

.hero,
.generator,
.stats-area {
    margin-bottom: 16px;
}

.hero {
    text-align: center;
}

.hero h1 {
    margin: 12px 0 8px;
    letter-spacing: 0.4px;
}

.hero p {
    margin: 0;
    color: var(--muted);
}

.back-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid rgba(80, 211, 198, 0.35);
    color: var(--text);
    text-decoration: none;
    background: rgba(12, 35, 44, 0.65);
}

h2 {
    margin: 0 0 10px;
}

.api-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--muted);
    font-size: 14px;
}

.field input,
.field select {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    border-radius: 12px;
    border: 1px solid rgba(80, 211, 198, 0.45);
    background: rgba(7, 20, 29, 0.85);
    color: var(--text);
    font-size: 14px;
}

.field input:focus,
.field select:focus {
    outline: none;
    border-color: rgba(80, 211, 198, 0.8);
    box-shadow: 0 0 0 3px rgba(80, 211, 198, 0.18);
}

.field select {
    appearance: none;
    cursor: pointer;
}

.generator-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

button {
    min-height: 42px;
    padding: 0 20px;
    border-radius: 999px;
    border: 1px solid rgba(245, 191, 80, 0.5);
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #08222d;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 180ms ease;
}

button:hover {
    transform: translateY(-1px);
}

button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.button-subtle {
    border-color: rgba(203, 238, 255, 0.2);
    background: rgba(11, 30, 40, 0.95);
    color: var(--text);
}

.status {
    margin: 0;
    color: var(--muted);
}

.status.error {
    color: #ffc2b7;
}

.status.success {
    color: #b6f5d9;
}

.status.pending {
    color: #cbeeff;
}

.generator-note {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.stats-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.stats-updated {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.stats-grid {
    margin-top: 12px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
}

.stat-card {
    margin: 0;
    border: 1px solid rgba(203, 238, 255, 0.14);
    border-radius: 14px;
    padding: 10px 12px;
    background: rgba(8, 24, 32, 0.85);
}

.stat-label {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.35px;
}

.stat-value {
    margin: 4px 0 0;
    font-size: 28px;
    line-height: 1.1;
    font-weight: 700;
    color: var(--accent);
}

.viz-grid {
    margin-top: 12px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 10px;
}

.viz-card {
    border: 1px solid rgba(203, 238, 255, 0.14);
    border-radius: 14px;
    padding: 12px;
    background: rgba(8, 24, 32, 0.85);
}

.viz-label {
    margin: 0 0 8px;
    font-size: 13px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.35px;
}

.viz-value {
    margin: 7px 0 0;
    font-weight: 600;
}

.meter {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--meter-bg);
    border: 1px solid rgba(203, 238, 255, 0.14);
}

.meter-fill {
    width: 0;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent), var(--accent-strong));
    transition: width 220ms ease;
}

.streak-fill {
    background: linear-gradient(90deg, #8deeb9, #f5bf50);
}

.history-panel {
    margin-top: 12px;
    border: 1px solid rgba(203, 238, 255, 0.14);
    border-radius: 14px;
    padding: 12px;
    background: rgba(8, 24, 32, 0.85);
}

.history-bars {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(18px, 1fr));
    align-items: end;
    gap: 6px;
    min-height: 90px;
}

.history-bar {
    border-radius: 8px 8px 4px 4px;
    border: 1px solid rgba(203, 238, 255, 0.16);
    background: linear-gradient(180deg, #9ad7ff, #50d3c6);
    min-height: 18px;
}

.history-bar.pending {
    background: rgba(203, 238, 255, 0.2);
}

.quiz-area {
    background: var(--surface-strong);
}

.reference-area {
    margin-top: 16px;
}

.functional-sheet {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 16px 18px;
}

.functional-sheet summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--accent);
    user-select: none;
}

.functional-sheet summary::marker {
    color: var(--accent-strong);
}

.sheet-note {
    margin: 12px 0 8px;
    color: var(--muted);
    font-size: 16px;
}

.sheet-table-wrap {
    overflow-x: auto;
}

.sheet-table {
    width: 100%;
    border-collapse: collapse;
    font-family: "Source Sans 3", "Segoe UI", sans-serif;
    font-size: 16px;
    background: rgba(8, 24, 32, 0.75);
    border: 1px solid rgba(203, 238, 255, 0.15);
    border-radius: 12px;
}

.sheet-table th,
.sheet-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid rgba(203, 238, 255, 0.12);
    vertical-align: middle;
}

.sheet-table th {
    color: var(--accent-strong);
    font-family: "Space Grotesk", "Avenir Next", sans-serif;
    font-size: 13px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.sheet-table tbody tr:last-child td {
    border-bottom: none;
}

.sheet-formula {
    display: inline-flex;
    align-items: flex-end;
    gap: 0;
    padding: 4px 8px;
    border-radius: 8px;
    border: 1px solid rgba(203, 238, 255, 0.14);
    background: rgba(6, 18, 25, 0.85);
    font-family: "IBM Plex Mono", "Consolas", monospace;
    font-size: 16px;
    line-height: 1.1;
}

.sheet-formula .token-count {
    margin-right: 0;
}

.sheet-bond-hint {
    margin-left: 8px;
    color: var(--muted);
    font-size: 14px;
}

.shape-svg {
    display: block;
    width: 190px;
    max-width: 100%;
    height: 46px;
}

.shape-line {
    stroke: rgba(203, 238, 255, 0.9);
    stroke-width: 2.2;
    stroke-linecap: round;
}

.shape-text {
    fill: #ecf8ff;
    font-family: "IBM Plex Mono", "Consolas", monospace;
    font-size: 12px;
    font-weight: 600;
}

.quiz-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

#iupac-progress {
    margin: 0;
    color: var(--accent);
    font-weight: 600;
}

.quiz-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
}

.iupac-card {
    background: var(--surface-soft);
    border: 1px solid rgba(203, 238, 255, 0.15);
    border-radius: 18px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: card-rise 280ms ease-out;
    position: relative;
    isolation: isolate;
    overflow: hidden;
}

.iupac-card.is-correct {
    border-color: rgba(71, 215, 150, 0.85);
}

.iupac-card.is-wrong {
    border-color: rgba(255, 139, 121, 0.85);
}

.iupac-card > * {
    position: relative;
    z-index: 1;
}

.iupac-card.flash-green::after {
    content: "";
    position: absolute;
    inset: -35%;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 18% 28%, rgba(151, 255, 207, 0.45), transparent 52%),
        radial-gradient(circle at 80% 70%, rgba(106, 236, 255, 0.32), transparent 55%),
        linear-gradient(
            120deg,
            rgba(71, 215, 150, 0) 20%,
            rgba(71, 215, 150, 0.55) 47%,
            rgba(245, 191, 80, 0.45) 52%,
            rgba(71, 215, 150, 0) 80%
        );
    mix-blend-mode: screen;
    filter: blur(6px);
    animation: iupac-correct-shader 950ms ease-out forwards;
}

.iupac-card.flash-green {
    animation: iupac-correct-pulse 950ms ease-out;
}

.card-label {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.compound-panel {
    border-radius: 14px;
    border: 1px solid rgba(80, 211, 198, 0.3);
    background: linear-gradient(150deg, rgba(15, 40, 50, 0.92), rgba(10, 26, 36, 0.9));
    padding: 12px 14px;
    position: relative;
}

.compound-visual {
    font-family: "IBM Plex Mono", "Consolas", monospace;
    font-size: 24px;
    font-weight: 600;
    line-height: 1.3;
    overflow-wrap: anywhere;
    display: inline-block;
    max-width: 100%;
    cursor: help;
    border-radius: 8px;
    padding: 2px 4px;
    margin: -2px -4px 0;
}

.compound-visual:focus-visible {
    outline: 2px solid rgba(80, 211, 198, 0.85);
    outline-offset: 2px;
}

.compound-raw {
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
}

.compound-hint {
    margin-top: 6px;
    color: rgba(203, 238, 255, 0.78);
    font-size: 12px;
}

.compound-explainer {
    margin-top: 0;
    border: 0 solid rgba(80, 211, 198, 0.35);
    border-radius: 12px;
    background: rgba(9, 31, 41, 0.95);
    padding: 0 11px;
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    pointer-events: none;
    transition: opacity 140ms ease, max-height 180ms ease, padding 180ms ease, margin 180ms ease;
}

.compound-explainer.is-visible {
    opacity: 1;
    max-height: 260px;
    margin-top: 8px;
    border-width: 1px;
    padding: 10px 11px;
    overflow-y: auto;
    pointer-events: auto;
}

.compound-explainer-title {
    margin: 0 0 6px;
    color: #9feadf;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.35px;
}

.compound-explainer-body {
    margin: 0;
    color: #dbf3ff;
    font-size: 13px;
    line-height: 1.45;
}

.token-el {
    font-weight: 700;
}

.token-count {
    font-size: 0.72em;
    vertical-align: sub;
    margin-right: 2px;
    color: rgba(238, 248, 255, 0.92);
}

.token-bond {
    color: #ffd38d;
    margin: 0 1px;
}

.el-c {
    color: #79e6a2;
}

.el-h {
    color: #9ad7ff;
}

.el-o {
    color: #ff9f8f;
}

.el-n {
    color: #a8c2ff;
}

.el-s {
    color: #ffe089;
}

.el-p {
    color: #ffb57a;
}

.el-f,
.el-cl,
.el-br,
.el-i {
    color: #d6ff9e;
}

.el-default {
    color: #e7f3ff;
}

.answer-label {
    color: var(--muted);
    font-size: 14px;
}

.answer-row {
    display: flex;
    gap: 8px;
}

.answer-input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(203, 238, 255, 0.22);
    background: rgba(5, 15, 22, 0.9);
    color: var(--text);
    font-size: 15px;
}

.answer-input:focus {
    outline: none;
    border-color: rgba(80, 211, 198, 0.8);
    box-shadow: 0 0 0 3px rgba(80, 211, 198, 0.2);
}

.feedback {
    min-height: 24px;
    margin: 0;
    font-size: 14px;
    color: var(--muted);
}

.feedback.ok {
    color: #b6f5d9;
}

.feedback.bad {
    color: #ffc2b7;
}

.empty {
    margin: 8px 0 0;
    color: var(--muted);
}

@keyframes card-rise {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes iupac-correct-shader {
    0% {
        opacity: 0;
        transform: translateX(-26%) scale(0.94);
    }
    20% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translateX(26%) scale(1.08);
    }
}

@keyframes iupac-correct-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(71, 215, 150, 0.5);
    }
    45% {
        box-shadow: 0 0 0 8px rgba(71, 215, 150, 0.15);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(71, 215, 150, 0);
    }
}

@media (max-width: 700px) {
    body {
        padding: 12px;
    }

    .hero,
    .generator,
    .stats-area,
    .quiz-area {
        padding: 16px;
        border-radius: 16px;
    }

    .compound-visual {
        font-size: 21px;
    }

    .answer-row {
        flex-direction: column;
    }

    .generator-actions {
        flex-direction: column;
        align-items: stretch;
    }
}
