.console-grid {
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    gap: 1rem;
    padding: 1rem;
    height: 100%;
    min-height: 0;
}

@media (max-width: 1100px) {
    .console-grid {
        grid-template-columns: 1fr;
        grid-template-rows: 50% 50%;
    }
}

.viewport {
    position: relative;
    background:
        radial-gradient(ellipse at center, rgba(30, 30, 4, 0.18) 0%, rgba(0,0,0,0.65) 100%);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(254, 232, 1, 0.06);
    min-height: 0;
}

.viewport-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    /* Stop the browser from hijacking drag/pinch — let OrbitControls handle them */
    touch-action: none;
    cursor: grab;
}
.viewport-canvas:active { cursor: grabbing; }

.viewport-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 1rem 1.25rem;
}

.viewport-overlay > * { pointer-events: auto; }

.viewport-title {
    font-family: var(--font-heading);
    color: var(--color-cyan);
    text-shadow: var(--glow-cyan);
    letter-spacing: 3px;
    font-size: 0.78rem;
}

.viewport-help {
    align-self: flex-end;
    font-size: 0.7rem;
    color: var(--color-text-dim);
    background: rgba(0, 0, 0, 0.45);
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(6px);
    max-width: 100%;
}

.viewport-controls {
    position: absolute;
    top: 0.85rem;
    right: 0.95rem;
    display: flex;
    gap: 6px;
    pointer-events: auto;
}

.viewport-btn {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid var(--border-color);
    color: var(--color-cyan);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    backdrop-filter: blur(6px);
}
.viewport-btn:hover {
    background: rgba(254, 232, 1, 0.10);
    border-color: var(--color-cyan);
    box-shadow: var(--glow-cyan);
    transform: scale(1.05);
}
.viewport-btn:active { transform: scale(0.96); }

.panel {
    position: relative;
    overflow: hidden;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    backdrop-filter: blur(14px);
}

.console-grid {
    position: relative;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(180deg, rgba(254,232,1,0.06), transparent);
    font-family: var(--font-heading);
    letter-spacing: 2px;
    color: var(--color-cyan);
    font-size: 0.78rem;
}

.panel-header .status-tag {
    color: var(--color-yellow);
    font-size: 0.72rem;
    text-shadow: var(--glow-yellow);
}

.panel-body {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.panel-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border-glow); border-radius: 3px; }

.meta-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 0.9rem;
}

.meta-pill {
    padding: 3px 9px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-size: 0.7rem;
    color: var(--color-text-dim);
    background: rgba(254, 232, 1, 0.04);
    letter-spacing: 1px;
}
.meta-pill.solved   { color: var(--color-green); border-color: rgba(84,193,230,0.4); background: rgba(84,193,230,0.05); }
.meta-pill.unlocked { color: var(--color-cyan); border-color: rgba(254,232,1,0.4); background: rgba(254,232,1,0.05); }
.meta-pill.locked   { color: var(--color-red); border-color: rgba(255,58,58,0.3); background: rgba(255,58,58,0.05); }
.meta-pill.master   { color: var(--color-magenta); border-color: rgba(57,196,182,0.4); background: rgba(57,196,182,0.05); }

.narrative-block {
    padding: 0.95rem 1rem;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border-color);
    border-left: 2px solid var(--color-yellow);
    border-radius: 3px;
    margin-bottom: 0.9rem;
    font-size: 0.9rem;
    line-height: 1.7;
}
.narrative-block .label {
    display: block;
    font-family: var(--font-heading);
    font-size: 0.68rem;
    letter-spacing: 2px;
    color: var(--color-yellow);
    margin-bottom: 6px;
    text-shadow: var(--glow-yellow);
}

.flavour-block {
    padding: 0.7rem 0.9rem;
    background: rgba(84, 193, 230, 0.03);
    border: 1px dashed rgba(84, 193, 230, 0.3);
    border-radius: 3px;
    color: var(--color-green);
    font-size: 0.8rem;
    margin-bottom: 0.9rem;
    font-style: italic;
}

.download-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 0.65rem 0.9rem;
    background: rgba(254, 232, 1, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    margin-bottom: 0.9rem;
    font-size: 0.84rem;
}

.flag-submit {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-top: 0.8rem;
}

.feedback-line {
    margin-top: 0.55rem;
    font-size: 0.84rem;
    min-height: 1.4em;
}
.feedback-line.error { color: var(--color-red); }
.feedback-line.ok { color: var(--color-green); }
.feedback-line.warn { color: var(--color-yellow); }

