﻿* {
    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;     /* body text, titles, input text, modal titles */
    --text-ui:        #2d3748;     /* sidebar, profile header, settings chrome labels */
    --text-secondary: #666666;     /* muted labels, icons, descriptions, subtitles */
    --text-muted:     #999999;     /* disabled, empty states, finish moves, close btn */

    /* ── Accent / interactive ── */
    --bar-learned:       #28a745;
    --bar-learning:      #ffa000;
    --accent:            #007bff;
    --accent-hover:      #0056b3;
    --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 */

    /* ── 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;

    /* ── 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);
    --good-case:   #007900;
    --bad-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;

    /* ── 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: #ffffff;

    /* ── 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). SVG piece fills stay white — they are legible
   on every dark card background chosen below.
   ═══════════════════════════════════════════════════════════ */
[data-theme="dark"] {
    color-scheme: dark;

    --background:      #12141a;
    --surface:         #1c1f28;
    --surface-raised:  #242730;
    --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;

    --accent:            #3a7bd5;
    --accent-hover:      #5596f0;
    --link-color:        #6a9ef8;
    --hover-bg:          #1e2535;
    --step-highlight-bg: #1a1e2a;

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

    --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:         #3fff86;
    --parity-even:        #42c9ff;
    --parity-odd-mirror:  #02c23c;
    --parity-even-mirror: #0088ff;
    --parity-invalid:     #ff0000;

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

    --card-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    --good-case:   #00b100;
    --bad-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: #221900;  --card-learning-border: #9c7010;
    --card-learning-header: #2c2108; --card-learning-svg: #241b00;

    --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: #e2e4ed;

    --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 — same in both themes ── */
    --header-dark-bg:   #2d3748;

    --toast-success-bg: #0f2d18;
    --toast-error-bg:   #2d0f14;
    --toast-info-bg:    #252830;
    --toast-color:      #e2e4ed;

    --search-highlight-bg:    #6b5a00;
    --search-highlight-color: #ffe680;

    --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;
}

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;
}

::-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-primary);
    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-primary);
}

.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: white;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
    align-items: center;
    justify-content: center;
}

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

.search-toggle-btn svg {
    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-primary);
}

select {
    flex: 1;
    min-width: 150px;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 1rem;
    background: var(--surface-raised);
    color: var(--text-primary);
    cursor: pointer;
}

.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-primary);
    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;
    cursor: pointer;
    transition: transform 0.2s;
}

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

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

.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;
}

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

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

.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-primary);
}

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

.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;
}

.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;
}

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

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

.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;
}

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

.sidebar-toggle-btn img {
    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 img {
        width: 20px;
        height: 20px;
    }
}

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

    .sidebar-toggle-btn img {
        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;
}

#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-primary);
}

.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;
}

.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-primary);
}

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

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

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;
}

.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;
}

.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-primary);
}

@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 img {
        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 select {
        opacity: 0;
        pointer-events: none;
        width: 0;
        min-width: 0;
        padding: 0;
        border: none;
    }

    .controls select {
        padding: 8px 10px;
        font-size: 0.9rem;
        flex: 1;
        min-width: 0;
        transition: all 0.3s ease;
    }
}

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

    select {
        padding: 8px 8px;
        font-size: 0.85rem;
        min-width: 100px;
    }

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

    .search-toggle-btn img {
        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;
    }

    select {
        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;
    }

    select {
        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;
}

/* Hint Toggle Styles */
.hide-hints .label-toggle {
    display: none;
}

/* 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;
}

/* 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;
}

.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-primary);
}

.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;
}

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

.settings-info-btn img {
    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-primary); border-radius: 3px; cursor: pointer; transition: background 0.15s; }
.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); }
.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); }
.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-primary) !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-primary);
    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: white;
    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;
}

.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-primary);
    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: white; }
.confirm-btn--neutral  { background: var(--delete-btn-bg); color: var(--text-primary); }
.confirm-btn--secondary { background: var(--delete-btn-bg); color: var(--text-primary); }
.confirm-btn--danger   { background: #c0392b;              color: white; }
.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-primary);
    line-height: 1.6;
}

.quick-info-btn {
    display: block;
    margin: 20px auto 0;
    padding: 10px 24px;
    background: var(--accent);
    color: white;
    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; }


/* ── 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);
}

.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-primary);
}

.alg-delete-btn {
    padding: 6px;
    background: var(--delete-btn-bg);
    color: var(--text-primary);
    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;
}




/* ================================================================
   DARK-MODE SVG ICON INVERSION
   Using html[data-theme="dark"] gives specificity (0,2,0) + element
   selectors, which beats all plain class-based filter rules in other
   stylesheets (svg-editor, quick-edit) without needing !important.

   How it works: filter is applied to the <img> element in the host
   document — it is NOT blocked by SVG's <img> isolation boundary.
   (Only CSS custom properties / currentColor are blocked.)

   Excluded: avatar images (semantic shape/color, must not invert).
   The always-dark headers (svg-editor, quick-edit) already have their
   own permanent brightness(0) invert(1) rules; this block leaves them
   alone in light mode and correctly overrides to plain invert(1) in
   dark mode — visually the same (black icon → white either way).
   ================================================================ */

/* Smooth transition on theme switch for all SVG <img> icons */
img[src$=".svg"] {
    transition: filter 0.25s ease;
}

/* All pure-black icon SVGs — invert to white in dark mode */
html[data-theme="dark"] img[src$="settings.svg"],
html[data-theme="dark"] img[src$="tracing.svg"],
html[data-theme="dark"] img[src$="training.svg"],
html[data-theme="dark"] img[src$="delete.svg"],
html[data-theme="dark"] img[src$="exit.svg"],
html[data-theme="dark"] img[src$="info.svg"],
html[data-theme="dark"] img[src$="menu.svg"],
html[data-theme="dark"] img[src$="next.svg"],
html[data-theme="dark"] img[src$="notes.svg"],
html[data-theme="dark"] img[src$="pen.svg"],
html[data-theme="dark"] img[src$="previous.svg"],
html[data-theme="dark"] img[src$="redo.svg"],
html[data-theme="dark"] img[src$="reset.svg"],
html[data-theme="dark"] img[src$="revert.svg"],
html[data-theme="dark"] img[src$="save.svg"],
html[data-theme="dark"] img[src$="search.svg"] {
    filter: invert(1);
}


/* ================================================================
   CUBESHAPE SVG THEMING
   The .cubeshape-svg elements are injected inline (from svg.js),
   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
     (fill="white" stroke="black" stroke-width="4").
   - .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;
}

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

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