:root {
    --lab-ink: #10212d;
    --lab-panel: rgba(244, 248, 250, 0.97);
    --lab-panel-strong: #eef5f2;
    --lab-line: rgba(16, 33, 45, 0.12);
    --lab-accent: #1f9bcf;
    --lab-accent-deep: #14739b;
    --lab-cool: #5bb2df;
    --lab-mint: #76c893;
    --lab-gold: #f4d35e;
    --lab-shadow: 0 20px 50px rgba(10, 21, 34, 0.18);
}

.pixel-lab-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(91, 178, 223, 0.24), transparent 24%),
        radial-gradient(circle at top right, rgba(118, 200, 147, 0.24), transparent 26%),
        linear-gradient(180deg, #ecf7fb 0%, #dcefed 52%, #eef3f7 100%);
    color: var(--lab-ink);
}

.pixel-lab-section {
    position: relative;
    overflow: hidden;
}

.pixel-lab-section::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(16, 33, 45, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(16, 33, 45, 0.035) 1px, transparent 1px);
    background-size: 28px 28px;
    pointer-events: none;
}

.pixel-lab-shell {
    position: relative;
    margin: 2rem auto 3rem;
    padding: 1.5rem;
    border-radius: 28px;
    background:
        linear-gradient(145deg, rgba(247, 253, 255, 0.96), rgba(239, 249, 245, 0.95));
    border: 1px solid rgba(16, 33, 45, 0.08);
    box-shadow: var(--lab-shadow);
}