.master-bar {
    border-top: 1px solid var(--border-color);
    padding: 0.95rem 1.5rem;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 14px;
    background: linear-gradient(180deg, transparent, rgba(154,159,23,0.05));
    align-items: center;
}
.master-bar .master-label {
    font-family: var(--font-heading);
    color: var(--color-yellow);
    font-size: 0.78rem;
    letter-spacing: 2px;
    text-shadow: var(--glow-yellow);
}
.master-bar input { background: rgba(0,0,0,0.6); border-color: rgba(154,159,23,0.35); }
.master-bar input:focus { border-color: var(--color-yellow); box-shadow: 0 0 10px rgba(154,159,23,0.3); }

.empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--color-text-dim);
    text-align: center;
    padding: 2rem;
}
.empty-state .big {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--color-cyan);
    letter-spacing: 3px;
    text-shadow: var(--glow-cyan);
}
.empty-state .sub { font-size: 0.84rem; max-width: 380px; line-height: 1.6; }

.btn { /* console-specific overrides */ }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.stage-actions {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 1rem;
}

.victory-modal {
    position: fixed;
    inset: 0;
    background: rgba(3, 5, 8, 0.92);
    backdrop-filter: blur(8px);
    display: grid;
    place-items: center;
    z-index: 9999;
    padding: 2rem;
}
.victory-modal .card {
    max-width: 560px;
    width: 100%;
    background: var(--bg-panel-solid);
    border: 2px solid var(--color-green);
    box-shadow: 0 0 60px rgba(84,193,230,0.35);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
}
.victory-modal h2 {
    font-family: var(--font-heading);
    color: var(--color-green);
    letter-spacing: 4px;
    text-shadow: var(--glow-green);
    margin-bottom: 1rem;
}
.victory-modal p { color: var(--color-text); margin-bottom: 1rem; line-height: 1.6; }
.victory-modal .final-flag {
    user-select: all;
    display: block;
    padding: 0.9rem;
    background: rgba(84,193,230,0.08);
    border: 1px solid var(--color-green);
    border-radius: 3px;
    color: var(--color-green);
    font-family: var(--font-mono);
    font-size: 1rem;
    margin: 1rem 0;
    word-break: break-all;
}

/* Achievement ribbons (victory modal) */
#achievement-list {
    margin-top: 1.4rem;
    text-align: left;
}
.ach-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-heading);
    font-size: 0.74rem;
    letter-spacing: 2px;
    color: var(--color-text-dim);
    margin-bottom: 0.6rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border-color);
}
.ach-header .ach-count { color: var(--color-yellow); text-shadow: var(--glow-yellow); }
.ach-header .ach-elapsed { color: var(--color-cyan); }

.ach-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 8px;
}

.ach-ribbon {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
        "icon title"
        "icon desc";
    gap: 1px 10px;
    padding: 0.55rem 0.7rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.35);
    transition: all 0.2s;
}
.ach-ribbon.earned {
    border-color: var(--color-yellow);
    background: rgba(154, 159, 23, 0.06);
    box-shadow: 0 0 12px rgba(154, 159, 23, 0.18);
}
.ach-ribbon.missed { opacity: 0.45; }
.ach-icon {
    grid-area: icon;
    font-size: 1.5rem;
    align-self: center;
    color: var(--color-yellow);
    text-shadow: var(--glow-yellow);
    width: 24px;
    text-align: center;
}
.ach-ribbon.missed .ach-icon {
    color: var(--color-text-dim);
    text-shadow: none;
}
.ach-title {
    grid-area: title;
    font-family: var(--font-heading);
    font-size: 0.74rem;
    letter-spacing: 1px;
    color: var(--color-yellow);
}
.ach-ribbon.missed .ach-title { color: var(--color-text-dim); }
.ach-desc {
    grid-area: desc;
    font-size: 0.68rem;
    color: var(--color-text-dim);
    line-height: 1.3;
}

.kbd {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 0.72rem;
    color: var(--color-cyan);
    background: rgba(254, 232, 1, 0.05);
    margin: 0 1px;
}

/* Rotation tag block (for rotating-flag stages) */
/* Animated gradient border on panels */
.viewport,
.panel {
    position: relative;
    border: none;
}
.viewport::before,
.panel::before {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: 9px;
    padding: 1px;
    background: conic-gradient(from var(--border-angle, 0deg), rgba(254,232,1,0.4), rgba(57,196,182,0.3), rgba(254,232,1,0.1), rgba(84,193,230,0.3), rgba(254,232,1,0.4));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    z-index: -1;
    animation: border-spin 8s linear infinite;
}

