:root {
    --ink: #1c2432;
    --muted: #5e6b7e;
    --panel-bg: rgba(255, 255, 255, 0.9);
    --line: #d8e3f0;
    --teal: #0f9bb8;
    --deep-teal: #0a6f8d;
    --lime: #2db26f;
    --orange: #f0932b;
    --red: #dc5454;
    --soft-shadow: 0 22px 44px rgba(13, 34, 66, 0.14);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Space Grotesk', sans-serif;
    color: var(--ink);
    min-height: 100vh;
    background:
        radial-gradient(circle at 8% 12%, rgba(15, 155, 184, 0.22), transparent 34%),
        radial-gradient(circle at 92% 18%, rgba(240, 147, 43, 0.24), transparent 32%),
        linear-gradient(160deg, #f4fbff 0%, #ebf3ff 40%, #f5f7ff 100%);
    padding: 22px;
}

.app-shell {
    max-width: 1240px;
    margin: 0 auto;
    display: grid;
    gap: 18px;
}

.hero {
    background: linear-gradient(120deg, rgba(13, 63, 84, 0.95), rgba(15, 155, 184, 0.92));
    border-radius: 26px;
    box-shadow: var(--soft-shadow);
    color: #f4ffff;
    padding: 28px 30px;
    overflow: hidden;
    position: relative;
}

.hero::after {
    content: "";
    position: absolute;
    right: -80px;
    top: -90px;
    width: 260px;
    height: 260px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.32) 0%, rgba(255, 255, 255, 0) 70%);
}

.kicker {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.8rem;
    font-weight: 700;
    opacity: 0.9;
    margin-bottom: 8px;
}

h1 {
    font-family: 'Archivo Black', sans-serif;
    font-size: clamp(1.65rem, 2vw, 2.2rem);
    line-height: 1.2;
    margin-bottom: 10px;
}

