:root {
    /* ===== APP BACKGROUNDS ===== */
    --bg-app: linear-gradient(135deg, #0d1117, #202731);
    --bg-landing:
        radial-gradient(800px 400px at 50% 20%,
            rgba(99, 102, 241, 0.12),
            transparent 60%),
        linear-gradient(135deg, #0d1117, #1f2937);

    /* ===== TEXT ===== */
    --text-app-primary: #ffffff;
    --text-app-secondary: #cbd5e1;

    /* ===== ACCENTS ===== */
    --accent-primary: #2563eb;
    --accent-soft: rgba(255, 255, 255, 0.1);
    --app-safe-top: env(safe-area-inset-top, 0px);
    --app-safe-bottom: env(safe-area-inset-bottom, 0px);

    --sidebar-width: clamp(220px, 22vw, 300px);
    --toolbar-height: clamp(56px, 7vh, 64px);
    --modal-width-sm: min(90vw, 420px);
}


.study-locked {
    pointer-events: none;
}

/* ===============================
   REMOVE NUMBER INPUT SPINNERS
   =============================== */

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

/* Works on Chrome, Edge, Safari */
*::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
}

/* Firefox */
* {
    scrollbar-width: none !important;
}

body,
html,
#notesPage,
.notes-editor,
.notes-tree {
    overflow-x: hidden !important;
}

input,
textarea,
select {
    font-size: 16px !important;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

input[type="range"] {
    --slider-track-h: 8px;
    --slider-thumb-size: 18px;
    --slider-track-bg: linear-gradient(
        90deg,
        color-mix(in srgb, var(--accent-primary), var(--surface-base) 38%) 0%,
        color-mix(in srgb, var(--accent-primary), var(--text-primary) 14%) 48%,
        color-mix(in srgb, var(--surface-border), var(--surface-base) 12%) 100%
    );
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: var(--slider-thumb-size);
    line-height: 1;
    padding: 0;
    border-radius: 999px;
    background: transparent;
    outline: none;
    cursor: pointer;
    transition: box-shadow 0.2s ease, background 0.2s ease;
}

input[type="range"]:focus,
input[type="range"]:focus-visible {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-primary), transparent 78%);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: var(--slider-thumb-size);
    height: var(--slider-thumb-size);
    margin-top: calc((var(--slider-track-h) - var(--slider-thumb-size)) / 2);
    border-radius: 50%;
    border: 2px solid var(--surface-base);
    background: radial-gradient(
        circle at 32% 30%,
        color-mix(in srgb, var(--text-primary), transparent 6%) 0%,
        var(--accent-primary) 65%
    );
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--accent-primary), transparent 45%),
        0 3px 10px color-mix(in srgb, var(--accent-primary), transparent 62%);
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.06);
}

input[type="range"]::-webkit-slider-runnable-track {
    height: var(--slider-track-h);
    border-radius: 999px;
    background: var(--slider-track-bg);
    border: 1px solid color-mix(in srgb, var(--surface-border), var(--text-primary) 8%);
    box-shadow: inset 0 1px 0 color-mix(in srgb, var(--text-primary), transparent 88%);
}

input[type="range"]::-moz-range-track {
    height: var(--slider-track-h);
    border-radius: 999px;
    background: var(--slider-track-bg);
    border: 1px solid color-mix(in srgb, var(--surface-border), var(--text-primary) 8%);
}

input[type="range"]::-moz-range-progress {
    height: var(--slider-track-h);
    border-radius: 999px;
    background: linear-gradient(
        90deg,
        color-mix(in srgb, var(--accent-primary), var(--text-primary) 18%) 0%,
        color-mix(in srgb, var(--accent-primary), var(--surface-base) 22%) 100%
    );
}

input[type="range"]::-moz-range-thumb {
    width: var(--slider-thumb-size);
    height: var(--slider-thumb-size);
    border-radius: 50%;
    border: 2px solid var(--surface-base);
    background: radial-gradient(
        circle at 32% 30%,
        color-mix(in srgb, var(--text-primary), transparent 6%) 0%,
        var(--accent-primary) 65%
    );
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--accent-primary), transparent 45%),
        0 3px 10px color-mix(in srgb, var(--accent-primary), transparent 62%);
}