@property --border-angle {
    syntax: "<angle>";
    initial-value: 0deg;
    inherits: false;
}
@keyframes border-spin {
    to { --border-angle: 360deg; }
}

/* Progress ring in topbar */
.progress-ring-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}
.progress-ring-wrap svg {
    transform: rotate(-90deg);
    flex-shrink: 0;
}
.progress-ring-bg {
    fill: none;
    stroke: rgba(254, 232, 1, 0.12);
    stroke-width: 3;
}
.progress-ring-fill {
    fill: none;
    stroke: var(--color-cyan);
    stroke-width: 3;
    stroke-linecap: round;
    filter: drop-shadow(0 0 4px rgba(254,232,1,0.5));
    transition: stroke-dashoffset 0.6s ease-out;
}
.progress-ring-text {
    font-family: var(--font-heading);
    font-size: 0.72rem;
    letter-spacing: 1px;
}

/* Achievement slide-in notification */
.ach-notif {
    position: fixed;
    top: 70px;
    right: -400px;
    z-index: 10001;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.8rem 1.2rem;
    background: var(--bg-panel-solid);
    border: 1px solid var(--color-yellow);
    border-radius: 6px;
    box-shadow: 0 0 30px rgba(154,159,23,0.25);
    animation: ach-slide-in 0.4s ease-out forwards;
    max-width: 340px;
}
.ach-notif.out {
    animation: ach-slide-out 0.35s ease-in forwards;
}
.ach-notif-icon {
    font-size: 1.8rem;
    color: var(--color-yellow);
    text-shadow: var(--glow-yellow);
    flex-shrink: 0;
}
.ach-notif-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.ach-notif-label {
    font-family: var(--font-heading);
    font-size: 0.65rem;
    letter-spacing: 2px;
    color: var(--color-text-dim);
}
.ach-notif-title {
    font-family: var(--font-heading);
    font-size: 0.82rem;
    letter-spacing: 1px;
    color: var(--color-yellow);
    text-shadow: var(--glow-yellow);
}
@keyframes ach-slide-in {
    from { right: -400px; opacity: 0; }
    to   { right: 1.5rem; opacity: 1; }
}
@keyframes ach-slide-out {
    from { right: 1.5rem; opacity: 1; }
    to   { right: -400px; opacity: 0; }
}

/* Stage 10 rate limit HUD bar */
.ratelimit-hud {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.55rem 0.9rem;
    margin-bottom: 0.9rem;
    border-radius: 3px;
    font-size: 0.78rem;
    font-family: var(--font-heading);
    letter-spacing: 1px;
    transition: all 0.3s;
}
.ratelimit-hud.locked {
    background: rgba(255, 58, 58, 0.06);
    border: 1px solid rgba(255, 58, 58, 0.35);
    border-left: 3px solid var(--color-red);
    color: var(--color-red);
}
.ratelimit-hud.open {
    background: rgba(84, 193, 230, 0.06);
    border: 1px solid rgba(84, 193, 230, 0.35);
    border-left: 3px solid var(--color-green);
    color: var(--color-green);
}
.ratelimit-hud .rl-icon {
    font-size: 1.1rem;
}
.ratelimit-hud .rl-bar {
    flex: 1;
    height: 4px;
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
    overflow: hidden;
}
.ratelimit-hud .rl-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 1s linear;
}
.ratelimit-hud.locked .rl-bar-fill {
    background: var(--color-red);
    box-shadow: 0 0 6px var(--color-red);
}
.ratelimit-hud.open .rl-bar-fill {
    background: var(--color-green);
    box-shadow: 0 0 6px var(--color-green);
}

