:root {
    --bg: #05070d;
    --bg-2: #09111f;
    --panel: rgba(13, 22, 38, 0.78);
    --panel-solid: #0d1626;
    --panel-soft: #111d31;
    --line: rgba(156, 196, 255, 0.16);
    --line-strong: rgba(117, 233, 255, 0.36);
    --text: #edf7ff;
    --muted: #91a5bd;
    --soft: #c9d7e8;
    --accent: #46e6ff;
    --accent-2: #9cff6d;
    --accent-3: #b78cff;
    --danger: #ff6b8a;
    --warning: #ffd166;
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
    --radius: 18px;
}

:root.light {
    --bg: #edf4f8;
    --bg-2: #f8fbff;
    --panel: rgba(255, 255, 255, 0.82);
    --panel-solid: #ffffff;
    --panel-soft: #f3f8fc;
    --line: rgba(21, 41, 64, 0.12);
    --line-strong: rgba(18, 128, 166, 0.24);
    --text: #0d1726;
    --muted: #506174;
    --soft: #203248;
    --shadow: 0 24px 80px rgba(45, 72, 104, 0.18);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    overflow: hidden;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 50% 18%, rgba(70, 230, 255, 0.16), transparent 30%),
        radial-gradient(circle at 88% 10%, rgba(183, 140, 255, 0.16), transparent 28%),
        linear-gradient(135deg, var(--bg), var(--bg-2));
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.28;
    background-image:
        linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: radial-gradient(circle at 50% 40%, black, transparent 74%);
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    border: 0;
    color: inherit;
    cursor: pointer;
}

.app-shell {
    height: 100vh;
    display: grid;
    grid-template-columns: minmax(260px, 300px) minmax(0, 1fr) minmax(280px, 340px);
    grid-template-rows: 72px minmax(0, 1fr);
    gap: 14px;
    padding: 14px;
}

.topbar {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 310px minmax(280px, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: linear-gradient(135deg, rgba(16, 29, 50, 0.9), rgba(7, 13, 24, 0.72));
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

:root.light .topbar {
    background: rgba(255, 255, 255, 0.78);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    background: transparent;
}

.brand-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 15px;
    color: #031018;
    font-weight: 900;
    letter-spacing: -0.04em;
    background: conic-gradient(from 140deg, var(--accent), var(--accent-2), var(--accent-3), var(--accent));
    box-shadow: 0 0 34px rgba(70, 230, 255, 0.42);
}

.brand strong,
.panel h2,
.stage h1 {
    letter-spacing: -0.03em;
}

.brand strong {
    display: block;
    font-size: 16px;
}

.brand small {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
}

.command-bar {
    min-width: 0;
    height: 48px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(4, 9, 18, 0.5);
}

:root.light .command-bar {
    background: rgba(244, 249, 253, 0.9);
}

.command-bar input {
    width: 100%;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
}

.command-bar input::placeholder {
    color: var(--muted);
}

kbd,
.mono {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
}

kbd {
    min-width: 26px;
    padding: 4px 7px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
}

.top-actions,
.hud,
.mini-actions,
.filter-grid {
    display: flex;
    align-items: center;
    gap: 8px;
}

.left-rail,
.right-rail,
.stage {
    min-height: 0;
}

.panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.left-rail,
.right-rail {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 14px;
}

.library-panel,
.inspector {
    min-height: 0;
    overflow: hidden;
}

.library-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 16px;
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

.panel h2 {
    margin: 0;
    font-size: 24px;
}

.stage {
    display: grid;
    grid-template-rows: auto minmax(320px, 1fr) auto minmax(190px, 0.5fr);
    gap: 14px;
    min-width: 0;
}

.stage-top {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 20px;
}

.stage h1 {
    margin: 0;
    font-size: clamp(34px, 4.7vw, 68px);
    line-height: 0.92;
}

#moleculeSubtitle {
    margin: 10px 0 0;
    color: var(--soft);
    font-size: 15px;
}

.score-card {
    min-width: 150px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(8, 15, 28, 0.56);
}