.fade-in {
    animation: fadeIn 0.35s ease forwards;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255, 255, 255, 0.2);
    border-top-color: #4f9eff;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.save-btn:hover {
    background: rgba(59, 130, 246, 0.65);
    backdrop-filter: blur(6px) brightness(1.25);
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.cancel-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(6px) brightness(1.3);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.danger-btn:hover {
    background: rgba(255, 0, 0, 0.55);
    backdrop-filter: blur(5px) brightness(1.2);
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(255, 0, 0, 0.18);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* ============================================================
   APP SHELL — SIDE PANEL
   ============================================================ */

:root {
    --toolbar-height: 60px;
    --sidebar-width: clamp(220px, 22vw, 300px);
}

#sidePanel {
    position: fixed;
    top: var(--toolbar-height);
    left: 0;

    width: var(--sidebar-width);
    height: calc(100dvh - var(--toolbar-height) - var(--app-safe-bottom));

    background: var(--surface-muted);
    color: var(--text-primary);
    padding: 20px;
    padding-bottom: calc(20px + var(--app-safe-bottom));

    box-shadow: var(--shadow-elevated);

    transform: translateX(-100%);
    transition: transform 0.3s ease;

    z-index: 999999;

    display: flex;
    flex-direction: column;
}

#sidePanel.open {
    transform: translateX(0);
}

#sidePanelScroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-right: 4px;
}

#sidePanelBottom {
    padding-top: 10px;
    padding-bottom: var(--app-safe-bottom);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

/* ============================================================
   SIDE PANEL BACKDROP
   ============================================================ */

#sidePanelBackdrop {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 999998;
    display: none;
}

#sidePanelBackdrop.show {
    display: block;
}

/* ============================================================
   APP SHELL — FLASH TOOLBAR
   ============================================================ */

:root {
    --toolbar-height: clamp(56px, 7vh, 64px);
    --toolbar-bg: var(--surface-muted);
    --toolbar-control-height: 36px;
}

/* Main toolbar bar */
#flashToolbarBar {
    position: fixed;
    top: 0;
    left: 0;

    width: 100%;
    height: var(--toolbar-height);

    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--surface-border);

    display: flex;
    align-items: center;
    justify-content: center;

    z-index: 99997;
    box-shadow: var(--shadow-soft);
}

/* Full-width inner positioning grid */
#flashToolbarBar>div {
    position: relative;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas: "left center right";
    align-items: center;
    gap: 10px;
    padding: 0 10px;
}

/* LEFT */
#tbLeft {
    grid-area: left;
    position: static;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    overflow: hidden;
}

/* CENTER */
#tbCenter {
    grid-area: center;
    position: static;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 0;
    justify-self: center;
    max-width: 100%;
    overflow: hidden;
}

.tb-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    min-width: 0;
    max-width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    white-space: nowrap;
}

.tb-nav::-webkit-scrollbar {
    display: none;
}

/* RIGHT */
#tbRight {
    grid-area: right;
    position: static;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
    max-width: 100%;
    overflow: visible;
}

#tbRight > * {
    flex: 0 0 auto;
}

/* Progress bar wrapper */
#tbProgressWrapper {
    width: 180px;
    height: 6px;

    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    overflow: hidden;
}

#tbProgressFill {
    height: 100%;
    width: 0%;
    background: #3b82f6;
    transition: width 0.35s ease;
}

#mobileStudyProgressRow {
    position: fixed;
    top: var(--toolbar-height);
    left: 0;
    right: 0;
    height: 16px;
    padding: 4px 10px;
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--surface-border);
    z-index: 99996;
    display: none;
}

#mobileStudyProgressTrack {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    overflow: hidden;
}

#mobileStudyProgressFill {
    height: 100%;
    width: 0%;
    background: #3b82f6;
    transition: width 0.35s ease;
}

/* Mode switch */
#flashModeSwitch {
    display: flex;
    gap: 6px;
    justify-content: flex-start;
    flex: 1 1 auto;
    width: 0;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#flashModeSwitch::-webkit-scrollbar {
    display: none;
}

#flashModeSwitch .modeBtn {
    flex: 0 0 auto;
    white-space: nowrap;
}

#flashModeDropdownWrap {
    display: none;
    align-items: center;
    min-width: 0;
    flex: 0 0 auto;
}

#flashModeDropdown {
    width: auto;
    min-width: 92px;
    max-width: min(56vw, 240px);
    height: var(--toolbar-control-height);
    padding-right: 28px;
}

#flashToolbarBar .toolbar-btn {
    white-space: nowrap;
}