/* Skeleton shimmer for loading states */
.skeleton {
    background: linear-gradient(90deg, rgba(254,232,1,0.04) 25%, rgba(254,232,1,0.08) 50%, rgba(254,232,1,0.04) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 3px;
}
.skeleton-line {
    height: 14px;
    margin-bottom: 10px;
    width: 100%;
}
.skeleton-line:nth-child(2) { width: 85%; }
.skeleton-line:nth-child(3) { width: 70%; }
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.rotation-block {
    margin: 0.6rem 0 0.9rem;
    padding: 0.7rem 0.9rem;
    background: rgba(57, 196, 182, 0.04);
    border: 1px solid rgba(57, 196, 182, 0.35);
    border-left: 3px solid var(--color-magenta);
    border-radius: 3px;
    font-size: 0.82rem;
}
.rotation-block .rot-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.rotation-block .rot-row + .rot-row {
    margin-top: 4px;
}
.rotation-block .rot-label {
    font-family: var(--font-heading);
    font-size: 0.7rem;
    letter-spacing: 2px;
    color: var(--color-magenta);
    text-shadow: 0 0 6px rgba(57, 196, 182, 0.5);
}
.rotation-block .rot-tag {
    font-family: var(--font-heading);
    font-weight: 900;
    font-size: 1.5rem;
    letter-spacing: 4px;
    color: var(--color-magenta);
    text-shadow: 0 0 12px rgba(57, 196, 182, 0.7);
}
.rotation-block .rot-hint { color: var(--color-text-dim); font-size: 0.74rem; }
.rotation-block .rot-countdown {
    font-family: var(--font-mono);
    color: var(--color-yellow);
    font-size: 0.78rem;
}

/* ============================================================
 * Polish: typewriter, glitch flash, decryption overlay, mute btn
 * ============================================================ */

/* Typewriter cursor */
.tw-cursor {
    display: inline-block;
    margin-left: 2px;
    color: var(--color-cyan);
    text-shadow: var(--glow-cyan);
    animation: tw-blink 0.65s steps(2, end) infinite;
}
@keyframes tw-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* Glitch flash — RGB-split + jitter + slice. Tasteful, ~300ms. */
.glitch-flash {
    position: relative;
    animation: glitch-shake 0.28s steps(6, end);
}
.glitch-flash::before,
.glitch-flash::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    mix-blend-mode: screen;
    animation: glitch-slice 0.28s ease-out;
}
.glitch-flash::before {
    background: rgba(255, 58, 58, 0.18);
    transform: translateX(-3px);
}
.glitch-flash::after {
    background: rgba(254, 232, 1, 0.18);
    transform: translateX(3px);
}
@keyframes glitch-shake {
    0%   { transform: translate(0, 0); filter: none; }
    20%  { transform: translate(-2px, 1px); filter: hue-rotate(40deg) saturate(1.4); }
    40%  { transform: translate(2px, -1px); filter: hue-rotate(-30deg); }
    60%  { transform: translate(-1px, 2px); filter: hue-rotate(60deg) saturate(1.6); }
    80%  { transform: translate(1px, 0); filter: hue-rotate(-50deg); }
    100% { transform: translate(0, 0); filter: none; }
}
@keyframes glitch-slice {
    0%   { clip-path: inset(0 0 0 0); opacity: 0; }
    20%  { clip-path: inset(45% 0 30% 0); opacity: 1; }
    50%  { clip-path: inset(15% 0 70% 0); opacity: 0.9; }
    80%  { clip-path: inset(65% 0 10% 0); opacity: 0.7; }
    100% { clip-path: inset(0 0 0 0); opacity: 0; }
}

/* Decryption overlay — shown briefly when a node is selected */
.decrypting-overlay {
    position: absolute;
    inset: 0;
    z-index: 6;
    background: rgba(5, 7, 10, 0.93);
    backdrop-filter: blur(3px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    animation: dec-fade-in 0.18s ease-out;
    padding: 2rem;
}
.decrypting-overlay.fade-out {
    animation: dec-fade-out 0.18s ease-in forwards;
}
.decrypting-title {
    font-family: var(--font-heading);
    color: var(--color-cyan);
    letter-spacing: 4px;
    text-shadow: var(--glow-cyan);
    font-size: 0.85rem;
    animation: dec-title-pulse 0.4s ease-in-out infinite alternate;
}
.decrypting-stream {
    font-family: var(--font-mono);
    color: rgba(254, 232, 1, 0.5);
    font-size: 0.7rem;
    line-height: 1.3;
    margin: 0;
    text-align: center;
    user-select: none;
    text-shadow: 0 0 4px rgba(254, 232, 1, 0.4);
    max-width: 100%;
    overflow: hidden;
    white-space: pre;
}
.decrypting-progress {
    width: 60%;
    max-width: 280px;
    height: 2px;
    background: rgba(254, 232, 1, 0.15);
    border-radius: 1px;
    overflow: hidden;
}
.decrypting-progress .bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--color-cyan), var(--color-magenta));
    box-shadow: 0 0 6px var(--color-cyan);
    transition: width 0.04s linear;
}
@keyframes dec-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes dec-fade-out {
    from { opacity: 1; }
    to   { opacity: 0; }
}
@keyframes dec-title-pulse {
    from { opacity: 0.6; letter-spacing: 4px; }
    to   { opacity: 1; letter-spacing: 5px; }
}