:root.light .score-card {
    background: rgba(255, 255, 255, 0.72);
}

.score-card span,
.score-card small,
.metric-grid span,
.atom-readout span,
.feature-card span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.score-card strong {
    display: block;
    margin: 4px 0;
    color: var(--accent-2);
    font-size: 28px;
}

.canvas-wrap {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line-strong);
    border-radius: 26px;
    background:
        radial-gradient(circle at 50% 45%, rgba(70, 230, 255, 0.16), transparent 30%),
        radial-gradient(circle at 42% 55%, rgba(156, 255, 109, 0.11), transparent 22%),
        linear-gradient(180deg, rgba(9, 17, 32, 0.7), rgba(2, 5, 12, 0.88));
    box-shadow: inset 0 0 80px rgba(70, 230, 255, 0.08), var(--shadow);
}

#canvas-container {
    position: absolute;
    inset: 0;
}

.hud {
    position: absolute;
    z-index: 5;
}

.top-left {
    top: 16px;
    left: 16px;
}

.top-right {
    top: 16px;
    right: 16px;
}

.bottom-left {
    left: 16px;
    bottom: 16px;
}

.bottom-right {
    right: 16px;
    bottom: 16px;
}

.chip,
.icon-btn,
.tiny-btn,
.primary-btn,
.dock-tab,
.mini-actions button,
.fav-btn {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(11, 21, 38, 0.72);
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease;
}

:root.light .chip,
:root.light .icon-btn,
:root.light .tiny-btn,
:root.light .primary-btn,
:root.light .dock-tab,
:root.light .mini-actions button,
:root.light .fav-btn {
    background: rgba(255, 255, 255, 0.78);
}

.chip:hover,
.icon-btn:hover,
.tiny-btn:hover,
.primary-btn:hover,
.dock-tab:hover,
.mini-actions button:hover,
.fav-btn:hover {
    transform: translateY(-1px);
    border-color: var(--line-strong);
}

.chip {
    padding: 9px 12px;
    color: var(--soft);
    font-size: 12px;
    font-weight: 800;
}

.chip.active,
.dock-tab.active,
.icon-btn.active {
    color: #031018;
    border-color: transparent;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.icon-btn {
    min-width: 42px;
    height: 42px;
    display: inline-grid;
    place-items: center;
    padding: 0 10px;
    color: var(--soft);
    font-weight: 800;
}

.primary-btn {
    height: 44px;
    padding: 0 16px;
    color: #031018;
    font-weight: 900;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.tiny-btn,
.mini-actions button {
    padding: 9px 11px;
    color: var(--soft);
    font-size: 12px;
    font-weight: 800;
}

.segmented {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.segmented button,
.element-strip button {
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.04);
}

.segmented button.active,
.element-strip button.active {
    color: var(--text);
    border-color: var(--line-strong);
    background: rgba(70, 230, 255, 0.12);
}

.filter-grid {
    align-items: stretch;
    margin-bottom: 12px;
}

select {
    min-width: 0;
    width: 100%;
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--soft);
    outline: 0;
    background: var(--panel-solid);
}

.element-strip {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    min-height: 46px;
    padding-bottom: 10px;
    margin-bottom: 10px;
}

.element-strip button {
    min-width: 42px;
    font-weight: 900;
}

.molecule-list {
    min-height: 0;
    overflow-y: auto;
    padding: 2px 4px 0 0;
}

.molecule-card {
    width: 100%;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    margin-bottom: 9px;
    padding: 12px;
    border: 1px solid transparent;
    border-radius: 16px;
    text-align: left;
    background: rgba(255, 255, 255, 0.045);
}

.molecule-card.active {
    border-color: var(--line-strong);
    background: linear-gradient(135deg, rgba(70, 230, 255, 0.14), rgba(156, 255, 109, 0.08));
}

.orb {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    color: #031018;
    font-family: "JetBrains Mono", monospace;
    font-weight: 900;
    box-shadow: 0 0 24px currentColor;
}

.molecule-card strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.molecule-card small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}

