﻿* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* ═══════════════════════════════════════════════════════════
   THEME TOKENS  —  Light (default) values mirror the original
   hard-coded colours exactly so the light theme is unchanged.
   ═══════════════════════════════════════════════════════════ */
:root {
    /* ── Surfaces (layering system) ── */
    --background:      #f5f5f5;
    --surface:         #ffffff;    /* cards, modals, menus, sidebars, popups */
    --surface-raised:  #ffffff;    /* inputs, float btns, action btns — elevated on dark */
    --surface2:        #f8f9fa;    /* headers, code blocks, info btns, algo lines */
    --modal-header-bg: #f8f9fa;    /* modal/panel headers — different dark value (#16181f) */
    --surface-border:  #e9ecef;    /* dividers, tracks, section borders, avatar ring */
    --border-color:    #dddddd;    /* input and card borders (slightly stronger) */

    /* ── Typography ── */
    --text-primary:   #333333;     /* cube faces and text that should stand out */
    --text-ui:        #2d3748;     /* normal interface text */
    --text-secondary: #666666;     /* muted labels, icons, descriptions, subtitles */
    --text-muted:     #999999;     /* disabled, empty states, finish moves, close btn */
    --text-on-color:  #ffffff;     /* text/icons on saturated or always-dark surfaces */

    /* ── Accent / interactive ── */
    --bar-learned:       #28a745;
    --bar-learning:      #ffa000;
    --accent:            #007bff;
    --accent-hover:      #0056b3;
    --focus-ring:        #007bff;  /* keyboard-nav focus outline */
    --link-color:        #007bff;  /* links + menu selected — dark value differs from accent */
    --hover-bg:          #e3f2fd;  /* row hover, menu selection bg, popup input hover */
    --step-highlight-bg: #f0f9ff;  /* shape-path step chips, popup step spans */
    --select-option-selected-bg: #dbeafe;

    /* ── Floating buttons (sidebar, profile, theme toggle) ── */
    --floating-btn-color:  #000000;
    --floating-btn-shadow: rgba(123, 123, 123, 0.4);

    /* ── Sidebar ── */
    --sidebar-item-hover:  #f8f9fa;   /* also absorbs menu-item-hover */
    --sidebar-close-color: #6c757d;

    /* ── Modals ── */
    --modal-overlay:    rgba(0, 0, 0, 0.6);

    /* ── Algorithm display ── */
    --algo-setup-color:   #6d739c;
    --z2-prefix-color:    #007afc;
    --algo-invalid-color: #dc3545;

    /* ── Parity cell colors ── */
    --parity-odd:         #00a126;
    --parity-even:        #0069d9;
    --parity-odd-mirror:  #006b1a;
    --parity-even-mirror: #004a9f;
    --parity-invalid:     #71000b;

    /* ── Parity tracer: trace-order badges ── */
    --trace-badge-base:   #c4202c;
    --trace-badge-fg:     #ffffff;

    /* ── SVG ── */
    --svg-stroke:   #1a1a1a;
    --svg-fill:     #ffffff;
    --svg-label-bg: rgba(255, 255, 255, 0.75);
    --card-labels:  #5177ff;

    /* ── Card chrome ── */
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
    --nice-case:   #007900;
    --evil-case:    #8b0000;

    /* ── Card states ── */
    --card-learned-bg: #d4edda;   --card-learned-border: #28a745;
    --card-learned-header: #c3e6cb;  --card-learned-svg: #e8f5e9;
    --card-planned-bg: #cce5ff;   --card-planned-border: #007bff;
    --card-planned-header: #b8daff;
    --card-learning-bg: #fff3cd;  --card-learning-border: #ffc107;
    --card-learning-header: #ffe69c; --card-learning-svg: #fffae6;

    /* ── Evil-case picker ── */
    --evil-case-bg:     #ffe0e0;
    --evil-case-border: #e53e3e;
    --evil-case-text:   #7b1c1c;
    --nice-case-bg:     #e8f5e9;
    --nice-case-border: #38a169;
    --nice-case-text:   #1a4731;

    /* ── Priority tiers ── */
    --p1-bg: #b3d9ff; --p1-border: #80bfff; --p1-header: #cce6ff; --p1-svg: #d9edff;
    --p2-bg: #d4ebf7; --p2-border: #a9d6ed; --p2-header: #e3f2fa; --p2-svg: #e8f4fa;
    --p3-bg: #e0ffff; --p3-border: #b8e6e6; --p3-header: #f0ffff; --p3-svg: #f0ffff;
    --p4-bg: #ffffff; --p4-border: #dddddd; --p4-header: #f8f9fa; --p4-svg: #ffffff;
    --p5-bg: #f5deb3; --p5-border: #d4be94; --p5-header: #f8e8c8; --p5-svg: #faf0dd;
    --p6-bg: #e6c8a0; --p6-border: #d4b894; --p6-header: #f0ddc8; --p6-svg: #f5e6d9;
    --p7-bg: #c4c4c4; --p7-border: #909090; --p7-header: #d2d2d2; --p7-svg: #d8d8d8;

    /* ── Info box ── */
    --info-box-bg:    rgba(0, 0, 0, 0.75);
    --info-box-color: var(--text-on-color);

    /* ── Scrollbar ── */
    --scrollbar-thumb:       rgba(0, 0, 0, 0.2);
    --scrollbar-thumb-hover: rgba(0, 0, 0, 0.4);

    /* ── Misc UI ── */
    --loading-overlay-bg:      rgba(255, 255, 255, 0.95);
    --spinner-track:           #f3f3f3;
    --progress-track:          #e9ecef;
    --about-header-bg:         #1f2933;
    --about-link-color:        #2563eb;
    --warning-bg:              #fff3cd;
    --warning-border:          #ffc107;
    --warning-color:           #856404;
    --btn-safe:                #c1e6ca;
    --btn-danger-soft:         #f2dadc;
    --delete-btn-bg:           #d0d0d0;
    --avatar-border-idle:      #e9ecef;
    --prevscramble-bar-bg:     #f0f0f0;
    --prevscramble-bar-border: #e0e0e0;
    --prevscramble-empty-color:#bbbbbb;

    /* ── Profile progress bars ── */
    --bar-learned:   #28a745;
    --bar-learning:  #ffc107;
    --bar-coverage:  linear-gradient(90deg, #007bff, #0056b3);
    --bar-safety:    linear-gradient(90deg, #ffc107, #ff8c00);

    /* ── Toast ── */
    --toast-success-bg: #c9ffd6;
    --toast-error-bg:   #ffd7db;
    --toast-info-bg:    #d1d1d1;
    --toast-color:      #000000;

    /* ── Always-dark header chrome (svg-editor, quick-edit) ── */
    --header-dark-bg:   #2d3748;

    /* ── Search highlight ── */
    --search-highlight-bg:    #ffeb3b;
    --search-highlight-color: #000000;

    --double-align-color:    #007afc;
    --double-misalign-color: #dc3545;
}

/* ═══════════════════════════════════════════════════════════
   DARK THEME OVERRIDES
   All contrast ratios are WCAG AA compliant (≥4.5:1 for
   normal text). Canonical white cube faces resolve to --text-primary
   in dark mode; internal SVG mask geometry remains white.
   ═══════════════════════════════════════════════════════════ */
[data-theme="dark"] {
    color-scheme: dark;

    --background:      #12141a;
    --surface:         #1c1f28;
    --surface-raised:  #2b2f3a;
    --surface2:        #242730;
    --modal-header-bg: #16181f;
    --surface-border:  rgba(255, 255, 255, 0.09);
    --border-color:    rgba(255, 255, 255, 0.13);

    --text-primary:   #e2e4ed;
    --text-ui:        #c4c8d8;
    --text-secondary: #9299b0;
    --text-muted:     #6b7080;
    --text-on-color:  var(--text-primary);

    --accent:            #3a7bd5;
    --accent-hover:      #5596f0;
    --focus-ring:        #6a9ef8;  /* keyboard-nav focus outline */
    --link-color:        #6a9ef8;
    --hover-bg:          #1e2535;
    --step-highlight-bg: #1a1e2a;
    --select-option-selected-bg: #263e62;

    --floating-btn-color:  #e2e4ed;
    --floating-btn-shadow: rgba(0, 0, 0, 0.65);

    --sidebar-item-hover:  rgba(255, 255, 255, 0.06);
    --sidebar-close-color: #7a8099;

    --modal-overlay:    rgba(0, 0, 0, 0.76);
    --modal-algo-label: #4ade80;

    --algo-setup-color:   #9098cc;
    --z2-prefix-color:    #6a9ef8;
    --algo-invalid-color: #ff6b6b;

    --parity-odd:         #63c98f;
    --parity-even:        #79a9d6;
    --parity-odd-mirror:  #4b9c70;
    --parity-even-mirror: #5e86b2;
    --parity-invalid:     #d96b73;

    --trace-badge-base:   #d03540;
    --trace-badge-fg:     #ffffff;

    --svg-stroke:   #c8ccd8;
    --svg-fill:     var(--text-primary);
    --svg-label-bg: rgba(30, 32, 40, 0.75);
    --card-labels:  #7fa8ff;

    --card-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    --nice-case:   #00b100;
    --evil-case:    #fe8d8d;

    --card-learned-bg: #0f2117;   --card-learned-border: #2a7a3e;
    --card-learned-header: #132819;  --card-learned-svg: #162c1a;
    --card-planned-bg: #0e1f3a;   --card-planned-border: #2558a0;
    --card-planned-header: #122344;
    --card-learning-bg: #221a0d;  --card-learning-border: #a47818;
    --card-learning-header: #292010; --card-learning-svg: #2c2212;

    --evil-case-bg:     #3a1f26;
    --evil-case-border: #d35f6b;
    --evil-case-text:   #ffb8be;
    --nice-case-bg:     #183524;
    --nice-case-border: #49b978;
    --nice-case-text:   #a8e6bd;

    --p1-bg: #0e2240; --p1-border: #2558a0; --p1-header: #122648; --p1-svg: #102440;
    --p2-bg: #112232; --p2-border: #236080; --p2-header: #162a3c; --p2-svg: #142838;
    --p3-bg: #082424; --p3-border: #1a6060; --p3-header: #0e2e2e; --p3-svg: #0e2e2e;
    --p4-bg: #1c1f28; --p4-border: rgba(255,255,255,0.10); --p4-header: #242730; --p4-svg: #1c1f28;
    --p5-bg: #261c04; --p5-border: #705020; --p5-header: #2e2208; --p5-svg: #221800;
    --p6-bg: #261400; --p6-border: #6a3810; --p6-header: #2e1804; --p6-svg: #221000;
    --p7-bg: #252832; --p7-border: #585c70; --p7-header: #2e3040; --p7-svg: #2a2d3a;

    --info-box-bg:    rgba(6, 8, 14, 0.94);
    --info-box-color: var(--text-primary);

    --scrollbar-thumb:       rgba(255, 255, 255, 0.12);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.24);

    --loading-overlay-bg:      rgba(18, 20, 26, 0.95);
    --spinner-track:           #2d3040;
    --progress-track:          #2a2d3d;
    --about-header-bg:         #0d1117;
    --about-link-color:        #6a9ef8;
    --warning-bg:              #2a1f00;
    --warning-border:          #9c7010;
    --warning-color:           #d4a843;
    --btn-safe:                #7a917f;
    --btn-danger-soft:         #b3797e;
    --delete-btn-bg:           #3a3d4a;
    --avatar-border-idle:      rgba(255, 255, 255, 0.15);
    --prevscramble-bar-bg:     #1c1f28;
    --prevscramble-bar-border: #242730;
    --prevscramble-empty-color: #454860;

    /* ── Profile progress bars ── */
    --bar-learned:   #2a7a3e;
    --bar-learning:  #9c7010;
    --bar-coverage:  linear-gradient(90deg, #2558a0, #3a6ec0);
    --bar-safety:    linear-gradient(90deg, #9c7010, #df853c);

    /* ── Always-dark header chrome ── */
    --header-dark-bg:   #16181f;

    --toast-success-bg: #1e5234;
    --toast-error-bg:   #921023;
    --toast-info-bg:    #103394;
    --toast-color:      var(--text-primary);

    --search-highlight-bg:    #d9b92e;
    --search-highlight-color: #14161c;

    --double-align-color:    #6a9ef8;
    --double-misalign-color: #ff6b6b;
}

/* ═══════════════════════════════════════════════════════════
   SMOOTH THEME TRANSITIONS  (only properties that change)
   ═══════════════════════════════════════════════════════════ */
body,
.card, .card-header, .card-images, .card-svg-container,
.topbar, .modal-content, .modal-header, .modal-algo-line,
.sidebar-content, .sidebar-item,
.algo-popup, .settings-info-btn,
input[type="text"], select,
.floating-profile-btn, .sidebar-toggle-btn, .theme-toggle-btn,
.profile-popup-content, footer, footer a {
    transition:
        background-color 0.25s ease,
        background      0.25s ease,
        border-color    0.25s ease,
        color           0.25s ease,
        box-shadow      0.25s ease;
}

/* ═══════════════════════════════════════════════════════════
   FOCUS RING  —  designed outline, keyboard navigation only.
   `data-input-modality` is stamped on <html> by focusRing.ts:
     • "pointer"  → mouse/touch focus, no ring
     • "keyboard" → Tab / Esc navigation, show the ring
   Until that attribute exists (JS failed to load) the browser's
   default focus ring is left untouched.
   ═══════════════════════════════════════════════════════════ */
html[data-input-modality] :focus {
    outline: none;
}

html[data-input-modality="keyboard"] :focus {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

html, body {
    height: 100%;
}

html {
    overflow-y: hidden;
}

::-webkit-scrollbar {
    width: 9px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

@media (hover: hover) {
    ::-webkit-scrollbar-thumb:hover {
        background: var(--scrollbar-thumb-hover);
    }
}

html.scroll-locked body {
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-ui);
    padding: 20px;
    overflow-y: scroll;
    scrollbar-gutter: stable;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

h1 {
    font-size: 3rem;
    margin-bottom: 5px;
    color: var(--text-ui);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 10px;
}

.controls {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    align-items: center;
    position: relative;
    width: 100%;
}

/* Match grid max-width for 1 column mode */
@media (max-width: 569px) {
    .controls {
        max-width: 430px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* Match grid max-width for 2 column mode */
@media (min-width: 570px) and (max-width: 1039px) {
    .controls {
        max-width: 900px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* Match grid max-width for 3 column mode */
@media (min-width: 1040px) and (max-width: 1659px) {
    .controls {
        max-width: 1540px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* Match grid max-width for 4 column mode */
@media (min-width: 1660px) and (max-width: 2099px) {
    .controls {
        max-width: 2040px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* Match grid max-width for 5 column mode */
@media (min-width: 2100px) and (max-width: 2599px) {
    .controls {
        max-width: 2540px;
        margin-left: auto;
        margin-right: auto;
    }
}

.search-toggle-btn {
    display: none;
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 8px;
    background: var(--accent);
    color: var(--text-on-color);
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
    align-items: center;
    justify-content: center;
}

@media (hover: hover) {
    .search-toggle-btn:hover {
        background: var(--accent-hover);
        transform: scale(1.05);
    }
}

.search-toggle-btn .themed-icon {
    width: 22px;
    height: 22px;
}

input[type="text"] {
    flex: 2;
    min-width: 200px;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 1rem;
    background: var(--surface-raised);
    color: var(--text-ui);
}

select {
    flex: 1;
    min-width: 150px;
    padding: 10px 36px 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--surface-raised);
    color: var(--text-ui);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%236b7280' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

@media (hover: hover) {
    select:not(:disabled):hover {
        border-color: var(--accent);
    }
}

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

select option {
    background: var(--surface);
    color: var(--text-ui);
}

select option:checked,
select option:hover {
    background: var(--select-option-selected-bg);
    color: var(--text-ui);
}

[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%23a0a7b4' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
}

.custom-dropdown {
    position: relative;
    display: inline-flex;
    flex: 1;
    min-width: 150px;
}

.custom-dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-width: 0;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-raised);
    color: var(--text-ui);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.custom-dropdown-trigger::after {
    content: '';
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    background-color: var(--text-secondary);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
    transform: rotate(0deg);
    transform-origin: center;
    transition: transform 0.2s ease;
}

.custom-dropdown-trigger[aria-expanded="true"] {
    border-color: var(--accent);
}

.custom-dropdown-trigger[aria-expanded="true"]::after {
    transform: rotate(180deg);
}

@media (hover: hover) {
    .custom-dropdown-trigger:not(:disabled):hover {
        border-color: var(--accent);
    }
}

.custom-dropdown-trigger:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.custom-dropdown-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-dropdown-menu {
    position: absolute;
    z-index: 12000;
    top: calc(100% + 5px);
    left: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    max-height: 260px;
    overflow-y: auto;
    padding: 5px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

.custom-dropdown-menu[hidden] {
    display: none;
}

.custom-dropdown-menu--above {
    top: auto;
    bottom: calc(100% + 5px);
}

.custom-dropdown-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    width: 100%;
    padding: 9px 11px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-ui);
    font: inherit;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.custom-dropdown-option[aria-selected="true"] {
    background: var(--select-option-selected-bg);
    color: var(--link-color);
}

@media (hover: hover) {
    .custom-dropdown-option:not(:disabled):hover {
        background: var(--hover-bg);
        color: var(--text-ui);
    }
}

.custom-dropdown-option:disabled {
    color: var(--text-muted);
    cursor: not-allowed;
}

.custom-dropdown-check {
    width: 1em;
    flex: 0 0 1em;
    color: var(--link-color);
    text-align: center;
}

.custom-dropdown--fit-options {
    width: max-content;
    max-width: 100%;
    flex: 0 1 auto;
}

.custom-dropdown--fit-options .custom-dropdown-trigger {
    display: grid;
    grid-template-columns: max-content 16px;
    width: max-content;
    max-width: 100%;
    padding: 5px 8px;
}

.custom-dropdown--fit-options .custom-dropdown-label,
.custom-dropdown-measure {
    grid-area: 1 / 1;
}

.custom-dropdown-measure {
    visibility: hidden;
    white-space: nowrap;
    padding-right: 16px;
}

.custom-dropdown--fit-options .custom-dropdown-trigger::after {
    grid-area: 1 / 2;
}

.custom-dropdown--fit-options .custom-dropdown-menu {
    width: max-content;
    min-width: 100%;
}

.custom-dropdown--fit-options .custom-dropdown-option {
    white-space: nowrap;
    padding-right: 3px;
}

.custom-dropdown--fit-options .custom-dropdown-option > span:first-child {
    text-align: left;
}

.custom-dropdown-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
}

.grid {
    display: grid;
    gap: 20px;
    width: 100%;
}

/* 1 column mode: 0-570px, max card width 430px */
@media (max-width: 569px) {
    .grid {
        grid-template-columns: 1fr;
        max-width: 430px;
        margin: 0 auto;
        gap: 15px;
    }
}

@media (max-width: 420px) {
    .grid {
        gap: 12px;
    }
}

/* 2 column mode: 570-1039px, card width 270-430px */
@media (min-width: 570px) and (max-width: 1039px) {
    .grid {
        grid-template-columns: repeat(2, 1fr);
        max-width: 900px;
        margin: 0 auto;
    }
}

/* 3 column mode: 1040-1659px, card width 330-500px */
@media (min-width: 1040px) and (max-width: 1659px) {
    .grid {
        grid-template-columns: repeat(3, 1fr);
        max-width: 1540px;
        margin: 0 auto;
    }
}

/* 4 column mode: 1660-2099px, card width 415-500px */
@media (min-width: 1660px) and (max-width: 2099px) {
    .grid {
        grid-template-columns: repeat(4, 1fr);
        max-width: 2040px;
        margin: 0 auto;
    }
}

/* 5+ column mode: 2100px+, min card width 420px */
@media (min-width: 2100px) {
    .grid {
        grid-template-columns: repeat(5, 1fr);
        max-width: 2540px;
        margin: 0 auto;
    }
}

/* 6+ column mode: 2600px+ */
@media (min-width: 2600px) {
    .grid {
        grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
        max-width: none;
    }
}

.card {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--card-shadow);
    overflow: hidden;
    transition: all 0.3s ease;
    border: 1px solid var(--border-color);
}

.card.learned {
    background: var(--card-learned-bg);
    border: 2px solid var(--card-learned-border);
}

.card.planned {
    background: var(--card-planned-bg);
    border: 2px solid var(--card-planned-border);
}

.card.learning {
    background: var(--card-learning-bg);
    border: 2px solid var(--card-learning-border);
}

.card-header {
    padding: min(15px, 1.5vw);
    background: var(--surface2);
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
}

.card.learned .card-header {
    background: var(--card-learned-header);
}

.card.planned .card-header {
    background: var(--card-planned-header);
}

.card.learning .card-header {
    background: var(--card-learning-header);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-ui);
    flex: 1;
}

.card-header-actions {
    display: flex;
    gap: min(8px, 0.8vw);
    align-items: center;
}

.icon-btn {
    width: min(28px, 2.5vw);
    height: min(28px, 2.5vw);
    min-width: 20px;
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
}

@media (hover: hover) {
    .icon-btn:hover {
        transform: scale(1.1);
    }
}

.icon-btn svg {
    width: 100%;
    height: 100%;
    display: block;
}

.probability {
    color: var(--card-labels);
    font-size: 0.9rem;
    font-weight: 500;
}

@media (max-width: 420px) {
    .probability {
        font-size: 0.75rem;
    }
}

@media (max-width: 360px) {
    .probability {
        font-size: 0.7rem;
    }
}

.card-images {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--surface-border);
    overflow: hidden;
}

.card-images img {
    width: 50%;
    height: auto;
    display: block;
}

.card-svg-container {
    width: 100%;
    aspect-ratio: 2 / 1 !important;
    display: flex;
    overflow: hidden;
    position: relative;
}

.card-svg-container > div {
    width: 50%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-svg-container svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.card-svg-container svg {
    transition: transform 0.3s ease;
}

.card-body {
    padding: min(15px, 1.5vw);
}

.sqg-skeleton-card {
    pointer-events: none;
    overflow: hidden;
    min-height: var(--sqg-card-estimated-height, 360px);
}

.sqg-skeleton-line,
.sqg-skeleton-shape {
    position: relative;
    display: block;
    overflow: hidden;
    background: var(--surface2);
    border-radius: 4px;
}

.sqg-skeleton-line::after,
.sqg-skeleton-shape::after {
    content: '';
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(
        90deg,
        transparent,
        color-mix(in srgb, var(--surface-raised) 70%, transparent),
        transparent
    );
    animation: sqgSkeletonGlint 1.15s ease-in-out infinite;
}

.sqg-skeleton-card .card-header {
    min-height: 55px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sqg-skeleton-title {
    width: 48%;
    height: 18px;
}

.sqg-skeleton-prob {
    width: 64px;
    height: 16px;
}

.sqg-skeleton-shape {
    width: min(70%, 96px);
    aspect-ratio: 1;
    border-radius: 50%;
}

.sqg-skeleton-card .card-body {
    display: grid;
    gap: 9px;
}

.sqg-skeleton-card .card-body .sqg-skeleton-line {
    height: 13px;
}

.sqg-skeleton-line-short {
    width: 58%;
}

.sqg-skeleton-line-mid {
    width: 76%;
}

@keyframes sqgSkeletonGlint {
    100% {
        transform: translateX(100%);
    }
}

.algo-section {
    margin-bottom: 15px;
}

.algo-section:last-child {
    margin-bottom: 0;
}

.algo-label {
    color: var(--card-labels);
    font-weight: 600;
    margin-bottom: 5px;
    display: block;
}

.algo-line {
    margin-bottom: 5px;
    line-height: 1.5;
    font-family: Consolas, Menlo, Monaco, 'Courier New', monospace;
    font-size: 0.82rem;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: normal;
    color: var(--text-ui);
}

.topbar {
    background: var(--surface);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--card-shadow);
    color: var(--text-ui);
}

.topbar-vw-mode {
    padding: 3vw !important;
    margin-bottom: 3vw !important;
    border-radius: 1.5vw !important;
}

.topbar-vw-mode > div {
    font-size: 2.8vw !important;
    line-height: 1.3 !important;
}

.topbar-vw-mode > div > div {
    margin-bottom: 0.8vw !important;
    font-size: 2.8vw !important;
    line-height: 1.3 !important;
}

.topbar-vw-mode button {
    font-size: 2.8vw !important;
    padding: 1.5vw 2.5vw !important;
}

.topbar-vw-mode button svg,
.topbar-vw-mode button img {
    width: 3vw !important;
    height: 3vw !important;
}

.modal,
.parity-analysis-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100vh;
    background-color: var(--modal-overlay);
    padding: 0;
    overflow-y: auto;
}

.modal.active,
.parity-analysis-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.parity-analysis-modal {
    z-index: 2000;
}

body.modal-open .floating-buttons-container {
    right: 20px;
}

/* Sidebar Styles */
.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    pointer-events: none;
    transition: opacity 0.3s ease;
    opacity: 0;
}

.app-sidebar.active {
    opacity: 1;
    pointer-events: all;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 120vh;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.app-sidebar.active .sidebar-overlay {
    opacity: 1;
}

.sidebar-content {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    max-height: 100vh;
    width: 280px;
    max-width: 80vw;
    background: var(--surface);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.20);
    transform: translateX(-100%);
    transition: transform 0.3s ease, background-color 0.25s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.app-sidebar.active .sidebar-content {
    transform: translateX(0);
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.sidebar-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sidebar-close-color);
    transition: color 0.2s;
}

@media (hover: hover) {
    .sidebar-close-btn:hover {
        color: var(--text-ui);
    }
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.sidebar-item {
    width: 100%;
    padding: 14px 20px;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95rem;
    color: var(--text-ui);
    font-weight: 500;
    transition: background 0.2s;
}

@media (hover: hover) {
    .sidebar-item:hover {
        background: var(--sidebar-item-hover);
    }
}

.sidebar-item img,
.sidebar-item svg,
.sidebar-item .themed-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.themed-icon {
    display: inline-block;
    flex: 0 0 auto;
    background-color: currentColor;
    mask: var(--icon-mask) center / contain no-repeat;
    -webkit-mask: var(--icon-mask) center / contain no-repeat;
}

.themed-icon--menu { --icon-mask: url("res/menu.svg"); }
.themed-icon--search { --icon-mask: url("res/search.svg"); }
.themed-icon--info { --icon-mask: url("res/info.svg"); }
.themed-icon--variables { --icon-mask: url("res/var.svg"); }
.themed-icon--save { --icon-mask: url("res/save.svg"); }
.themed-icon--exit { --icon-mask: url("res/exit.svg"); }
.themed-icon--previous { --icon-mask: url("res/previous.svg"); }
.themed-icon--next { --icon-mask: url("res/next.svg"); }
.themed-icon--delete { --icon-mask: url("res/delete.svg"); }
.themed-icon--pen { --icon-mask: url("res/pen.svg"); }
.themed-icon--notes { --icon-mask: url("res/notes.svg"); }
.themed-icon--training { --icon-mask: url("res/training.svg"); }
.themed-icon--tracing { --icon-mask: url("res/tracing.svg"); }
.themed-icon--settings { --icon-mask: url("res/settings.svg"); }
.themed-icon--training-settings { --icon-mask: url("res/training-settings.svg"); }

.sidebar-divider {
    height: 1px;
    background: var(--surface-border);
    margin: 10px 0;
}

.sidebar-toggle-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 50%;
    background: var(--surface-raised);
    color: var(--floating-btn-color);
    border: none;
    box-shadow: 0 4px 12px var(--floating-btn-shadow);
    cursor: pointer;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    padding: 0;
}

@media (hover: hover) {
    .sidebar-toggle-btn:hover {
        transform: scale(1.05);
    }
}

.sidebar-toggle-btn .themed-icon {
    width: 24px;
    height: 24px;
}

@media (max-width: 570px) {
    .sidebar-toggle-btn {
        top: 15px;
        left: 15px;
    }
}

@media (max-width: 420px) {
    .sidebar-toggle-btn {
        width: 40px;
        height: 40px;
    }

    .sidebar-toggle-btn .themed-icon {
        width: 20px;
        height: 20px;
    }
}

@media (max-width: 360px) {
    .sidebar-toggle-btn {
        width: 36px;
        height: 36px;
    }

    .sidebar-toggle-btn .themed-icon {
        width: 18px;
        height: 18px;
    }
}

.floating-buttons-container .floating-expand-btn {
    border-radius: 0 0 24px 24px;
    clip-path: polygon(
        0% 0%,
        100% 0%,
        100% 100%,
        calc(50% + 24px) 100%,
        calc(50% + 24px) calc(100% - 24px),
        50% calc(100% - 24px),
        calc(50% - 24px) calc(100% - 24px),
        calc(50% - 24px) 100%,
        0% 100%
    );
}

.floating-buttons-container .floating-retract-btn {
    border-radius: 0 0 24px 24px;
    display: none;
}

.floating-buttons-container .menu-action-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: none;
}

.floating-buttons-container.expanded .menu-action-btn {
    display: flex;
}

.floating-buttons-container.expanded .floating-retract-btn {
    display: flex;
}

@media (min-width: 621px) {
    .sidebar-mobile-only {
        display: none !important;
    }
}

#profileModalMobile.active {
    background: var(--modal-overlay);
}

.modal-content {
    background-color: var(--surface);
    padding: 0;
    border-radius: 18px;
    width: min(800px, 100%);
    min-height: 20vh;
    max-height: 80vh;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    position: relative;
    box-sizing: border-box;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#generalNotesModal .modal-content {
    background-color: var(--background);
}

#svgEditorModal .modal-content {
    max-width: 100vw !important;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
}

.modal-header {
    padding: 20px;
    background: var(--modal-header-bg);
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-ui);
}

.close-btn {
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    width: 30px;
    height: 30px;
    line-height: 1;
}

@media (hover: hover) {
    .close-btn:hover {
        color: var(--text-ui);
    }
}

.modal-body {
    padding: 20px;
}

.modal-images {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
    justify-content: center;
}

.modal-images > div {
    width: 200px;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.modal-images img {
    width: 100%;
    height: 100%;
}

.modal-images svg {
    transition: transform 0.3s ease;
}

.modal-algo-section {
    margin-bottom: 30px;
}

.modal-algo-label {
    color: var(--bar-learned);
    font-weight: 600;
    font-size: 1.2rem;
    margin-bottom: 10px;
    display: block;
}

.modal-subsection {
    margin-bottom: 15px;
}

.modal-subsection-label {
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 5px;
    display: block;
}

.modal-algo-line {
    margin-bottom: 8px;
    line-height: 1.6;
    font-family: Consolas, Menlo, Monaco, 'Courier New', monospace;
    font-size: 1rem;
    padding: 8px;
    background: var(--surface2);
    border-radius: 4px;
    color: var(--text-ui);
}

footer {
    text-align: center;
    margin-top: 40px;
    color: var(--text-secondary);
}

footer a {
    color: var(--link-color);
    text-decoration: none;
}

@media (hover: hover) {
    footer a:hover {
        text-decoration: underline;
    }
}

/* Title visibility */
.mobile-title {
    display: none;
}

.desktop-title {
    display: block;
}

.tablet-title {
    display: none;
}

.mobile-stats {
    display: none;
}

.desktop-stats {
    display: block;
}

details[open] .arrow {
    transform: rotate(90deg);
}

details summary::-webkit-details-marker {
    display: none;
}

details summary::marker {
    display: none;
}

@media (max-width: 768px) {
    .desktop-title {
        display: none;
    }

    .tablet-title {
        display: block;
    }

    h1 {
        font-size: 2.5rem;
    }

    .subtitle {
        font-size: 1rem;
    }
}

@media (max-width: 570px) {
    .tablet-title {
        display: none;
    }

    .mobile-title {
        display: block;
    }

    .mobile-stats {
        display: block;
    }

    .desktop-stats {
        display: none;
    }
}

/* Floating Profile Button */
.floating-profile-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 50%;
    background: var(--surface-raised);
    color: var(--floating-btn-color);
    border: none;
    box-shadow: 0 4px 12px var(--floating-btn-shadow);
    cursor: pointer;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease, transform 0.3s ease;
    padding: 0;
    transform-origin: top right;
    flex-shrink: 0;
    overflow: hidden;
}

[data-theme="dark"] .floating-profile-btn, .sidebar-toggle-btn {
    border: 1px solid rgba(255, 255, 255, 0.16);
}

@media (hover: hover) {
    .floating-profile-btn:hover {
        transform: scale(1.05);
        box-shadow: 0 6px 16px var(--floating-btn-shadow);
    }
}

.homepage-info-btn {
    position: fixed;
    top: 86px;
    right: 20px;
}

body.modal-open .homepage-info-btn {
    right: 20px;
}

/* ═══════════════════════════════════════════════════════════
   THEME TOGGLE BUTTON
   Desktop: sits to the left of the profile button.
   Mobile (≤620px): profile btn is hidden; toggle moves to
   the same top-right spot the profile btn vacated.
   ═══════════════════════════════════════════════════════════ */
.theme-toggle-btn {
    position: fixed;
    top: 20px;
    right: 76px;   /* 20px edge + 48px profile btn + 8px gap */
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 50%;
    background: var(--surface-raised);
    color: var(--floating-btn-color);
    border: none;
    box-shadow: 0 4px 12px var(--floating-btn-shadow);
    cursor: pointer;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
}

@media (hover: hover) {
    .theme-toggle-btn:hover {
        transform: scale(1.05);
    }
}

.theme-toggle-btn svg {
    width: 22px;
    height: 22px;
    display: block;
    pointer-events: none;
}

/* Show moon icon on light theme, sun icon on dark theme */
.theme-toggle-btn .icon-moon { display: block; }
.theme-toggle-btn .icon-sun  { display: none;  }
[data-theme="dark"] .theme-toggle-btn .icon-moon { display: none;  }
[data-theme="dark"] .theme-toggle-btn .icon-sun  { display: block; }

/* On mobile: profile btn hides, so theme btn moves into its place */
@media (max-width: 620px) {
    .theme-toggle-btn {
        right: 20px;
        top: 15px;
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
    .theme-toggle-btn svg {
        width: 18px;
        height: 18px;
    }
}

@media (max-width: 480px) {
    .theme-toggle-btn {
        width: 10vw;
        height: 10vw;
        min-width: 36px;
        min-height: 36px;
        max-width: 44px;
        max-height: 44px;
        right: 15px;
    }
}

/* Desktop Profile Popup Styles */
.profile-popup-desktop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9998;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    display: none;
}

.profile-popup-desktop.active {
    opacity: 1;
    pointer-events: none;
    display: block;
}

.profile-popup-content {
    position: fixed;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    width: 300px;
    pointer-events: auto;
    border: 1px solid var(--surface-border);
    color: var(--text-ui);
}

@media (max-width: 620px) {
    .floating-profile-btn {
        display: none;
    }

    .profile-popup-desktop {
        display: none !important;
    }

    .sidebar-mobile-only {
        display: flex !important;
    }
}

@media (max-width: 570px) and (min-width: 621px) {
    .floating-profile-btn {
        top: 15px;
        right: 15px;
    }
}

.floating-profile-btn svg,
.floating-profile-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    flex-shrink: 0;
}

/* Mobile Responsive Styles */
@media (max-width: 570px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 2rem;
        margin-bottom: 3px;
    }

    .subtitle {
        font-size: 0.9rem;
        margin-bottom: 8px;
    }
}

@media (max-width: 420px) {
    .modal-content {
        margin: 15px;
        max-width: calc(100% - 30px);
        padding: 0;
    }

    .modal-header {
        padding: 12px 15px;
    }

    .modal-body {
        padding: 15px;
    }

    .modal-title {
        font-size: 1.05rem;
    }
}

@media (max-width: 420px) {
    .icon-btn {
        width: 22px;
        height: 22px;
        min-width: 22px;
        min-height: 22px;
    }

    .card-header-actions {
        gap: 6px;
    }
}

/* Better scaling for 320-420px range */
@media (max-width: 420px) {
    body {
        padding: 6px;
    }

    h1 {
        font-size: 1.6rem;
    }

    .subtitle {
        font-size: 0.85rem;
    }

    .card-title {
        font-size: 0.9rem;
    }

    .algo-line {
        font-size: 0.72rem;
    }

    .probability {
        font-size: 0.8rem;
    }

    .card-header {
        padding: 8px;
    }

    .card-body {
        padding: 8px;
    }

    .algo-section {
        margin-bottom: 8px;
    }

    .algo-label {
        font-size: 0.8rem;
        margin-bottom: 3px;
    }
}

@media (max-width: 420px) {
    .card-subtitle {
        font-size: 0.65rem !important;
    }
}

@media (max-width: 360px) {
    .card-subtitle {
        font-size: 0.6rem !important;
    }
}

@media (max-width: 480px) {
    .sidebar-toggle-btn {
        width: 10vw;
        height: 10vw;
        min-width: 36px;
        min-height: 36px;
        max-width: 48px;
        max-height: 48px;
    }

    .sidebar-toggle-btn .themed-icon {
        width: 5vw;
        height: 5vw;
        min-width: 18px;
        min-height: 18px;
        max-width: 24px;
        max-height: 24px;
    }

    .floating-profile-btn {
        width: 10vw;
        height: 10vw;
        min-width: 40px;
        min-height: 40px;
        max-width: 48px;
        max-height: 48px;
    }

    .floating-profile-btn img {
        width: 5vw;
        height: 5vw;
        min-width: 20px;
        min-height: 20px;
        max-width: 24px;
        max-height: 24px;
    }
}

@media (max-width: 360px) {
    body {
        padding: 3px;
    }

    h1 {
        font-size: 1.4rem;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    .card-title {
        font-size: 0.9rem;
    }
}

@media (max-width: 620px) {

    /* Compact header for mobile */
    header {
        margin-bottom: 15px;
    }

    /* Compact topbar for mobile */
    .topbar {
        padding: 12px;
        margin-bottom: 15px;
    }

    .topbar > div {
        font-size: 0.85rem !important;
    }

    .topbar > div > div {
        margin-bottom: 4px !important;
        font-size: 0.85rem !important;
    }

    #progress-text,
    #known-parity-text,
    #safety-text {
        font-weight: 700;
    }

    /* Compact controls for mobile */
    .controls {
        gap: 8px;
        margin-bottom: 15px;
        flex-wrap: nowrap;
        position: relative;
    }

    .search-toggle-btn {
        display: flex;
        flex-shrink: 0;
        order: -1;
    }

    .controls input[type="text"]#search {
        padding: 8px 10px;
        font-size: 0.9rem;
        position: absolute;
        left: 0;
        top: 0;
        width: 0;
        opacity: 0;
        pointer-events: none;
        transition: all 0.3s ease;
        z-index: 10;
        min-width: 0;
    }

    .controls.search-expanded input[type="text"]#search {
        width: 100%;
        opacity: 1;
        pointer-events: all;
    }

    .controls.search-expanded .custom-dropdown {
        opacity: 0;
        pointer-events: none;
        width: 0;
        min-width: 0;
        flex: 0 0 0;
    }

    .controls .custom-dropdown {
        flex: 1;
        min-width: 0;
        transition: all 0.3s ease;
    }

    .controls .custom-dropdown-trigger {
        padding: 8px 10px;
        font-size: 0.9rem;
    }
}