.lab-intro {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.intro-copy h1 {
    margin: 0.2rem 0 0.5rem;
    font-family: "Trebuchet MS", "Gill Sans", sans-serif;
    font-size: clamp(2rem, 4vw, 3rem);
    line-height: 0.95;
    color: #123246;
}

.lab-eyebrow {
    margin: 0;
    font-family: "Courier New", monospace;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #1f6f8f;
    font-size: 0.78rem;
}

.lab-lead {
    max-width: 58ch;
    margin: 0 0 0.7rem;
    color: rgba(16, 33, 45, 0.8);
}

.lab-description {
    max-width: 70ch;
    margin: 0;
    color: rgba(16, 33, 45, 0.8);
    line-height: 1.55;
}

.intro-actions {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    align-items: flex-end;
}

.mode-switch {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(16, 33, 45, 0.08);
}

.mode-chip,
.tool-btn,
.size-btn,
.mini-link,
.mode-link {
    font: inherit;
}

.mode-chip {
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: rgba(16, 33, 45, 0.76);
    padding: 0.65rem 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.mode-chip:hover,
.tool-btn:hover,
.size-btn:hover,
.mini-link:hover,
.mode-link:hover {
    transform: translateY(-1px);
}

.mode-chip.active {
    background: linear-gradient(135deg, #123246, #1f5974);
    color: #fff;
}

.mode-link {
    color: #123246;
    text-decoration: none;
    font-weight: 700;
}

.lab-layout {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr) 320px;
    gap: 1rem;
    align-items: start;
}

.lab-toolbar,
.lab-panel {
    display: grid;
    gap: 1rem;
}

.toolbar-card,
.panel-card,
.palette-card {
    background: var(--lab-panel);
    border: 1px solid var(--lab-line);
    border-radius: 22px;
    box-shadow: 0 10px 24px rgba(10, 21, 34, 0.06);
}

.toolbar-card {
    padding: 1rem;
}

.toolbar-heading {
    font-family: "Trebuchet MS", "Gill Sans", sans-serif;
    font-size: 0.82rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(16, 33, 45, 0.65);
    margin-bottom: 0.7rem;
}

.tool-grid,
.action-row,
.size-row {
    display: grid;
    gap: 0.55rem;
}

.tool-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.action-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.size-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tool-btn,
.size-btn,
.mini-link {
    border: 1px solid rgba(16, 33, 45, 0.12);
    border-radius: 16px;
    background: #fff;
    color: #123246;
    padding: 0.72rem 0.9rem;
    cursor: pointer;
    font-weight: 700;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.tool-btn.secondary,
.mini-link,
.size-btn {
    background: rgba(255, 255, 255, 0.78);
}

.tool-btn.active,
.size-btn.active {
    background: linear-gradient(135deg, #dff5ff, #c9f3e0);
    border-color: rgba(31, 155, 207, 0.28);
    color: #12506b;
}

.tool-btn:disabled,
.size-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.selected-material {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 3rem;
    padding: 0.7rem 0.85rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.84);
    border: 1px dashed rgba(16, 33, 45, 0.12);
}

.selected-swatch,
.science-swatch {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    background: #d3dbe1;
    box-shadow: 0 0 0 2px rgba(16, 33, 45, 0.08);
}

.selected-label {
    font-weight: 700;
}

.toolbar-hint,
.palette-header p,
.science-note-card p,
.quiz-explanation,
.mission-card p,
.discovery-card p {
    margin: 0;
    color: rgba(16, 33, 45, 0.68);
    font-size: 0.92rem;
    line-height: 1.45;
}

.lab-main {
    display: grid;
    gap: 1rem;
}

.lab-guide {
    display: grid;
    gap: 1rem;
    margin-top: 1rem;
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.guide-card {
    padding: 1.15rem 1.2rem;
    border-radius: 22px;
    background: var(--lab-panel);
    border: 1px solid var(--lab-line);
    box-shadow: 0 10px 24px rgba(10, 21, 34, 0.06);
}

.guide-card h2 {
    margin: 0 0 0.8rem;
    color: #123246;
    font-family: "Trebuchet MS", "Gill Sans", sans-serif;
}

.guide-card p {
    margin: 0 0 0.9rem;
    color: rgba(16, 33, 45, 0.74);
    line-height: 1.55;
}

.guide-card p:last-child {
    margin-bottom: 0;
}

.guide-card ul {
    margin: 0;
    padding-left: 1.2rem;
    color: rgba(16, 33, 45, 0.78);
}

.guide-card li {
    margin-bottom: 0.65rem;
    line-height: 1.5;
}

.guide-card li:last-child {
    margin-bottom: 0;
}

.lab-status-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    gap: 0.8rem;
}

.status-pill,
.metric-card {
    padding: 0.85rem 1rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid var(--lab-line);
}

.status-pill {
    min-width: 0;
    min-height: 4.2rem;
}

.status-label,
.metric-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(16, 33, 45, 0.55);
}

.status-value,
.metric-value {
    display: block;
    margin-top: 0.2rem;
    font-weight: 800;
    color: #123246;
    min-width: 0;
}

.status-value {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.24;
    word-break: break-word;
}

#fullscreenToggleBtn {
    background: linear-gradient(135deg, #e7f4ff, #d8ecff);
    border-color: rgba(31, 89, 116, 0.22);
}

.canvas-shell {
    position: relative;
    display: grid;
    place-items: center;
    padding: 1rem;
    border-radius: 26px;
    background: linear-gradient(180deg, #172f3c, #0e222f);
    min-height: min(62vh, 700px);
    overflow: hidden;
    border: 1px solid rgba(16, 33, 45, 0.12);
    isolation: isolate;
    contain: layout paint;
    transform: translateZ(0);
}

.canvas-backdrop {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at top, rgba(255, 122, 26, 0.12), transparent 26%),
        radial-gradient(circle at bottom, rgba(91, 178, 223, 0.18), transparent 34%);
    pointer-events: none;
}

#labCanvas {
    position: relative;
    display: block;
    width: 100%;
    max-width: 100%;
    aspect-ratio: 132 / 84;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    border-radius: 18px;
    border: 2px solid rgba(244, 248, 250, 0.12);
    background: #10222f;
    z-index: 1;
    touch-action: none;
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

.canvas-overlay-note {
    position: absolute;
    inset: auto 50% 1.2rem auto;
    transform: translateX(50%);
    z-index: 2;
    padding: 0.5rem 0.8rem;
    border-radius: 999px;
    background: rgba(12, 21, 33, 0.68);
    color: #eef6fb;
    font-size: 0.88rem;
    letter-spacing: 0.04em;
}

.canvas-hover-readout {
    position: absolute;
    right: 1rem;
    bottom: 1rem;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    max-width: calc(100% - 2rem);
}

.canvas-hover-item {
    display: inline-flex;
    align-items: center;
    min-height: 2rem;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: rgba(12, 21, 33, 0.88);
    color: #eef6fb;
    font-size: 0.84rem;
    font-weight: 700;
    line-height: 1.2;
}

#hoverObjectLabel {
    max-width: min(220px, 52vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pixel-lab-shell > .fullscreen-btn {
    display: none;
}

.palette-card {
    padding: 1rem;
}

.palette-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.palette-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.9rem;
}

.palette-tab {
    border: 1px solid rgba(16, 33, 45, 0.12);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    color: #123246;
    padding: 0.5rem 0.9rem;
    cursor: pointer;
    font-weight: 700;
}

.palette-tab.active {
    background: #123246;
    color: #fff;
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 0.75rem;
}

.material-btn {
    display: grid;
    gap: 0.35rem;
    align-content: start;
    min-height: 92px;
    padding: 0.75rem;
    border: 1px solid rgba(16, 33, 45, 0.1);
    border-radius: 18px;
    background: #fff;
    cursor: pointer;
    text-align: left;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.material-btn.active {
    border-color: rgba(255, 122, 26, 0.46);
    box-shadow: 0 8px 20px rgba(215, 95, 19, 0.12);
}

.material-topline {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.material-swatch {
    width: 0.95rem;
    height: 0.95rem;
    border-radius: 50%;
    flex: 0 0 auto;
    background: #d8e2ea;
}

.material-name {
    font-weight: 800;
    color: #123246;
}

.material-meta {
    color: rgba(16, 33, 45, 0.6);
    font-size: 0.8rem;
    text-transform: capitalize;
}

.panel-section summary {
    list-style: none;
    cursor: pointer;
    padding: 1rem 1.1rem;
    font-family: "Trebuchet MS", "Gill Sans", sans-serif;
    font-weight: 800;
    color: #123246;
}

.panel-section summary::-webkit-details-marker {
    display: none;
}

.panel-body {
    padding: 0 1.1rem 1.1rem;
}

.panel-body h2,
.science-note-header h3 {
    margin: 0 0 0.45rem;
    color: #123246;
}

.science-note-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.8rem;
}

.science-note-card {
    display: grid;
    gap: 0.35rem;
}

.progress-stack {
    margin: 1rem 0 1.1rem;
}

.progress-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.45rem;
    font-size: 0.9rem;
    color: rgba(16, 33, 45, 0.74);
}

.progress-bar {
    height: 0.8rem;
    border-radius: 999px;
    background: rgba(16, 33, 45, 0.08);
    overflow: hidden;
}

.progress-bar span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--lab-gold), var(--lab-accent));
    transition: width 0.2s ease;
}