.difficulty {
    padding: 5px 7px;
    border-radius: 999px;
    color: var(--accent);
    font-size: 10px;
    font-weight: 900;
    background: rgba(70, 230, 255, 0.1);
}

.learning-dock {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow: visible;
}

.dock-tab {
    padding: 11px 15px;
    color: var(--soft);
    font-weight: 900;
    white-space: nowrap;
}

.workspace {
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 18px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.workspace-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.info-card,
.feature-card,
.quiz-card,
.note-card,
.teacher-item {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.045);
}

.info-card h3,
.feature-card h3 {
    margin-bottom: 8px;
}

.info-card p,
.feature-card p,
.quiz-card p {
    color: var(--soft);
    line-height: 1.55;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.metric-grid div {
    min-width: 0;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.045);
}

.metric-grid strong {
    display: block;
    overflow: hidden;
    margin-top: 6px;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 18px;
}

.inspector,
.teacher-panel {
    padding: 16px;
}

.teacher-panel {
    overflow: hidden;
}

.right-rail {
    overflow: auto;
}

.fav-btn {
    width: 42px;
    height: 42px;
    color: var(--warning);
    font-size: 22px;
}

.composition {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 14px 0;
}

.element-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--soft);
    background: rgba(255, 255, 255, 0.05);
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
}

.fact-stack h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

.fact-stack ul {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.fact-stack li {
    padding: 10px;
    border-left: 3px solid var(--accent);
    border-radius: 10px;
    color: var(--soft);
    background: rgba(255, 255, 255, 0.045);
}

.mini-actions {
    flex-wrap: wrap;
    margin-top: 14px;
}

.atom-readout {
    max-width: 290px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(3, 8, 16, 0.72);
}

:root.light .atom-readout {
    background: rgba(255, 255, 255, 0.82);
}

.speed-box {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(3, 8, 16, 0.72);
}

.speed-box label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

input[type="range"] {
    accent-color: var(--accent);
}

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

.feature-card {
    min-height: 130px;
}

.feature-card.done {
    border-color: rgba(156, 255, 109, 0.4);
    background: rgba(156, 255, 109, 0.08);
}

.radar-wrap {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    gap: 16px;
    align-items: center;
}

.radar {
    width: 170px;
    height: 170px;
}

.stat-list {
    display: grid;
    gap: 8px;
}

.stat-row {
    display: grid;
    grid-template-columns: 90px minmax(0, 1fr) 38px;
    gap: 8px;
    align-items: center;
    color: var(--soft);
    font-size: 12px;
}

.bar {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}

.bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.lab-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 290px;
    gap: 14px;
}

.reagent-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
}

.reagent-btn {
    min-height: 86px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    color: var(--text);
    text-align: left;
    background: rgba(255, 255, 255, 0.045);
}

.reagent-btn strong {
    display: block;
    margin-bottom: 5px;
}

.reagent-btn span {
    color: var(--muted);
    font-size: 12px;
}

.reaction-output {
    min-height: 224px;
    display: grid;
    align-content: center;
    gap: 10px;
    border: 1px solid var(--line-strong);
    border-radius: 18px;
    padding: 18px;
    background:
        radial-gradient(circle at 50% 30%, rgba(70, 230, 255, 0.18), transparent 34%),
        rgba(255, 255, 255, 0.045);
}

.beaker {
    width: 90px;
    height: 120px;
    margin: 0 auto;
    border: 3px solid rgba(237, 247, 255, 0.62);
    border-top: 0;
    border-radius: 0 0 20px 20px;
    position: relative;
    overflow: hidden;
}

.beaker::before {
    content: "";
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    height: 58%;
    border-radius: 0 0 14px 14px;
    background: linear-gradient(180deg, rgba(70,230,255,0.75), rgba(156,255,109,0.55));
    animation: liquidPulse 1.8s ease-in-out infinite;
}