/* Fix overlap at 578-600px range */
@media (min-width: 571px) and (max-width: 620px) {
    .controls {
        gap: 6px;
    }

    .controls .custom-dropdown {
        min-width: 100px;
    }

    .controls .custom-dropdown-trigger {
        padding: 8px;
        font-size: 0.85rem;
    }

    .search-toggle-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        flex-shrink: 0;
    }

    .search-toggle-btn .themed-icon {
        width: 20px;
        height: 20px;
    }
}

@media (max-width: 620px) {
    /* Smaller grid gap */
    .grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* Compact cards */
    .card {
        border-radius: 6px;
    }

    .card-header {
        padding: 10px;
        flex-direction: row;
        align-items: center;
        gap: 0;
        flex-wrap: nowrap;
    }

    .card-title {
        font-size: 1rem;
        flex: 1;
        min-width: 0;
    }

    .card-body {
        padding: 10px;
    }

    .algo-section {
        margin-bottom: 10px;
    }

    .algo-label {
        font-size: 0.85rem;
    }

    .algo-line {
        font-size: 0.75rem;
        word-break: break-all;
    }

    /* Compact modal for mobile (non-training) */
    .modal-content {
        margin: 10px;
        max-width: calc(100% - 20px);
    }

    .modal-header {
        padding: 12px;
    }

    .modal-title {
        font-size: 1.1rem;
    }

    .modal-body {
        padding: 12px;
    }

    .modal-images {
        gap: 2vw;
        flex-direction: row;
        align-items: center;
    }

    .modal-images > div {
        width: 40vw !important;
        height: 40vw !important;
        max-width: 180px !important;
        max-height: 180px !important;
    }

    .modal-algo-label {
        font-size: 1rem;
    }

    .modal-algo-line {
        font-size: 0.85rem;
        padding: 6px;
        word-break: break-all;
    }

    /* Compact icon buttons */
    .icon-btn {
        width: 24px;
        height: 24px;
    }

    /* Priority controls on mobile */
    .card-header-actions {
        gap: 6px;
    }

    /* Smaller probability text */
    .probability {
        font-size: 0.85rem;
    }
}