.objective-list {
    display: grid;
    gap: 0.65rem;
    margin: 0 0 1rem;
    padding: 0;
    list-style: none;
}

.objective-item {
    display: flex;
    gap: 0.65rem;
    align-items: flex-start;
    padding: 0.75rem 0.85rem;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(16, 33, 45, 0.08);
}

.objective-item.completed {
    background: rgba(118, 200, 147, 0.16);
    border-color: rgba(118, 200, 147, 0.28);
}

.objective-dot {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    border: 2px solid rgba(16, 33, 45, 0.2);
    flex: 0 0 auto;
    margin-top: 0.15rem;
}

.objective-item.completed .objective-dot {
    border-color: rgba(118, 200, 147, 0.9);
    background: rgba(118, 200, 147, 0.9);
}

.metric-grid,
.discovery-summary,
.result-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.modal-shell {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(10, 21, 34, 0.52);
    backdrop-filter: blur(6px);
}

.hidden {
    display: none !important;
}

.modal-card {
    width: min(880px, 100%);
    max-height: min(88vh, 900px);
    overflow: hidden;
    border-radius: 24px;
    background: linear-gradient(180deg, #f7fbff, #edf6f5);
    border: 1px solid rgba(16, 33, 45, 0.12);
    box-shadow: 0 28px 60px rgba(10, 21, 34, 0.22);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
}

.modal-card-narrow {
    width: min(540px, 100%);
}

.modal-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    padding: 1rem 1.2rem;
    border-bottom: 1px solid rgba(16, 33, 45, 0.08);
}

.modal-head h2 {
    margin: 0;
    color: #123246;
}