.beaker::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    left: 26px;
    bottom: 34px;
    border-radius: 999px;
    background: rgba(255,255,255,0.8);
    box-shadow: 28px -18px 0 rgba(255,255,255,0.62), 16px -42px 0 rgba(255,255,255,0.42);
    animation: bubbles 1.5s ease-in-out infinite;
}

@keyframes liquidPulse {
    50% { transform: translateY(6px); filter: hue-rotate(40deg); }
}

@keyframes bubbles {
    50% { transform: translateY(-16px); opacity: 0.5; }
}

.periodic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
}

.element-card {
    min-height: 136px;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 13px;
    background: rgba(255, 255, 255, 0.045);
}

.element-card strong {
    display: block;
    font-family: "JetBrains Mono", monospace;
    font-size: 30px;
}

.element-card span,
.element-card small {
    display: block;
    color: var(--muted);
}

.passport {
    border: 1px solid var(--line-strong);
    border-radius: 22px;
    padding: 20px;
    background:
        linear-gradient(135deg, rgba(70, 230, 255, 0.12), rgba(183, 140, 255, 0.1)),
        var(--panel-solid);
}

.script-box {
    white-space: pre-wrap;
    line-height: 1.65;
}

.compare-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.quiz-options {
    display: grid;
    gap: 9px;
}

.quiz-options button {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 13px;
    color: var(--soft);
    text-align: left;
    background: rgba(255, 255, 255, 0.04);
}

.quiz-options button.correct {
    color: #031018;
    background: var(--accent-2);
}

.quiz-options button.wrong {
    color: #fff;
    background: var(--danger);
}

textarea {
    width: 100%;
    min-height: 120px;
    resize: vertical;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    color: var(--text);
    outline: 0;
    background: rgba(255, 255, 255, 0.045);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(2, 5, 10, 0.74);
    backdrop-filter: blur(14px);
}

.modal.hidden {
    display: none;
}

.modal-card {
    position: relative;
    width: min(780px, 100%);
    max-height: min(760px, 90vh);
    overflow: auto;
    padding: 24px;
    border: 1px solid var(--line-strong);
    border-radius: 24px;
    background: var(--panel-solid);
    box-shadow: var(--shadow);
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    color: var(--soft);
    background: rgba(255, 255, 255, 0.06);
}

.teacher-board {
    display: grid;
    gap: 10px;
}

.teacher-item strong {
    display: block;
    margin-bottom: 4px;
}

.teacher-item span {
    color: var(--muted);
    font-size: 12px;
}

.atom-label {
    position: absolute;
    z-index: 4;
    padding: 4px 7px;
    border: 1px solid rgba(255,255,255,0.24);
    border-radius: 999px;
    color: #031018;
    font-family: "JetBrains Mono", monospace;
    font-size: 11px;
    font-weight: 900;
    background: rgba(255,255,255,0.86);
    pointer-events: none;
}

.label-layer {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(145, 165, 189, 0.34);
}

@media (max-width: 1180px) {
    .app-shell {
        grid-template-columns: 280px minmax(0, 1fr);
    }

    .right-rail {
        display: none;
    }
}

@media (max-width: 860px) {
    body {
        overflow: auto;
    }

    .app-shell {
        height: auto;
        min-height: 100vh;
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }

    .topbar {
        grid-column: auto;
        grid-template-columns: 1fr;
    }

    .left-rail {
        order: 2;
    }

    .stage {
        order: 1;
        grid-template-rows: auto 520px auto auto;
    }

    .right-rail {
        display: flex;
        order: 3;
    }

    .workspace-grid,
    .compare-grid,
    .lab-grid,
    .radar-wrap {
        grid-template-columns: 1fr;
    }

    .stage-top {
        align-items: start;
        flex-direction: column;
    }

    .top-left,
    .top-right,
    .bottom-left,
    .bottom-right {
        position: static;
    }

    .canvas-wrap {
        display: grid;
        align-content: space-between;
        padding: 12px;
    }

    #canvas-container {
        z-index: 0;
    }

    .hud {
        position: relative;
        flex-wrap: wrap;
    }
}