@media (max-width: 980px) {
    #flashToolbarBar {
        --toolbar-control-height: 34px;
    }

    #flashToolbarBar > div {
        gap: 8px;
        padding: 0 8px;
    }

    #tbLeft {
        gap: 8px;
    }

    #tbRight {
        gap: 8px;
    }

    .tb-nav {
        gap: 8px;
    }

    #tbPrev,
    #tbFlip,
    #tbNext {
        padding: 6px 9px !important;
        font-size: 14px !important;
    }

    #tbProgressWrapper {
        width: 150px;
    }

    #flashModeSwitch {
        gap: 4px;
    }

    #flashModeSwitch .modeBtn {
        padding: 5px 8px;
        font-size: 12px;
    }

    #flashToolbarBar .toolbar-btn {
        padding: 6px 9px;
        font-size: 13px;
    }

    #difficultyBtn,
    #instanceBtn,
    #tbMore {
        padding: 6px 9px !important;
        font-size: 13px !important;
    }
}

@media (max-width: 760px) {
    #flashToolbarBar {
        --toolbar-control-height: 32px;
    }

    #flashToolbarBar > div {
        gap: 6px;
        padding: 0 6px;
    }

    #tbLeft {
        gap: 6px;
    }

    #tbCenter {
        gap: 4px;
    }

    .tb-nav {
        gap: 6px;
    }

    #tbPrev,
    #tbFlip,
    #tbNext {
        padding: 5px 7px !important;
        font-size: 12px !important;
    }

    #tbProgressWrapper {
        width: 110px;
    }

    #flashModeSwitch .modeBtn {
        padding: 4px 7px;
        font-size: 11px;
    }

    #tbRight {
        gap: 6px;
    }

    #flashToolbarBar .toolbar-btn {
        padding: 5px 8px;
        font-size: 12px;
    }

    #difficultyBtn,
    #instanceBtn,
    #tbMore {
        padding: 5px 8px !important;
        font-size: 12px !important;
    }
}

/* Difficulty dropdown wrapper */
#difficultyDropdown {
    display: inline-block;
    position: relative;
}

/* Notes toolbar (only visible in notes mode) */
#notesToolbar {
    display: none;
    align-items: center;
    gap: 10px;
    padding-left: 20px;
    padding-right: 96px;
    max-width: calc(100vw - 96px);
    min-width: 0;
    overflow: visible;
    position: relative;
}

#notesToolbarCenter {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    white-space: nowrap;
}

#notesToolbarCenter > * {
    flex: 0 0 auto;
}

#notesToolbar .notes-math {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
}

#notesToolbarRight {
    flex: 0 0 auto;
    position: absolute !important;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    margin-left: 0 !important;
    z-index: 2;
}

#flashToolbarBar #notesMobileBrowseToolbarBtn,
#notesMobileToolsWrap {
    display: none;
}

#notesMobileBrowseToolbarBtn {
    font-weight: 700;
    border: 1px solid color-mix(in srgb, var(--accent-primary), var(--surface-border) 35%) !important;
    background: color-mix(in srgb, var(--accent-primary), transparent 82%) !important;
    color: var(--text-primary) !important;
    border-radius: 10px !important;
    padding: 0 12px !important;
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-primary), transparent 72%);
    transform: none !important;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

#notesMobileBrowseToolbarBtn:hover,
#notesMobileBrowseToolbarBtn:active,
#notesMobileBrowseToolbarBtn:focus-visible {
    background: color-mix(in srgb, var(--accent-primary), transparent 72%) !important;
    border-color: color-mix(in srgb, var(--accent-primary), var(--text-primary) 14%) !important;
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-primary), transparent 58%);
    transform: none !important;
    outline: none;
}

.notes-mobile-tools-wrap {
    position: relative;
}

.notes-mobile-tools-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    max-height: min(60dvh, 380px);
    overflow-y: auto;
    padding: 6px;
    border-radius: 10px;
    background: var(--surface-muted);
    border: 1px solid var(--surface-border);
    box-shadow: var(--shadow-elevated);
    z-index: 1000003;
}

.notes-mobile-tools-menu.show {
    display: block;
}

.notes-mobile-tools-menu button {
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
}

.notes-mobile-tools-menu button:hover {
    background: var(--surface-hover);
}

#flashToolbarBar.notes-toolbar-active #tbRight {
    justify-self: end;
    justify-content: flex-end;
    width: auto;
    max-width: calc(100vw - 24px);
}

#flashToolbarBar.notes-toolbar-active #notesToolbar {
    margin-left: auto;
    max-width: min(78vw, 960px);
}

@media (max-width: 760px) {
    #flashToolbarBar.notes-toolbar-active #tbRight {
        max-width: calc(100vw - 84px);
    }
}