/* Mute button in topbar */
.mute-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--color-text-dim);
    width: 32px;
    height: 32px;
    border-radius: 3px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    font-size: 0.95rem;
    line-height: 1;
}
.mute-btn:hover {
    color: var(--color-cyan);
    border-color: var(--color-cyan);
    background: rgba(254, 232, 1, 0.05);
}
.mute-btn.muted {
    color: var(--color-red);
    border-color: rgba(255, 58, 58, 0.4);
}

/* Theme toggle button */
.theme-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--color-text-dim);
    width: 32px;
    height: 32px;
    border-radius: 3px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    font-size: 0.95rem;
    line-height: 1;
}
.theme-btn:hover {
    color: var(--color-cyan);
    border-color: var(--color-cyan);
    background: rgba(254, 232, 1, 0.05);
}

/* Sound visualizer EQ bars */
.eq-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 18px;
    padding: 0 4px;
}
.eq-bars span {
    display: block;
    width: 3px;
    border-radius: 1px;
    background: var(--color-cyan);
    box-shadow: 0 0 4px rgba(254, 232, 1, 0.4);
    animation: eq-bounce linear infinite;
}
.eq-bars span:nth-child(1) { height: 40%; animation-duration: 0.8s; }
.eq-bars span:nth-child(2) { height: 70%; animation-duration: 0.6s; animation-delay: 0.1s; }
.eq-bars span:nth-child(3) { height: 55%; animation-duration: 0.75s; animation-delay: 0.2s; }
.eq-bars span:nth-child(4) { height: 85%; animation-duration: 0.55s; animation-delay: 0.05s; }
.eq-bars span:nth-child(5) { height: 45%; animation-duration: 0.9s; animation-delay: 0.15s; }
@keyframes eq-bounce {
    0%, 100% { transform: scaleY(0.3); }
    50%      { transform: scaleY(1); }
}

/* Node hover tooltip */
.node-tooltip {
    position: fixed;
    z-index: 100;
    pointer-events: none;
    padding: 0.4rem 0.7rem;
    background: var(--bg-panel-solid);
    border: 1px solid var(--border-glow);
    border-radius: 4px;
    font-family: var(--font-heading);
    font-size: 0.7rem;
    letter-spacing: 1.5px;
    color: var(--color-cyan);
    text-shadow: var(--glow-cyan);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.15s;
    box-shadow: 0 0 16px rgba(254, 232, 1, 0.2);
}
.node-tooltip.visible {
    opacity: 1;
}
.node-tooltip .tt-status {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 1px;
    display: block;
    margin-top: 2px;
}
.node-tooltip .tt-status.solved { color: var(--color-green); }
.node-tooltip .tt-status.locked { color: var(--color-red); }
.node-tooltip .tt-status.unlocked { color: var(--color-yellow); }

/* Solve timeline ribbon (victory modal) */
.solve-timeline {
    display: flex;
    align-items: center;
    gap: 0;
    margin: 1.2rem 0 0.6rem;
    padding: 0.8rem 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 4px;
}
.solve-timeline .tl-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
    position: relative;
}
.solve-timeline .tl-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: transparent;
    transition: all 0.3s;
}
.solve-timeline .tl-node.solved .tl-dot {
    background: var(--color-green);
    border-color: var(--color-green);
    box-shadow: var(--glow-green);
}
.solve-timeline .tl-node.master .tl-dot {
    border-color: var(--color-magenta);
}
.solve-timeline .tl-node.master.solved .tl-dot {
    background: var(--color-magenta);
    box-shadow: 0 0 10px rgba(57, 196, 182, 0.5);
}
.solve-timeline .tl-label {
    font-family: var(--font-heading);
    font-size: 0.55rem;
    letter-spacing: 1px;
    color: var(--color-text-dim);
}
.solve-timeline .tl-node.solved .tl-label {
    color: var(--color-green);
}
.solve-timeline .tl-line {
    flex: 1;
    height: 2px;
    background: var(--border-color);
    min-width: 8px;
}
.solve-timeline .tl-line.filled {
    background: var(--color-green);
    box-shadow: 0 0 4px rgba(84, 193, 230, 0.4);
}