.subtitle {
    max-width: 760px;
    font-size: 1rem;
    opacity: 0.95;
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.layout > .panel {
    min-width: 0;
}

.panel {
    background: var(--panel-bg);
    border-radius: 22px;
    border: 1px solid rgba(170, 192, 214, 0.65);
    box-shadow: var(--soft-shadow);
    backdrop-filter: blur(4px);
    padding: 20px;
}

.panel-head {
    margin-bottom: 16px;
}

.panel-head h2 {
    font-size: 1.3rem;
    margin-bottom: 4px;
}

.panel-head p {
    color: var(--muted);
    font-size: 0.95rem;
}

.controls {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
}

.controls label {
    font-size: 0.95rem;
    color: var(--muted);
    font-weight: 500;
}

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

.button-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    border: none;
    border-radius: 14px;
    padding: 11px 16px;
    font-size: 0.95rem;
    font-weight: 700;
    font-family: 'Space Grotesk', sans-serif;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

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

button:active {
    transform: translateY(1px);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.primary {
    background: linear-gradient(120deg, var(--teal), var(--deep-teal));
    color: #f8ffff;
    box-shadow: 0 10px 20px rgba(10, 111, 141, 0.32);
}

.ghost {
    background: #eef4fb;
    color: #214266;
    border: 1px solid #c8d8ea;
}

.timeline {
    background: #f5f9ff;
    border: 1px solid #d8e5f2;
    border-radius: 14px;
    padding: 10px 12px;
    margin-bottom: 16px;
}

.timeline-labels {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.86rem;
    color: #4b5e75;
    margin-bottom: 6px;
}

.timeline-track {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    background: #dbe7f5;
    overflow: hidden;
}

.timeline-bar {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #0f9bb8, #2db26f);
    transition: width 0.16s linear;
    position: relative;
}

.timeline-bar::after {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        -60deg,
        rgba(255, 255, 255, 0.2) 0,
        rgba(255, 255, 255, 0.2) 10px,
        rgba(255, 255, 255, 0.05) 10px,
        rgba(255, 255, 255, 0.05) 20px
    );
    transform: translateX(-30px);
}

body.running .timeline-bar::after {
    animation: stripe-move 0.7s linear infinite;
}

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

.beaker-card {
    background: linear-gradient(175deg, #f9fdff, #f1f7ff);
    border: 1px solid #d3e1ee;
    border-radius: 16px;
    padding: 12px;
    display: grid;
    gap: 10px;
    transform: translateY(0);
    opacity: 0;
    animation: card-enter 0.6s ease forwards;
}

.beaker-card:nth-child(2) { animation-delay: 0.05s; }
.beaker-card:nth-child(3) { animation-delay: 0.1s; }
.beaker-card:nth-child(4) { animation-delay: 0.15s; }
.beaker-card:nth-child(5) { animation-delay: 0.2s; }
.beaker-card:nth-child(6) { animation-delay: 0.25s; }

.beaker-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: #23486f;
}

.beaker-visual {
    height: 170px;
    border-radius: 14px;
    border: 1px solid #c5d8ea;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(231, 242, 255, 0.65));
    position: relative;
    overflow: hidden;
}

.beaker-visual::before {
    content: "";
    position: absolute;
    left: 12px;
    right: 12px;
    top: 10px;
    height: 8px;
    border-radius: 999px;
    border: 1px solid #b8ccdf;
    background: rgba(255, 255, 255, 0.8);
}

.solution {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;
    height: 74%;
    border-radius: 0 0 10px 10px;
    background: linear-gradient(180deg, var(--fill-soft), var(--fill-strong));
    border: 1px solid rgba(88, 126, 163, 0.25);
    overflow: hidden;
}

.solution::before {
    content: "";
    position: absolute;
    left: -20%;
    right: -20%;
    top: -6px;
    height: 14px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
}

.potato-cylinder {
    position: absolute;
    left: 50%;
    bottom: 8px;
    width: 20px;
    height: 84px;
    border-radius: 10px;
    transform-origin: center bottom;
    transform: translateX(-50%) scaleY(1);
    background: linear-gradient(180deg, #f4d5ac, #cfaa78);
    border: 1px solid #ad8459;
    box-shadow: 0 4px 8px rgba(71, 44, 13, 0.2);
    transition: transform 0.16s linear;
}

.bubble {
    position: absolute;
    bottom: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    opacity: 0;
    animation: bubble-rise 2.2s linear infinite;
    animation-play-state: paused;
}

.b1 { left: 20%; animation-delay: 0.2s; }
.b2 { left: 50%; animation-delay: 1s; }
.b3 { left: 72%; animation-delay: 1.5s; }

body.running .bubble {
    animation-play-state: running;
}

.mass-readings {
    display: grid;
    gap: 4px;
    font-size: 0.82rem;
    color: #3f546d;
}

.mass-line strong {
    font-variant-numeric: tabular-nums;
    color: #1c3857;
}

.change-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.change-pill {
    font-size: 0.8rem;
    padding: 4px 8px;
    border-radius: 999px;
    font-weight: 700;
    min-width: 72px;
    text-align: center;
}

.change-pill.positive {
    color: #0f623a;
    background: #d8f4e7;
}

.change-pill.negative {
    color: #862f2f;
    background: #ffe2e2;
}

.change-pill.neutral {
    color: #555f6e;
    background: #e5ebf3;
}

.direction-indicator {
    font-size: 0.76rem;
    color: #617185;
    white-space: nowrap;
}

.chart-wrap {
    background: #fcfdff;
    border: 1px solid #d5e2f1;
    border-radius: 14px;
    padding: 8px;
    min-height: 320px;
}

#resultsChart {
    width: 100%;
    height: 300px;
}

.results-summary {
    margin: 10px 2px 12px;
    font-size: 0.9rem;
    color: #485a73;
    min-height: 20px;
}

.table-wrap {
    border: 1px solid #d7e4f0;
    border-radius: 14px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
    min-width: 520px;
}

thead {
    background: #eef4fb;
}

th,
td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #e3ecf5;
    white-space: nowrap;
}

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

tbody td {
    font-variant-numeric: tabular-nums;
}

.notes-list {
    list-style: none;
    display: grid;
    gap: 8px;
    color: #3f536b;
}

.notes-list li {
    position: relative;
    padding-left: 22px;
    line-height: 1.35;
}

.notes-list li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.45em;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: linear-gradient(120deg, #0f9bb8, #2db26f);
}

.osmosis-panel {
    display: grid;
    gap: 14px;
}

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