/* Extra small devices */
@media (max-width: 400px) {
    input[type="text"] {
        font-size: 0.85rem;
        padding: 6px 8px;
    }

    .custom-dropdown-trigger {
        font-size: 0.85rem;
        padding: 6px 8px;
    }

    .controls-row {
        gap: 6px;
    }
}

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

    .topbar > div > div {
        font-size: 0.75rem !important;
    }

    .card-title {
        font-size: 0.9rem;
    }

    .algo-line {
        font-size: 0.7rem;
    }

    .modal-title {
        font-size: 1rem;
    }

    .floating-profile-btn {
        width: 44px;
        height: 44px;
    }

    .floating-profile-btn svg {
        width: 22px;
        height: 22px;
    }

    .custom-dropdown-trigger {
        font-size: 0.8rem;
        padding: 5px 6px;
    }
}

.card.priority-1 {
    background: var(--p1-bg);
    border: 2px solid var(--p1-border);
}

.card.priority-1 .card-header {
    background: var(--p1-header);
}

.card.priority-2 {
    background: var(--p2-bg);
    border: 2px solid var(--p2-border);
}

.card.priority-2 .card-header {
    background: var(--p2-header);
}

.card.priority-3 {
    background: var(--p3-bg);
    border: 2px solid var(--p3-border);
}