/* Mobile responsive layout */
@media (max-width: 768px) {
    .console-grid {
        grid-template-columns: 1fr;
        grid-template-rows: 45vh 1fr;
        padding: 0.5rem;
        gap: 0.5rem;
    }
    .topbar {
        padding: 0.6rem 0.8rem;
    }
    .brand {
        font-size: 0.82rem;
        letter-spacing: 2px;
    }
    .progress-ring-text {
        font-size: 0.62rem;
    }
    .panel-body {
        padding: 0.7rem;
    }
    .master-bar {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 0.7rem 0.8rem;
    }
    .master-bar .master-label {
        font-size: 0.68rem;
    }
    .master-bar input {
        font-size: 0.8rem;
    }
    .viewport-help {
        font-size: 0.6rem;
        padding: 3px 8px;
    }
    .ach-notif {
        max-width: 280px;
        padding: 0.6rem 0.8rem;
    }
    .ach-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .console-grid {
        grid-template-rows: 35vh 1fr;
    }
    .progress-ring-wrap svg {
        width: 30px;
        height: 30px;
    }
    .flag-submit {
        grid-template-columns: 1fr;
    }
    .flag-submit .btn {
        width: 100%;
    }
}

/* ── Wrong-flag taunt bubbles ─────────────────────────────────── */
@keyframes taunt-shake {
    0%, 100% { transform: translateX(0); }
    10% { transform: translateX(-6px) rotate(-1deg); }
    20% { transform: translateX(5px) rotate(1deg); }
    30% { transform: translateX(-4px); }
    40% { transform: translateX(3px); }
    50% { transform: translateX(-2px); }
    60% { transform: translateX(0); }
}
@keyframes taunt-glow-pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(255, 58, 58, 0.25), inset 0 0 12px rgba(255, 58, 58, 0.04); }
    50% { box-shadow: 0 0 20px rgba(255, 58, 58, 0.45), inset 0 0 18px rgba(255, 58, 58, 0.08); }
}
.taunt-bubble {
    margin-top: 0.8rem;
    padding: 0.9rem 1.1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 58, 58, 0.5);
    background: rgba(255, 58, 58, 0.1);
    font-size: 1rem;
    line-height: 1.6;
    color: #ff6b6b;
    opacity: 0;
    transform: translateY(14px) scale(0.95);
    transition: opacity 0.4s cubic-bezier(0.22, 1, 0.36, 1), transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    overflow: hidden;
    box-shadow: 0 0 12px rgba(255, 58, 58, 0.3), inset 0 0 12px rgba(255, 58, 58, 0.04);
}
.taunt-bubble.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    animation: taunt-shake 0.5s 0.15s ease-out, taunt-glow-pulse 2s 0.6s ease-in-out infinite;
}
.taunt-text {
    display: block;
    font-style: italic;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-shadow: 0 0 8px rgba(255, 58, 58, 0.35);
}
.taunt-gif {
    display: block;
    margin-top: 0.7rem;
    width: 100%;
    max-width: 280px;
    border-radius: 6px;
    border: 1px solid rgba(255, 58, 58, 0.35);
    box-shadow: 0 0 14px rgba(255, 58, 58, 0.2);
}
.master-bar .taunt-bubble {
    grid-column: 1 / -1;
}

/* ── Mobile node list overlay ─────────────────────────────── */
.node-list-mobile {
    display: none;
}

@media (max-width: 480px) {
    .node-list-mobile {
        display: flex;
        gap: 8px;
        padding: 8px 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 10;
        background: linear-gradient(0deg, rgba(0,6,14,0.95) 0%, transparent 100%);
        padding-top: 24px;
    }
    .node-list-mobile::-webkit-scrollbar { display: none; }

    .node-chip {
        flex-shrink: 0;
        padding: 6px 14px;
        border: 1px solid var(--border-color);
        border-radius: 999px;
        font-family: var(--font-heading);
        font-size: 0.65rem;
        letter-spacing: 1px;
        color: var(--color-text-dim);
        background: rgba(0,0,0,0.6);
        cursor: pointer;
        white-space: nowrap;
        transition: all 0.15s;
        backdrop-filter: blur(6px);
    }
    .node-chip:active {
        transform: scale(0.95);
    }
    .node-chip.solved {
        border-color: rgba(84,193,230,0.4);
        color: var(--color-green);
    }
    .node-chip.open {
        border-color: #33ff77;
        color: #33ff77;
        box-shadow: 0 0 8px rgba(51,255,119,0.35);
        animation: chip-open-pulse 1.6s ease-in-out infinite;
    }
    .node-chip.active {
        border-color: var(--color-cyan);
        color: var(--color-cyan);
        background: rgba(254,232,1,0.08);
        box-shadow: 0 0 8px rgba(254,232,1,0.2);
    }
    .node-chip.locked {
        opacity: 0.4;
    }
    .node-chip.ghost {
        border-color: rgba(57,196,182,0.4);
        color: var(--color-magenta);
    }
}

@keyframes chip-open-pulse {
    0%, 100% { box-shadow: 0 0 6px rgba(51,255,119,0.25); }
    50% { box-shadow: 0 0 14px rgba(51,255,119,0.6); }
}