.osmosis-stage {
    position: relative;
    border-radius: 16px;
    border: 1px solid #c8d9eb;
    background: linear-gradient(185deg, #fafeff, #eff6ff);
    overflow: hidden;
    min-height: 360px;
}

#osmosisCanvas {
    width: 100%;
    height: 360px;
    display: block;
    background: linear-gradient(180deg, #f8fdff, #e9f3ff);
}

.osmosis-membrane-label {
    position: absolute;
    left: 50%;
    top: 12px;
    transform: translateX(-50%);
    border-radius: 999px;
    padding: 4px 10px;
    border: 1px dashed #7b95b2;
    background: rgba(255, 255, 255, 0.86);
    font-size: 0.78rem;
    font-weight: 700;
    color: #436182;
    pointer-events: none;
}

.osmosis-side-labels {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 12px;
    display: flex;
    justify-content: space-between;
    padding: 0 16px;
    font-size: 0.84rem;
    font-weight: 700;
    color: #41607f;
    pointer-events: none;
}

.osmosis-config {
    border: 1px solid #d2e2f1;
    border-radius: 16px;
    background: linear-gradient(180deg, #fbfdff, #f1f7ff);
    padding: 12px;
    display: grid;
    gap: 12px;
}

.osmosis-bars {
    display: grid;
    gap: 8px;
}

.osmosis-bar {
    display: grid;
    gap: 4px;
}

.osmosis-bar span {
    font-size: 0.8rem;
    color: #46637f;
    font-weight: 700;
}

.osmosis-progress-track {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    background: #d7e5f2;
    overflow: hidden;
}

.osmosis-progress-fill {
    width: 50%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #0f9bb8, #6fc8df);
    transition: width 0.2s ease;
}

.osmosis-slider-grid {
    display: grid;
    gap: 8px;
}

.osmosis-slider-card {
    display: grid;
    gap: 6px;
    border: 1px solid #d8e4f1;
    border-radius: 12px;
    background: #ffffff;
    padding: 10px;
}

.osmosis-slider-card span {
    font-size: 0.86rem;
    color: #334d6c;
    font-weight: 600;
}

.osmosis-actions {
    display: grid;
    gap: 10px;
}

.osmosis-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.84rem;
    color: #405975;
}

.osmosis-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.legend-dot.water {
    background: #2b9fc6;
    border: 1px solid #8fd1e7;
}

.legend-dot.solute {
    background: #f08f52;
    border: 1px solid #f5c8a5;
}

.osmosis-explainer {
    border: 1px solid #d6e4f2;
    border-radius: 12px;
    background: #ffffff;
    padding: 10px;
    display: grid;
    gap: 8px;
}

.osmosis-explainer h3 {
    font-size: 0.94rem;
    color: #244566;
}

.osmosis-explainer p,
.osmosis-explainer li {
    font-size: 0.84rem;
    color: #45607f;
    line-height: 1.4;
}

.osmosis-explainer ul {
    margin: 0;
    padding-left: 18px;
    display: grid;
    gap: 4px;
}

.osmosis-summary {
    font-weight: 600;
    color: #244c70;
    background: #f2f8ff;
    border: 1px solid #d6e7f6;
    border-radius: 10px;
    padding: 8px;
}

.osmosis-note {
    font-size: 0.85rem;
    color: #4c6582;
    line-height: 1.35;
    padding-top: 2px;
}

@keyframes bubble-rise {
    0% {
        transform: translateY(0) scale(0.8);
        opacity: 0;
    }
    15% {
        opacity: 0.7;
    }
    100% {
        transform: translateY(-86px) scale(1.1);
        opacity: 0;
    }
}

@keyframes stripe-move {
    from {
        transform: translateX(-40px);
    }
    to {
        transform: translateX(40px);
    }
}

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

@media (max-width: 1080px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .osmosis-layout {
        grid-template-columns: 1fr;
    }
}

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

    .app-shell {
        gap: 14px;
    }

    .hero {
        border-radius: 20px;
        padding: 22px 20px;
    }

    .panel {
        padding: 16px;
    }

    .panel-head h2 {
        font-size: 1.18rem;
    }

    .panel-head p {
        font-size: 0.9rem;
    }

    .timeline-labels {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .beaker-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .beaker-visual {
        height: 156px;
    }

    .chart-wrap {
        min-height: 250px;
    }

    #resultsChart {
        height: 230px;
    }

    .osmosis-stage,
    #osmosisCanvas {
        min-height: 320px;
        height: 320px;
    }

    .osmosis-side-labels {
        font-size: 0.78rem;
        padding: 0 12px;
    }
}

@media (max-width: 560px) {
    body {
        padding: 10px;
    }

    .app-shell {
        gap: 12px;
    }

    .hero {
        border-radius: 18px;
        padding: 18px 16px;
    }

    h1 {
        font-size: 1.45rem;
    }

    .subtitle {
        font-size: 0.92rem;
    }

    .panel {
        padding: 14px;
        border-radius: 18px;
    }

    .beaker-grid {
        grid-template-columns: 1fr;
    }

    .beaker-card {
        padding: 10px;
    }

    .beaker-visual {
        height: 142px;
    }

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

    button {
        width: 100%;
    }

    table {
        min-width: 0;
        font-size: 0.8rem;
    }

    th,
    td {
        white-space: normal;
        padding: 8px;
    }

    .osmosis-config {
        padding: 10px;
    }

    .osmosis-explainer p,
    .osmosis-explainer li,
    .osmosis-note {
        font-size: 0.8rem;
    }

    #osmosisCanvas {
        height: 260px;
    }

    .osmosis-stage {
        min-height: 260px;
    }

    .osmosis-membrane-label {
        top: 8px;
        font-size: 0.72rem;
        padding: 3px 8px;
    }

    .osmosis-side-labels {
        font-size: 0.74rem;
        padding: 0 10px;
    }
}

@media (max-width: 420px) {
    h1 {
        font-size: 1.3rem;
    }

    .kicker {
        font-size: 0.72rem;
    }

    .chart-wrap {
        min-height: 220px;
    }

    #resultsChart {
        height: 210px;
    }
}