.card.priority-3 .card-header {
    background: var(--p3-header);
}

.card.priority-4 {
    background: var(--p4-bg);
    border: 1px solid var(--p4-border);
}

.card.priority-4 .card-header {
    background: var(--p4-header);
}

.card.priority-5 {
    background: var(--p5-bg);
    border: 2px solid var(--p5-border);
}

.card.priority-5 .card-header {
    background: var(--p5-header);
}

.card.priority-6 {
    background: var(--p6-bg);
    border: 2px solid var(--p6-border);
}

.card.priority-6 .card-header {
    background: var(--p6-header);
}

.card.priority-7 {
    background: var(--p7-bg);
    border: 2px solid var(--p7-border);
}

.card.priority-7 .card-header {
    background: var(--p7-header);
}

/* Settings Modal Styles (Additions) */
.modal-content label {
    color: var(--text-ui);
}

.modal-content input[type="checkbox"] {
    transform: scale(1.3);
    margin-left: 10px;
    cursor: pointer;
}

/* SVG Styling */
.card .card-svg-container svg path {
    transition: fill 0.3s ease, stroke 0.3s ease;
}

.card .card-svg-container svg .label-toggle {
    stroke: none;
}

/* Cubeshape SVG base styles */
.cubeshape-svg {
    width: 200px !important;
    height: 200px !important;
    display: block;
    transition: transform 0.3s ease;
}