@media (max-width: 380px) {
    .topbar {
        padding: 0.4rem 0.5rem;
        gap: 4px;
    }
    .brand {
        font-size: 0.65rem;
        letter-spacing: 1px;
        gap: 6px;
    }
    .brand .dot {
        width: 7px;
        height: 7px;
    }
    .session-chip {
        display: none;
    }
    .mute-btn, .theme-btn {
        width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }
    .btn-danger {
        font-size: 0.6rem;
        padding: 0.2rem 0.5rem;
    }
    /* Hide scoreboard link on tiny screens */
    .topbar .btn-outline {
        display: none;
    }
}

@media (max-width: 480px) {
    .panel-header {
        padding: 0.6rem 0.8rem;
        font-size: 0.68rem;
    }
    .panel-header .status-tag {
        font-size: 0.62rem;
    }
    .narrative-block {
        padding: 0.7rem;
        font-size: 0.82rem;
    }
    .flavour-block {
        padding: 0.5rem 0.7rem;
        font-size: 0.72rem;
    }
    .download-row {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }
    .download-row .btn {
        text-align: center;
    }
    .meta-pill {
        font-size: 0.6rem;
        padding: 2px 7px;
    }
    .victory-modal .card {
        padding: 1.2rem;
    }
    .victory-modal h2 {
        font-size: 1rem;
        letter-spacing: 2px;
    }
    .solve-timeline {
        padding: 0.5rem 0.3rem;
        margin: 0.8rem 0 0.4rem;
    }
    .solve-timeline .tl-dot {
        width: 8px;
        height: 8px;
    }
    .solve-timeline .tl-label {
        font-size: 0.45rem;
    }
    .ach-ribbon {
        padding: 0.4rem 0.5rem;
    }
    .ach-icon {
        font-size: 1.2rem;
    }
    .ach-title {
        font-size: 0.65rem;
    }
    .ach-desc {
        font-size: 0.6rem;
    }
}

@media (max-width: 768px) {
    .viewport-help {
        display: none;
    }
    .viewport-controls {
        top: 0.5rem;
        right: 0.5rem;
    }
}

/* ── Onboarding tour ─────────────────────────────────────── */
.tour-overlay {
    position: fixed;
    inset: 0;
    z-index: 10003;
    background: rgba(0, 3, 8, 0.85);
    animation: tour-in 0.3s ease-out;
}
.tour-overlay.tour-fade-out {
    animation: tour-out 0.3s ease-in forwards;
}
@keyframes tour-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes tour-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

.tour-spotlight {
    position: fixed;
    border: 2px solid var(--color-cyan);
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0, 3, 8, 0.85), 0 0 30px rgba(254, 232, 1, 0.3);
    transition: all 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 10004;
    pointer-events: none;
}