.modal-close {
    border: 0;
    background: transparent;
    color: rgba(16, 33, 45, 0.6);
    cursor: pointer;
    font-size: 1.8rem;
    line-height: 1;
}

.modal-content {
    padding: 1rem 1.2rem 1.2rem;
    overflow: auto;
}

.mission-list,
.discovery-grid {
    display: grid;
    gap: 0.85rem;
}

.mission-card,
.discovery-card {
    padding: 1rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid rgba(16, 33, 45, 0.08);
}

.mission-card.locked {
    opacity: 0.65;
}

.mission-topline,
.discovery-topline,
.quiz-badges,
.stars-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.mission-topline {
    justify-content: space-between;
    margin-bottom: 0.45rem;
}

.mission-stars,
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.28rem 0.55rem;
    border-radius: 999px;
    background: rgba(16, 33, 45, 0.08);
    color: #123246;
    font-size: 0.8rem;
    font-weight: 700;
}

.badge {
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(16, 33, 45, 0.08);
}

.discovery-card.locked {
    opacity: 0.55;
}

.stars-row {
    justify-content: center;
    margin-bottom: 1rem;
    font-size: 2rem;
}

.star {
    color: rgba(16, 33, 45, 0.16);
}

.star.earned {
    color: #ffb703;
}

.quiz-scenario {
    margin-bottom: 0.85rem;
    padding: 0.95rem;
    border-radius: 18px;
    background: rgba(18, 50, 70, 0.08);
    color: #123246;
}

.quiz-prompt {
    margin: 0 0 1rem;
    font-weight: 700;
    color: #123246;
}

.quiz-choices {
    display: grid;
    gap: 0.7rem;
    margin-bottom: 0.9rem;
}

.quiz-choice {
    width: 100%;
    text-align: left;
    border: 1px solid rgba(16, 33, 45, 0.12);
    border-radius: 16px;
    background: #fff;
    padding: 0.85rem 0.95rem;
    cursor: pointer;
    font-weight: 600;
    color: #123246;
}

.quiz-choice.correct {
    background: rgba(118, 200, 147, 0.16);
    border-color: rgba(118, 200, 147, 0.34);
}

.quiz-choice.wrong {
    background: rgba(255, 122, 26, 0.16);
    border-color: rgba(255, 122, 26, 0.28);
}

.toast-stack {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 60;
    display: grid;
    gap: 0.75rem;
    width: min(320px, calc(100vw - 2rem));
}

.toast {
    padding: 0.9rem 1rem;
    border-radius: 18px;
    background: rgba(12, 21, 33, 0.9);
    color: #eef6fb;
    box-shadow: 0 18px 30px rgba(10, 21, 34, 0.22);
    animation: toastIn 0.2s ease;
}

.toast strong {
    display: block;
    margin-bottom: 0.2rem;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1180px) {
    .lab-layout {
        grid-template-columns: 1fr;
    }

    .lab-toolbar {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.8rem;
    }

    .lab-panel {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 880px) {
    .pixel-lab-shell {
        padding: 1rem;
        border-radius: 22px;
    }

    .lab-intro,
    .palette-header {
        flex-direction: column;
        align-items: stretch;
    }

    .intro-actions {
        align-items: stretch;
    }

    .lab-status-bar,
    .lab-toolbar,
    .lab-panel,
    .guide-grid,
    .metric-grid,
    .discovery-summary,
    .result-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .canvas-shell {
        min-height: 46vh;
    }
}

@media (max-width: 640px) {
    .lab-status-bar,
    .lab-toolbar,
    .lab-panel,
    .guide-grid,
    .metric-grid,
    .discovery-summary,
    .result-metrics,
    .action-row,
    .tool-grid {
        grid-template-columns: 1fr;
    }

    .mode-switch {
        justify-content: stretch;
        border-radius: 20px;
    }

    .mode-chip {
        flex: 1 1 auto;
        text-align: center;
        border-radius: 16px;
    }

    .palette-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .modal-content,
    .panel-body,
    .toolbar-card,
    .palette-card {
        padding-left: 0.9rem;
        padding-right: 0.9rem;
    }

    .canvas-shell {
        padding: 0.75rem;
        min-height: 38vh;
    }
}