.card-svg-container .cubeshape-svg,
.card-svg-container .squan {
    width: 100% !important;
    height: 100% !important;
}

/* SVG Container Backgrounds (whitespace around the scramble shapes) */
.card.learned .card-svg-container {
    background: var(--card-learned-svg);
}

.card.planned.priority-1 .card-svg-container {
    background: var(--p1-svg);
}

.card.planned.priority-2 .card-svg-container {
    background: var(--p2-svg);
}

.card.planned.priority-3 .card-svg-container {
    background: var(--p3-svg);
}

.card.planned.priority-4 .card-svg-container {
    background: var(--p4-svg);
}

.card.planned.priority-5 .card-svg-container {
    background: var(--p5-svg);
}

.card.planned.priority-6 .card-svg-container {
    background: var(--p6-svg);
}

.card.planned.priority-7 .card-svg-container {
    background: var(--p7-svg);
}

.card.learning .card-svg-container {
    background: var(--card-learning-svg);
}

.algo-interactive {
    cursor: pointer;
    transition: background 0.15s ease;
    padding: 2px 4px;
    border-radius: 3px;
    display: inline-block;
    margin: 2px 0;
}

@media (hover: hover) {
    .algo-interactive:hover {
        background: var(--hover-bg);
    }
}

.algo-popup {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 9999;
    max-width: 400px;
    pointer-events: auto;
    color: var(--text-ui);
}