@media (max-width: 900px) {
    body.mobile-study-mode #flashToolbarBar > div,
    body.mobile-flash-mcq-mode #flashToolbarBar > div {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "left right";
    }

    body.mobile-study-mode #toolbarTitle,
    body.mobile-flash-mcq-mode #toolbarTitle {
        display: none !important;
    }

    body.mobile-study-mode #flashModeDropdown,
    body.mobile-flash-mcq-mode #flashModeDropdown {
        max-width: min(44vw, 170px);
    }

    body.mobile-study-mode #tbCenter {
        display: none !important;
    }
    body.mobile-flash-mcq-mode #tbCenter {
        display: none !important;
    }

    body.mobile-study-mode #mobileStudyProgressRow {
        display: block;
    }
    body.mobile-flash-mcq-mode #mobileStudyProgressRow {
        display: block;
    }

    body.mobile-study-mode #tbRight {
        gap: 0;
        min-width: max-content;
        justify-self: end;
    }

    body.mobile-study-mode #difficultyDropdown,
    body.mobile-study-mode #instanceBtn {
        margin-left: 0 !important;
    }

    body.mobile-study-mode #difficultyBtn,
    body.mobile-study-mode #instanceBtn {
        height: 34px !important;
        min-height: 34px !important;
        padding: 0 12px !important;
        border: 1px solid color-mix(in srgb, var(--surface-border), var(--text-primary) 12%) !important;
        background: color-mix(in srgb, var(--surface-elevated), var(--surface-hover) 28%) !important;
        color: var(--text-primary) !important;
        line-height: 1 !important;
    }

    body.mobile-study-mode #difficultyBtn {
        border-radius: 10px 0 0 10px !important;
        border-right: none !important;
        margin-left: 0 !important;
    }

    body.mobile-study-mode #instanceBtn {
        border-radius: 0 10px 10px 0 !important;
        margin-left: 0 !important;
    }

    body.mobile-flash-mcq-mode #tbRight {
        gap: 0;
        min-width: max-content;
        justify-self: end;
    }

    body.mobile-flash-mcq-mode #difficultyDropdown,
    body.mobile-flash-mcq-mode #instanceBtn {
        margin-left: 0 !important;
    }

    body.mobile-flash-mcq-mode #difficultyBtn,
    body.mobile-flash-mcq-mode #instanceBtn {
        height: 34px !important;
        min-height: 34px !important;
        padding: 0 12px !important;
        border: 1px solid color-mix(in srgb, var(--surface-border), var(--text-primary) 12%) !important;
        background: color-mix(in srgb, var(--surface-elevated), var(--surface-hover) 28%) !important;
        color: var(--text-primary) !important;
        line-height: 1 !important;
    }

    body.mobile-flash-mcq-mode #difficultyBtn {
        border-radius: 10px 0 0 10px !important;
        border-right: none !important;
        margin-left: 0 !important;
    }

    body.mobile-flash-mcq-mode #instanceBtn {
        border-radius: 0 10px 10px 0 !important;
        margin-left: 0 !important;
    }

    body.mobile-study-mode #tbMore {
        margin-left: 8px !important;
    }

    body.mobile-study-mode #flashToolbarBar .tb-nav {
        display: none !important;
    }

    #flashToolbarBar.notes-toolbar-active #notesToolbar {
        max-width: calc(100vw - 72px);
        padding-left: 8px;
        padding-right: 8px;
    }

    #flashToolbarBar.notes-toolbar-active #notesToolbarCenter {
        display: none !important;
    }

    #flashToolbarBar.notes-toolbar-active #notesToolbarRight {
        position: static !important;
        top: auto;
        right: auto;
        transform: none;
        margin-left: auto !important;
        gap: 6px;
    }

    #flashToolbarBar.notes-toolbar-active #notesMobileBrowseToolbarBtn,
    #flashToolbarBar.notes-toolbar-active #notesMobileToolsWrap {
        display: inline-flex;
        align-items: center;
    }

    #flashToolbarBar.notes-toolbar-active #openAiPanel {
        display: inline-flex !important;
        align-items: center;
    }
}

#progress {
    position: absolute;
    bottom: 20px;
    width: 100%;
    text-align: center;
    font-size: 18px;
    color: #ffffffaa;
}

#landingTopBar {
    width: 100%;
    height: var(--toolbar-height, 60px);
    background: var(--surface-muted);
    position: fixed;
    top: 0;
    left: 0;
    display: none;
    z-index: 999999998;
    border-bottom: 1px solid var(--surface-border);
    box-shadow: var(--shadow-soft);
}