.tour-tooltip {
    position: fixed;
    z-index: 10005;
    width: 320px;
    background: var(--bg-panel-solid);
    border: 1px solid var(--color-cyan);
    border-radius: 8px;
    padding: 1.2rem 1.4rem;
    box-shadow: 0 0 40px rgba(254, 232, 1, 0.2);
    animation: tour-tooltip-in 0.35s ease-out;
    transition: left 0.4s cubic-bezier(0.22, 1, 0.36, 1), top 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes tour-tooltip-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.tour-title {
    font-family: var(--font-heading);
    font-size: 0.82rem;
    letter-spacing: 3px;
    color: var(--color-cyan);
    text-shadow: var(--glow-cyan);
    margin-bottom: 0.6rem;
}

.tour-text {
    font-size: 0.82rem;
    color: var(--color-text);
    line-height: 1.6;
    margin-bottom: 1rem;
}

.tour-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tour-skip {
    background: none;
    border: none;
    color: var(--color-text-dim);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    cursor: pointer;
    padding: 0.3rem 0;
    transition: color 0.15s;
}
.tour-skip:hover {
    color: var(--color-text);
}

.tour-next {
    background: var(--color-cyan);
    color: #00060e;
    border: none;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.72rem;
    letter-spacing: 2px;
    padding: 0.5rem 1.2rem;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.15s;
}
.tour-next:hover {
    background: #ffed4a;
    box-shadow: var(--glow-cyan);
}

.tour-counter {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10005;
    font-family: var(--font-heading);
    font-size: 0.7rem;
    letter-spacing: 2px;
    color: var(--color-text-dim);
}

/* Mobile tour adjustments */
@media (max-width: 768px) {
    .tour-tooltip {
        width: calc(100vw - 32px);
        max-width: 320px;
    }
}

/* --- Difficulty badges --- */
.difficulty-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font-heading);
    font-size: 0.6rem;
    letter-spacing: 1.5px;
    padding: 2px 8px;
    border-radius: 2px;
    border: 1px solid;
    text-transform: uppercase;
}
.difficulty-badge.easy    { color: #4ade80; border-color: #4ade8044; background: #4ade8010; }
.difficulty-badge.medium  { color: var(--color-yellow); border-color: var(--color-yellow-dim, #fee80144); background: #fee80110; }
.difficulty-badge.hard    { color: #f97316; border-color: #f9731644; background: #f9731610; }
.difficulty-badge.expert  { color: #ef4444; border-color: #ef444444; background: #ef444410; }
.difficulty-badge.unsolved { color: var(--color-magenta, #e879f9); border-color: #e879f944; background: #e879f910; }
.difficulty-badge .diff-dots {
    display: inline-flex;
    gap: 2px;
}
.difficulty-badge .diff-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.3;
}
.difficulty-badge .diff-dot.filled { opacity: 1; }

.difficulty-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.7rem;
    color: var(--color-text-dim);
    margin-bottom: 0.5rem;
    font-family: var(--font-body);
}
.difficulty-info .pts {
    font-family: var(--font-heading);
    letter-spacing: 1px;
    color: var(--color-cyan);
}
.difficulty-info .solves {
    opacity: 0.7;
}

/* ── Hint section ─────────────────────────────────────────── */
.hint-section {
    margin-bottom: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    overflow: hidden;
}
.hint-header {
    padding: 0.55rem 0.9rem;
    font-family: var(--font-heading);
    font-size: 0.7rem;
    letter-spacing: 2px;
    color: var(--color-yellow);
    text-shadow: var(--glow-yellow);
    cursor: pointer;
    background: rgba(154, 159, 23, 0.04);
    transition: background 0.15s;
}
.hint-header:hover {
    background: rgba(154, 159, 23, 0.08);
}
.hint-slots {
    border-top: 1px solid var(--border-color);
}
.hint-slots.hidden { display: none; }
.hint-slot {
    padding: 0.6rem 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
}
.hint-slot + .hint-slot {
    border-top: 1px solid rgba(254, 232, 1, 0.06);
}
.hint-slot .hint-label {
    font-family: var(--font-heading);
    font-size: 0.65rem;
    letter-spacing: 1.5px;
    color: var(--color-text-dim);
    flex-shrink: 0;
    min-width: 48px;
}
.hint-slot .hint-cost {
    font-family: var(--font-heading);
    font-size: 0.6rem;
    letter-spacing: 1px;
    color: var(--color-red);
    flex-shrink: 0;
}
.hint-slot .hint-cost.free {
    color: var(--color-green);
}
.hint-slot .hint-reveal-btn {
    margin-left: auto;
    font-size: 0.62rem;
    padding: 0.2rem 0.6rem;
}
.hint-slot.revealed {
    background: rgba(84, 193, 230, 0.04);
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}
.hint-slot.revealed .hint-label {
    color: var(--color-cyan);
}
.hint-slot .hint-text {
    color: var(--color-text);
    line-height: 1.5;
    font-size: 0.82rem;
}

/* ── Challenge timer ──────────────────────────────────────── */
.challenge-timer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0.45rem 0.9rem;
    margin-bottom: 0.9rem;
    border: 1px solid rgba(84, 193, 230, 0.2);
    border-radius: 3px;
    background: rgba(84, 193, 230, 0.03);
    font-family: var(--font-heading);
    font-size: 0.72rem;
    letter-spacing: 1px;
}
.challenge-timer .timer-icon {
    font-size: 0.9rem;
}
.challenge-timer .timer-label {
    color: var(--color-text-dim);
}
.challenge-timer .timer-value {
    color: var(--color-cyan);
    text-shadow: var(--glow-cyan);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    letter-spacing: 2px;
}

/* ── Writeup section ──────────────────────────────────────── */
.writeup-section {
    margin-top: 0.8rem;
}
.writeup-toggle {
    font-size: 0.68rem;
    letter-spacing: 1.5px;
}
.writeup-body {
    margin-top: 0.6rem;
    padding: 0.8rem 0.9rem;
    background: rgba(84, 193, 230, 0.04);
    border: 1px solid rgba(84, 193, 230, 0.25);
    border-left: 2px solid var(--color-green);
    border-radius: 3px;
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--color-text);
    animation: writeup-in 0.3s ease-out;
}
.writeup-body.hidden { display: none; }
@keyframes writeup-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