.algo-popup.permanent {
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

@media (max-width: 570px) {
    .algo-popup {
        max-width: calc(100vw - 40px);
        font-size: 0.85rem;
    }
}

/* Info button styles */
.info-wrapper {
    position: relative;
    display: inline-block;
    z-index: 10;
}

.settings-info-btn {
    background: var(--surface2);
    border: 1px solid var(--border-color);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    color: var(--text-secondary);
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 10;
    transition: all 0.2s;
    pointer-events: auto;
}

@media (hover: hover) {
    .settings-info-btn:hover {
        background: var(--surface-border);
    }
}

.settings-info-btn .themed-icon {
    width: 12px;
    height: 12px;
}

.info-box {
    position: fixed;
    min-width: 250px;
    max-width: 300px;
    background: var(--info-box-bg);
    color: var(--info-box-color);
    padding: 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    display: none;
    z-index: 100000;
    line-height: 1.4;
    pointer-events: none;
}

.info-box.show {
    display: block;
}

.hide-instructions .info-wrapper {
    display: none !important;
}

/* Force show hints in SVG editor */
.svg-editor-force-show-hints .label-toggle {
    display: block !important;
}

/* color theme stuff */
/* ── Algo popup elements ── */
.popup-label    { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 4px; font-weight: 600; }
.popup-setup    { font-size: 0.8rem; margin-bottom: 8px; padding: 4px; background: var(--surface2); color: var(--text-ui); border-radius: 3px; cursor: pointer; transition: background 0.15s; }
@media (hover: hover) {
    .popup-setup:hover {
        background: var(--hover-bg);
    }
}
.popup-step-span { background: var(--step-highlight-bg); padding: 1px 4px; border-radius: 2px; white-space: nowrap; }

/* ── Shape path block ── */
.shape-path-block { margin-top: 10px; padding: 10px; background: var(--surface2); border-radius: 4px; border-left: 3px solid var(--accent); }
.shape-path-label { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 5px; font-weight: 600; }
.shape-path-content { font-size: 0.9rem; line-height: 1.8; overflow-x: auto; white-space: nowrap; }
.shape-path-step { background: var(--step-highlight-bg); padding: 2px 6px; border-radius: 3px; white-space: nowrap; }
.shape-path-arrow { color: var(--accent); font-weight: bold; }

/* ── Search highlight ── */
mark.search-hl { background-color: var(--search-highlight-bg); color: var(--search-highlight-color); padding: 0 2px; border-radius: 2px; }

/* ── Context / priority menus ── */
.ctx-menu { background: var(--surface); border: 1px solid var(--border-color); color: var(--text-ui); }
.ctx-menu-divider { height: 1px; background: var(--surface-border); margin: 4px 0; }
.ctx-menu-status { color: var(--text-secondary); border-bottom: 1px solid var(--surface-border); }
.ctx-menu-item { color: var(--text-ui); }
@media (hover: hover) {
    .ctx-menu-item:hover {
        background: var(--sidebar-item-hover);
    }
}
.ctx-menu-item.disabled { color: var(--text-muted); }
.priority-menu { background: var(--surface); border: 2px solid var(--link-color); }
.priority-opt { color: var(--text-ui); }
@media (hover: hover) {
    .priority-opt:hover {
        background: var(--sidebar-item-hover);
    }
}
.priority-opt.selected { background: var(--hover-bg); color: var(--link-color); }

/* ── Render loading indicator ── */
#renderLoadingIndicator { background: var(--loading-overlay-bg) !important; color: var(--text-ui) !important; }

/* ── Training previous-scramble bar ── */
#prevScrambleBar { background: var(--prevscramble-bar-bg) !important; border-top-color: var(--prevscramble-bar-border) !important; color: var(--text-secondary) !important; }

/* ── Settings action buttons ── */
.settings-action-btn {
    background: var(--surface-raised) !important;
    color: var(--text-ui) !important;
    border-color: var(--settings-action-btn-border) !important;
}

/* ── Progress bar tracks ── */
.progress-track { background: var(--progress-track); }
.profile-label  { color: var(--text-ui); }

/* ================================================================
   ADDITIONS TO styles.css
   Paste this entire block at the END of css/styles.css.
   It covers:
     1.  Loading screen  (was all inline in index.html)
     2.  Dynamically created UI elements (context menus, toasts,
         priority menus, reorder button, render loader, etc.)
         that previously lived as style.cssText strings in JS.
   ================================================================ */


/* ── 1. LOADING SCREEN ─────────────────────────────────────── */

.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #f5f7fa 0%, #e8ebf0 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    font-family: 'Segoe UI', sans-serif;
    padding: 0 20px;
    box-sizing: border-box;
    transition: opacity 0.3s ease;
}

.loading-screen--fade-out {
    opacity: 0;
}

/* Dark-mode loading screen (replaces the old <style> block in <head>) */
[data-theme="dark"] .loading-screen {
    background: linear-gradient(135deg, #12141a 0%, #1c1f28 100%);
}

.loading-title {
    font-size: 3.5rem;
    font-weight: 800;
    color: #2d3748;
    margin-bottom: 8px;
    letter-spacing: -1px;
}

[data-theme="dark"] .loading-title { color: #e2e4ed; }

.loading-title--sm { font-size: 2.5rem; }
.loading-title--xs { font-size: 2rem; }

.loading-author {
    font-size: 1.1rem;
    color: #4a5568;
    margin-bottom: 3px;
    font-weight: 500;
}

[data-theme="dark"] .loading-author { color: #9299b0; }

.loading-author--sm { font-size: 0.95rem; }
.loading-author--xs { font-size: 0.85rem; }

.loading-tip {
    font-size: 0.95rem;
    color: #4a5568;
    max-width: 90vw;
    text-align: center;
    line-height: 1.5;
    font-weight: 400;
    padding: 0 15px;
    box-sizing: border-box;
    white-space: normal;
    overflow-wrap: break-word;
    margin-bottom: 25px;
}

[data-theme="dark"] .loading-tip { color: #9299b0; }

.loading-tip--sm { font-size: 0.8rem;  max-width: 90vw; }
.loading-tip--xs { font-size: 0.75rem; max-width: 95vw; }

.loading-bar-container {
    width: 320px;
    max-width: 90vw;
    height: 6px;
    background: #cbd5e0;
    border-radius: 3px;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .loading-bar-container {
    background: #242730;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.loading-bar-progress {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #4a5568, #2d3748);
    transition: width 0.3s ease;
}

[data-theme="dark"] .loading-bar-progress {
    background: linear-gradient(90deg, #3a7bd5, #6a9ef8);
}

.loading-credit {
    font-size: 0.85rem;
    color: #a0aec0;
    margin-top: 35px;
    text-align: center;
    font-weight: 400;
    padding: 0 15px;
    box-sizing: border-box;
    line-height: 1.4;
}

[data-theme="dark"] .loading-credit { color: #6b7080; }

.loading-credit--matt  { margin-top: 5px; }
.loading-credit--sm    { font-size: 0.7rem;  margin-top: 25px; }
.loading-credit--xs    { font-size: 0.65rem; margin-top: 20px; }

/* ── Main container: hidden during load ─────────────────────── */
.hidden-until-loaded {
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* ── Search toggle override (was inline in html) ─────────────── */
.search-toggle-icon-btn {
    background-color: var(--surface-raised);
    color: var(--text-ui);
    height: 35px;
    width: 35px;
}


/* ── 2. CONTEXT MENU ────────────────────────────────────────── */

.ctx-menu {
    position: fixed;
    border-radius: 6px;
    box-shadow: 0 4px 12px var(--card-shadow);
    z-index: 10000;
    padding: 4px 0;
    min-width: 180px;
    max-width: 200px;
}

.ctx-menu-status {
    padding: 6px 16px;
    font-size: 0.75rem;
    margin-bottom: 4px;
    text-align: center;
    font-weight: 600;
}

.ctx-menu-item {
    padding: 8px 16px;
    font-size: 0.9rem;
    cursor: pointer;
}

.ctx-menu-item.disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.ctx-menu-divider {
    height: 1px;
    margin: 4px 0;
}


/* ── 3. PRIORITY MENU ───────────────────────────────────────── */

.priority-menu {
    position: fixed;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    padding: 8px;
    min-width: 120px;
}

.priority-opt {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    font-weight: 500;
    transition: background 0.15s;
}

.priority-opt.selected {
    font-weight: 700;
}


/* ── 4. TOAST NOTIFICATION ──────────────────────────────────── */

.toast-notification {
    position: fixed;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 100000;
    font-size: 0.95rem;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s ease;
    color: var(--toast-color);
}

.toast-notification--success { background: var(--toast-success-bg); }
.toast-notification--error   { background: var(--toast-error-bg);   }
.toast-notification--info    { background: var(--toast-info-bg);    }
.toast-notification--visible { opacity: 1; }


/* ── 5. REORDER BUTTON ──────────────────────────────────────── */

.reorder-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 24px;
    background: var(--accent);
    color: var(--text-on-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
    z-index: 1000;
    transition: all 0.2s;
}

@media (hover: hover) {
    .reorder-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4);
        background: var(--accent-hover);
    }
}


/* ── 6. RENDER LOADING INDICATOR ────────────────────────────── */

.render-loading-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--loading-overlay-bg);
    padding: 20px 30px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 99999;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95rem;
    color: var(--text-ui);
    font-weight: 500;
}

.render-loading-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--spinner-track);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


/* ── 7. RENDER LOADER (full-screen, different from indicator) ── */

.render-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #f5f7fa 0%, #e8ebf0 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99998;
    font-family: 'Segoe UI', sans-serif;
    padding: 0 20px;
    box-sizing: border-box;
    transition: opacity 0.25s ease;
}

[data-theme="dark"] .render-loader {
    background: linear-gradient(135deg, #12141a 0%, #1c1f28 100%);
}

.render-loader__title {
    font-size: 2.5rem;
    font-weight: 800;
    color: #2d3748;
    margin-bottom: 6px;
    letter-spacing: -1px;
}

[data-theme="dark"] .render-loader__title { color: #e2e4ed; }

.render-loader__subtitle {
    font-size: 1rem;
    color: #4a5568;
    margin-bottom: 25px;
    font-weight: 500;
}

[data-theme="dark"] .render-loader__subtitle { color: #9299b0; }

.render-loader__bar-wrap {
    width: 280px;
    max-width: 85vw;
    height: 6px;
    background: #cbd5e0;
    border-radius: 3px;
    overflow: hidden;
}

[data-theme="dark"] .render-loader__bar-wrap { background: #242730; }

.render-loader__bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #4a5568, #2d3748);
    transition: width 0.2s ease;
}

[data-theme="dark"] .render-loader__bar {
    background: linear-gradient(90deg, #3a7bd5, #6a9ef8);
}


/* ── 8. CONFIRMATION MODALS (showConfirmation / showSaveDiscard) */

.confirm-modal-header {
    background: var(--modal-header-bg);
}

.confirm-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}

.confirm-btn--primary  { background: var(--accent);        color: var(--text-on-color); }
.confirm-btn--neutral  { background: var(--delete-btn-bg); color: var(--text-ui); }
.confirm-btn--secondary { background: var(--delete-btn-bg); color: var(--text-ui); }
.confirm-btn--danger   { background: #c0392b;              color: var(--text-on-color); }
@media (hover: hover) {
    .confirm-btn--danger:hover {
        background: #a93226;
    }
}


/* ── 9. QUICK INFO POPUP ────────────────────────────────────── */

.quick-info-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.quick-info-box {
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    color: var(--text-ui);
    line-height: 1.6;
}

.quick-info-btn {
    display: block;
    margin: 20px auto 0;
    padding: 10px 24px;
    background: var(--accent);
    color: var(--text-on-color);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
}


/* ── 10. PARITY LABEL COLOURS (used in modals.js updateParityLabel) */

.parity-odd     { color: var(--parity-odd);          font-weight: 600; }
.parity-even    { color: var(--parity-even);         font-weight: 600; }
.parity-mirror  { color: var(--parity-odd-mirror);   font-weight: 600; }
.parity-invalid { color: var(--parity-invalid);      font-weight: 600; }

/* z2 prefix shown before algs that solve the mirrored case */
.z2-prefix {
    color: var(--z2-prefix-color);
    font-weight: 600;
    margin-right: 4px;
    white-space: nowrap;
    user-select: none;
}


/* ── 11. PRESET OPTIONS in sidebar ──────────────────────────── */

.preset-option {
    padding: 12px 20px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s;
    color: var(--text-ui);
}

@media (hover: hover) {
    .preset-option:hover {
        background: var(--sidebar-item-hover);
    }
}
.preset-option.active   {
    background: var(--hover-bg);
    color: var(--link-color);
    font-weight: 600;
}


/* ── 12. COLOR SCHEME BUTTONS ───────────────────────────────── */

.color-btn {
    width: 60px;
    height: 40px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: border-color 0.15s, font-weight 0.15s;
}

.color-btn.selected {
    border: 3px solid var(--accent);
    font-weight: bold;
}


/* ── 13. AVATAR GRID ITEMS ──────────────────────────────────── */

.avatar-option {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid var(--avatar-border-idle);
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.avatar-option.selected {
    border-color: var(--accent);
}


/* ── 14. PROFILE POPUP PROGRESS BARS ────────────────────────── */

.profile-bar-learned   { background: #28a745; }
.profile-bar-learning  { background: #ffc107; }
.profile-bar-coverage  { background: linear-gradient(90deg, #007bff, #0056b3); }
.profile-bar-safety    { background: linear-gradient(90deg, #ffc107, #ff8c00); }

/* Note: the above 4 use hardcoded colours intentionally — they are
   semantic status indicators, not theme colours. Add vars for them
   if you need dark-mode variants:
     --bar-learned, --bar-learning, --bar-coverage, --bar-safety */


/* ── 15. ALGO INPUT ROWS (edit-case modal) ───────────────────── */

.alg-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.alg-input {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
    background: var(--surface-raised);
    color: var(--text-ui);
}

.alg-delete-btn {
    padding: 6px;
    background: var(--delete-btn-bg);
    color: var(--text-ui);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.parity-label {
    min-width: 40px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
}




/* ================================================================
   CUBESHAPE SVG THEMING
   The .cubeshape-svg elements are injected inline,
   so CSS properties DO cross into the SVG — unlike <img>-loaded SVGs.

   Structure of each cubeshape SVG:
   - path:first-child → the single diagonal divider line
     (stroke="#848484", no fill). This is the ONLY path without
     fill="white", and it always appears first.
   - All other path:not(.label-toggle) → the actual shape piece faces.
   - .label-toggle paths → colored position numbers (red/blue).
     NOT overridden — user-meaningful colors.

   The previous path[class=""] rule was WRONG because ALL paths in
   these SVGs have class="" (except .label-toggle), so it was
   overriding the piece stroke to --border-color (gray), causing
   the washed-out look.
   ================================================================ */

/* Shape piece fills and strokes — pieces only (not divider line) */
.cubeshape-svg path:not(:first-child):not(.label-toggle) {
    fill: var(--svg-fill);
    stroke: var(--svg-stroke);
}

/* Divider line — always the first path, needs a subtle stroke distinct
   from piece borders but still visible on both light and dark surfaces */
.cubeshape-svg path:first-child {
    fill: none;
    stroke: var(--border-color);
}

/* Blue tracing numbers — softer in dark mode */
[data-theme="dark"] .cubeshape-svg .label-toggle[fill="#5177FF"] {
    fill: var(--card-labels); /* already #7fa8ff in dark */
}

/* Red tracing numbers — soften the pure red */
[data-theme="dark"] .cubeshape-svg .label-toggle[fill="#FF0303"] {
    fill: #ff7070;
}

/* ── Settings action buttons ── */
.settings-action-btn {
    background: var(--surface2) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-ui) !important;
}

@media (hover: hover) {
    .settings-action-btn:hover {
        background: var(--hover-bg) !important;
        border-color: var(--accent-hover) !important;
        color: var(--accent-hover) !important;
    }
}

.settings-action-btn:active {
    transform: scale(0.98) !important;
    background: var(--step-highlight-bg) !important;
}

/* Settings share one continuous scroll; the sidebar is a section index. */
.modal-content.unified-settings-content,
.modal-content.homepage-images-content {
    width: 96vw;
    max-width: 820px;
    height: min(88vh, 820px);
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 18px;
    background: var(--surface);
}
.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 16px;
    padding: 18px 24px;
    border-bottom: 2px solid var(--surface-border);
}
.settings-header h2 {
    margin: 0;
    font-size: 1.3rem;
    color: var(--text-ui);
}
.settings-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
#settingsSidebar {
    flex-shrink: 0;
    width: 58px;
    padding: 10px 6px;
    background: var(--surface2);
    border-right: 1px solid var(--surface-border);
    overflow-y: auto;
}
#settingsSidebar button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 8px;
    justify-content: center;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    text-align: left;
    cursor: pointer;
}
#settingsSidebar button .themed-icon { flex-shrink: 0; opacity: .55; }
#settingsSidebar button[aria-current] { background: var(--surface-border); color: var(--text-ui); }
@media (hover: hover) {
    #settingsSidebar button:hover {
        background: var(--surface-border);
        color: var(--text-ui);
    }
}
#settingsSidebar button[aria-current] .themed-icon { opacity: 1; }
#settingsPanel {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 0 24px 22px;
    overscroll-behavior: contain;
}
#settingsPanel section { padding-top: 18px; }
#settingsPanel section + section { margin-top: 30px; border-top: 2px solid var(--surface-border); }
.settings-section-heading { margin: 0 0 16px; font-size: 1.1rem; color: var(--text-ui); }
.modal-content.homepage-images-content { max-width: 560px; height: auto; max-height: 88vh; }
.homepage-images-body { padding: 20px 24px 24px; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
@media (max-width: 540px) {
    #settingsSidebar { width: 54px; }
    #settingsSidebar button { justify-content: center; padding: 12px 4px; }
    #settingsSidebar button span { display: none; }
    #settingsPanel { padding: 0 14px 18px; }
    .settings-header { padding: 16px; }
    .settings-header h2 { font-size: 1.1rem; }
    .homepage-images-body { padding: 16px; }
}

.homepage-image-preview {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 12px;
    margin-bottom: 18px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--surface2);
}
.homepage-image-preview > div { width: 42%; max-width: 170px; text-align: center; }
.homepage-image-preview span { display: block; font-size: .78rem; color: var(--text-secondary); margin-bottom: 8px; }
.homepage-image-preview svg { width: 100%; height: auto; display: block; }
.homepage-image-draft { border: 0; margin: 0; padding: 0; min-width: 0; }
.stroke-width-label { display: flex; align-items: center; gap: 7px; font-size: .92rem; font-weight: 500; color: var(--text-secondary); }
.homepage-stroke-control { margin: 8px 12px 20px; }
.linked-width-slider { position: relative; width: 100%; height: 38px; user-select: none; touch-action: none; }
.linked-width-track { position: absolute; left: 0; top: 17px; width: 100%; height: 5px; border: 1px solid var(--border-color); border-radius: 999px; background: var(--surface2); }
.linked-width-handle { position: absolute; width: 14px; height: 16px; transform: translateX(-50%); cursor: grab; z-index: 3; padding: 0; border: 0; background: transparent; touch-action: none; }
.linked-width-handle:active { cursor: grabbing; }
.linked-width-handle:focus-visible { outline: 2px solid var(--text-ui); outline-offset: 3px; }
.linked-width-handle-top { top: 3px; }
.linked-width-handle-bottom { top: 22px; }
.linked-width-shape { display: block; width: 100%; height: 100%; background: linear-gradient(180deg, #657087, #323846); }
.linked-width-handle-top .linked-width-shape { clip-path: polygon(0 0, 100% 0, 100% 62%, 50% 100%, 0 62%); }
.linked-width-handle-bottom .linked-width-shape { clip-path: polygon(50% 0, 100% 38%, 100% 100%, 0 100%, 0 38%); }
.linked-width-handle.linked .linked-width-shape { background: linear-gradient(180deg, #31b38b, #21a978); }
.linked-width-handle.selected .linked-width-shape { background: linear-gradient(180deg, #ffd166, #d99423); }
.linked-width-handle-middle { top: 13px; width: 7px; height: 14px; z-index: 4; }
.linked-width-middle-shape { display: block; width: 100%; height: 100%; border: 1px solid #8a93a6; border-radius: 3px; background: linear-gradient(180deg, #eef2f7, #8f98a9); }
.stroke-width-values { display: flex; justify-content: space-between; gap: 8px; font-size: .72rem; color: var(--text-secondary); margin-top: 5px; }
.homepage-images-save { display: block; width: 100%; margin-top: 14px; padding: 12px; border: 0; border-radius: 10px; background: var(--text-ui); color: var(--surface); font-size: .95rem; font-weight: 600; cursor: pointer; }
.homepage-images-save:disabled { opacity: .6; cursor: wait; }
/* Learning-order group decoration and editor */
.learning-group-layer, .learning-order-list {
    --lg-0: var(--accent);
    --lg-1: #7c4dff;
    --lg-2: #00897b;
    --lg-3: #64748b;
}
[data-theme="dark"] .learning-group-layer, [data-theme="dark"] .learning-order-list {
    --lg-1: #9d82f0;
    --lg-2: #3fb8aa;
    --lg-3: #8a96ab;
}
.learning-group-layer { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.learning-group-box { --lg: var(--lg-0); position: absolute; box-sizing: border-box; border: 2px solid color-mix(in srgb, var(--lg) 50%, transparent); border-radius: var(--lg-radius, 12px); }
.learning-group-box[data-tone="1"] { --lg: var(--lg-1); }
.learning-group-box[data-tone="2"] { --lg: var(--lg-2); }
.learning-group-box[data-tone="3"] { --lg: var(--lg-3); }
/* Group continues on the previous/next row: leave that edge open. */
.learning-group-box.cont-start { border-left-color: transparent; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.learning-group-box.cont-end { border-right-color: transparent; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.learning-order-content { max-width: 920px; width: min(94vw, 920px); max-height: 88vh; display: flex; flex-direction: column; }
.learning-order-body { padding: 18px 22px 10px; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 14px; }
.learning-order-help { margin: 0; color: var(--text-secondary); font-size: .88rem; line-height: 1.8; }
.learning-order-help kbd {
    font: inherit; font-size: .78rem; font-weight: 600; white-space: nowrap;
    padding: 1px 6px; border: 1px solid var(--border-color); border-bottom-width: 2px;
    border-radius: 5px; background: var(--surface2); color: var(--text-ui);
}
.learning-order-toolbar { display: flex; align-items: center; gap: 8px; }
.learning-order-toolbar button { padding: 6px 14px; font-size: .85rem; }
.learning-order-toolbar button:disabled { opacity: .4; cursor: not-allowed; }
.learning-order-count { margin-left: auto; color: var(--text-muted); font-size: .82rem; }

.learning-order-list {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px 0;
    min-height: 96px; max-width: 100%; box-sizing: border-box; overflow-x: hidden;
    padding: 14px; background: var(--surface2);
    border: 1px solid var(--border-color); border-radius: 12px;
}
.learning-order-unit { display: flex; flex: 0 0 auto; align-items: center; }

.learning-order-insertion { position: relative; flex: 0 0 14px; align-self: stretch; min-height: 40px; }
.learning-order-insertion::after {
    content: ""; position: absolute; left: 50%; top: 2px; bottom: 2px;
    width: 3px; margin-left: -1.5px; border-radius: 2px; background: transparent;
}
.learning-order-insertion.learning-order-drop-target::after { background: var(--accent); }
.learning-order-group-items .learning-order-insertion { flex-basis: 12px; min-height: 36px; }

.learning-order-entry,
.learning-order-group-case {
    display: flex; align-items: center; padding: 8px 12px;
    border: 1px solid var(--border-color); border-radius: 8px;
    background: var(--surface); color: var(--text-ui);
    font-size: .9rem; font-weight: 500; cursor: grab; user-select: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
    transition: border-color .12s, transform .12s, box-shadow .12s;
}
.learning-order-entry:hover,
.learning-order-group-case:hover {
    border-color: var(--text-muted); transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, .18);
}

.learning-order-group {
    --lg: var(--lg-0);
    display: flex; flex-direction: row; align-items: center; min-width: max-content;
    padding: 6px 8px 6px 4px; cursor: grab; user-select: none;
    border: 1.5px solid color-mix(in srgb, var(--lg) 50%, transparent);
    border-radius: 12px;
    background: color-mix(in srgb, var(--lg) 10%, transparent);
}
.learning-order-group[data-tone="1"] { --lg: var(--lg-1); }
.learning-order-group[data-tone="2"] { --lg: var(--lg-2); }
.learning-order-group[data-tone="3"] { --lg: var(--lg-3); }
.learning-order-group-header {
    display: inline-flex; align-items: center; align-self: stretch; flex: 0 0 auto;
    padding: 0 8px 0 6px; margin-right: 4px;
    border-right: 1px solid color-mix(in srgb, var(--lg) 35%, transparent);
}
.learning-order-group-items { display: flex; flex-direction: row; flex-wrap: nowrap; align-items: stretch; overflow: visible; }
.learning-order-drag-handle { display: inline-flex; flex: 0 0 auto; align-items: center; color: var(--lg, var(--text-muted)); cursor: grab; }
.learning-order-drag-icon { width: 16px; height: 16px; fill: currentColor; }

.learning-order-selectable { cursor: grab; }
.learning-order-selectable:focus { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent); }
.learning-order-group-header:focus { outline: none; }
.learning-order-group:has(> .learning-order-group-header:focus) { outline: 2px solid var(--accent); outline-offset: 2px; }
.learning-order-dragging { opacity: .45; }
.learning-order-entry.learning-order-drop-target,
.learning-order-group.learning-order-drop-target,
.learning-order-group-case.learning-order-drop-target { outline: 2px solid var(--accent); outline-offset: 2px; }

.learning-order-footer {
    flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 10px;
    padding: 14px 22px 18px; border-top: 1px solid var(--border-color);
}
@media (max-width: 560px) {
    .learning-order-content { width: 100%; max-height: 92vh; }
    .learning-order-body { padding: 14px 14px 8px; }
    .learning-order-list { padding: 10px; }
    .learning-order-entry, .learning-order-group { max-width: 100%; box-sizing: border-box; }
}
