:root {
    color-scheme: light;
    --page-bg-start: #fbf7f0;
    --page-bg-end: #f5f1ea;
    --panel-bg: rgba(255, 253, 248, 0.98);
    --panel-bg-subtle: #f7f2ea;
    --ink: #201b18;
    --muted: #6d645d;
    --rule: #d8cec3;
    --rule-light: #ece5dc;
    --accent: #955f3b;
    --accent-hover: #b4754a;
    --accent-light: #f2e6dc;
    --status-success: #2c6a4f;
    --status-success-bg: #eaf5ee;
    --status-error: #a83232;
    --status-error-bg: #fbeeed;
    --status-warning: #b26a00;
    --status-warning-bg: #fff7e6;
    --shadow-light: rgba(54, 40, 23, 0.08);
    --shadow-medium: rgba(54, 40, 23, 0.16);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    color: var(--ink);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--page-bg-start);
    display: flex;
    flex-direction: column;
}

/* Header */
.editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 24px;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--rule);
    height: 58px;
    flex-shrink: 0;
    z-index: 20;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-sidebar-toggle {
    background: var(--panel-bg-subtle);
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-sidebar-toggle:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    transform: scale(1.05);
}

.btn-sidebar-toggle:active {
    transform: scale(0.95);
}

.editor-title {
    font-family: "Georgia", serif;
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 8px;
}

.editor-subtitle {
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
    border-left: 1px solid var(--rule);
    padding-left: 12px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-header {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid var(--rule);
    background: var(--panel-bg);
    color: var(--ink);
    text-decoration: none;
    transition: all 0.15s ease;
}

.btn-header:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-header.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.btn-header.primary:hover {
    background: var(--accent-hover);
}

/* Main Container Layout */
.editor-layout {
    display: flex;
    flex: 1;
    height: calc(100vh - 58px);
    overflow: hidden;
    position: relative;
}

/* Left Sidebar - Form Panels */
.editor-sidebar {
    width: 480px;
    background: var(--panel-bg);
    border-right: 1px solid var(--rule);
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 20;
    box-shadow: 2px 0 10px var(--shadow-light);
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.editor-sidebar.collapsed {
    margin-left: -480px;
}

.sidebar-scrollable {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sidebar-scrollable::-webkit-scrollbar {
    width: 6px;
}
.sidebar-scrollable::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-scrollable::-webkit-scrollbar-thumb {
    background: var(--rule);
    border-radius: 3px;
}

/* Form Sections */
.form-section {
    background: #ffffff;
    border: 1px solid var(--rule-light);
    border-radius: var(--radius-md);
    padding: 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    transition: all 0.2s ease;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--rule-light);
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
}

.section-header:hover .section-title {
    color: var(--accent-hover);
}

.section-collapse-arrow {
    font-size: 10px;
    color: var(--muted);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: auto;
}

.form-section.collapsed .section-collapse-arrow {
    transform: rotate(-90deg);
}

.form-section.collapsed .section-header {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.form-section.collapsed .section-body {
    display: none;
}

.section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 6px;
}

.section-hint {
    font-size: 11px;
    color: var(--muted);
}

/* Form Elements */
.form-group {
    margin-bottom: 12px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 5px;
}

.form-label span.req {
    color: var(--status-error);
    margin-left: 2px;
}

.form-input, .form-textarea, .form-select {
    width: 100%;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 13px;
    color: var(--ink);
    background: var(--panel-bg-subtle);
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
    border-color: var(--accent);
    background: #ffffff;
    box-shadow: 0 0 0 2px rgba(149, 95, 59, 0.12);
}

.form-textarea {
    resize: vertical;
    min-height: 54px;
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.form-row-4 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 8px;
}

/* Items List (Obstacles & Rewards) */
.items-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
    max-height: 160px;
    overflow-y: auto;
}

.item-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: var(--panel-bg-subtle);
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    font-size: 12px;
}

.item-chip-content {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Georgia', serif;
    font-size: 13px;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-chip.obstacle .badge {
    background: var(--status-error-bg);
    color: var(--status-error);
    font-family: 'Inter', sans-serif;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}

.item-chip.reward .badge {
    background: var(--status-success-bg);
    color: var(--status-success);
    font-family: 'Inter', sans-serif;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}

.btn-remove-chip {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.btn-remove-chip:hover {
    color: var(--status-error);
    background: var(--status-error-bg);
}

.add-input-bar {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.btn-add-item {
    padding: 7px 14px;
    background: var(--accent-light);
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.btn-add-item:hover {
    background: var(--accent);
    color: #ffffff;
}

/* Checkbox & Multi-select pills */
.pills-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.pill-checkbox {
    display: none;
}

.pill-label {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    background: var(--panel-bg-subtle);
    border: 1px solid var(--rule);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ink);
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
}

.pill-checkbox:checked + .pill-label {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
    font-weight: 600;
}

.pill-checkbox.forbidden:checked + .pill-label {
    background: var(--status-error);
    border-color: var(--status-error);
    color: #ffffff;
}

.custom-checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    font-size: 13px;
}

.custom-checkbox-row input {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Right Content Area */
.editor-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* Preview Canvas Container */
.preview-container {
    flex: 1;
    position: relative;
    background: var(--page-bg-start);
    overflow: hidden;
}

#editor-jxgbox {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none !important;
    background-color: var(--page-bg-start) !important;
}

/* Floating Top Level Details Card */
.floating-top-panel {
    position: absolute;
    top: 14px;
    left: 14px;
    width: 290px;
    max-width: 320px;
    max-height: 45vh;
    z-index: 30;
    overflow-y: auto;
}

.math-details-box {
    display: flex;
    flex-direction: column;
    background-color: rgba(255, 253, 248, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px var(--shadow-medium);
    overflow: hidden;
}

.geogebra-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--rule-light);
    transition: background 0.15s ease;
}

.geogebra-row:last-child {
    border-bottom: none;
}

.geogebra-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    background-color: color-mix(in srgb, currentColor 25%, transparent);
    flex-shrink: 0;
}

.geogebra-icon.obstacle {
    color: #a83232;
}

.geogebra-icon.gem {
    color: #e59c00;
    border-radius: 3px;
    transform: rotate(45deg);
}

.geogebra-text {
    font-size: 13px;
    color: var(--ink);
    font-family: "Georgia", serif;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-delete-row {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-left: auto;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.btn-delete-row:hover {
    background: rgba(168, 50, 50, 0.12);
    color: var(--status-error);
}

.btn-edit-row {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    transition: color 0.15s ease;
    flex-shrink: 0;
    padding: 0;
}

.btn-edit-row:hover,
.btn-edit-row.active {
    color: var(--accent);
}

/* Obstacle Row with Intervals */
.geogebra-row.obstacle-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 8px 12px;
    gap: 6px;
}

.geogebra-row.obstacle-row.editing {
    background: rgba(149, 95, 59, 0.08);
    border-left: 3px solid var(--accent);
}

.obstacle-row-header {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 8px;
}

.intervals-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    padding-left: 24px;
    border-top: 1px dashed rgba(0, 0, 0, 0.08);
    padding-top: 6px;
}

.interval-list-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    width: 100%;
}

.interval-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--muted);
    width: 100%;
}

.btn-add-interval {
    background: rgba(149, 95, 59, 0.08);
    border: 1px solid rgba(149, 95, 59, 0.2);
    color: var(--accent);
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    align-self: flex-start;
}

.btn-add-interval:hover {
    background: var(--accent);
    color: #ffffff;
}

.btn-delete-interval {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    transition: all 0.1s ease;
    margin-left: 2px;
}

.btn-delete-interval:hover {
    background: rgba(168, 50, 50, 0.1);
    color: var(--status-error);
}

.range-inputs-group {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    color: var(--muted);
}

.range-input {
    width: 44px;
    height: 20px;
    border: 1px solid var(--rule);
    border-radius: 4px;
    background: #ffffff;
    color: var(--ink);
    text-align: center;
    font-family: inherit;
    font-size: 11px;
    padding: 0;
    outline: none;
}

.range-input:focus {
    border-color: var(--accent);
    background: #fffdfa;
}

/* Preview floating legend / overlay (positioned top-right to avoid overlap) */
.preview-legend {
    position: absolute;
    top: 14px;
    right: 14px;
    background: var(--panel-bg);
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 11px;
    color: var(--ink);
    display: flex;
    gap: 12px;
    box-shadow: 0 2px 8px var(--shadow-light);
    z-index: 5;
    pointer-events: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.legend-dot.start { background: #2ca02c; }
.legend-dot.finish { background: #2c72c0; }
.legend-dot.obstacle { background: #a83232; }
.legend-dot.reward { background: #e09f3e; }

/* Reachability Banner */
.reachability-bar {
    padding: 10px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--rule);
    background: var(--panel-bg);
    z-index: 10;
    font-size: 13px;
    font-weight: 600;
}

.reachability-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
}

.status-badge.pass {
    background: var(--status-success-bg);
    color: var(--status-success);
    border: 1px solid rgba(44, 106, 79, 0.2);
}

.status-badge.fail {
    background: var(--status-error-bg);
    color: var(--status-error);
    border: 1px solid rgba(168, 50, 50, 0.2);
}

.status-badge.pending {
    background: var(--status-warning-bg);
    color: var(--status-warning);
    border: 1px solid rgba(178, 106, 0, 0.2);
}

/* Modals */
.editor-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.editor-modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.editor-modal {
    background: var(--panel-bg);
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 520px;
    box-shadow: 0 10px 30px var(--shadow-medium);
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.editor-modal-overlay.open .editor-modal {
    transform: scale(1);
}

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

.modal-title {
    font-family: 'Georgia', serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--ink);
}

.modal-body {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--rule);
    background: var(--panel-bg-subtle);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Toast Notifications */
.editor-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    background: var(--ink);
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 6px 20px var(--shadow-medium);
    z-index: 200;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.editor-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.editor-toast.error {
    background: var(--status-error);
}

.editor-toast.success {
    background: var(--status-success);
}

/* =============================================================
   Floating Equation Dock & Virtual Math Keyboard Styles
   ============================================================= */

.dock-label-badge {
    font-family: "Georgia", serif;
    font-weight: 700;
    font-size: 15px;
    color: var(--status-error);
    background: var(--status-error-bg);
    border: 1px solid rgba(168, 50, 50, 0.2);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    user-select: none;
}

.floating-bottom-bar {
    position: absolute;
    bottom: 20px;
    left: 80px;
    right: 20px;
    max-width: 880px;
    margin: 0 auto;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: bottom 0.3s cubic-bezier(0.1, 0.76, 0.55, 0.94);
}

.floating-bottom-bar.kb-open {
    bottom: 275px;
}

.dock-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 253, 248, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--rule);
    border-radius: 12px;
    padding: 8px 12px;
    box-shadow: 0 4px 20px rgba(54, 40, 23, 0.12);
}

.eq-input-wrapper {
    position: relative;
    flex: 1;
    min-height: 46px;
    border: 1px solid var(--rule);
    border-radius: 8px;
    background-color: #fffdf8;
    box-shadow: inset 0 2px 4px rgba(54, 40, 23, 0.04);
    padding: 4px 16px;
    display: flex;
    align-items: center;
    transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

.eq-input-wrapper:focus-within {
    border-color: var(--accent);
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(149, 95, 59, 0.15), inset 0 2px 4px rgba(54, 40, 23, 0.04);
}

.eq-input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    color: transparent;
    -webkit-text-fill-color: transparent;
    caret-color: var(--ink);
    font-family: "Georgia", serif;
    font-size: 18px;
    font-weight: 700;
    padding: 0;
    outline: none;
    position: relative;
    z-index: 2;
}

.eq-input:focus {
    color: var(--ink) !important;
    -webkit-text-fill-color: var(--ink) !important;
}

.eq-input:focus + .eq-latex-render {
    opacity: 0;
}

.eq-input::placeholder {
    font-family: "Inter", sans-serif;
    font-size: 13px;
    font-weight: 500;
    font-style: normal;
    color: var(--muted);
}

.eq-latex-render {
    position: absolute;
    left: 16px;
    right: 16px;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    pointer-events: none;
    z-index: 1;
    font-size: 18px;
    color: var(--ink);
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.1s ease;
}

.eq-live-preview {
    position: absolute;
    bottom: 58px;
    left: 0;
    background: var(--panel-bg);
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 8px 16px;
    box-shadow: 0 4px 15px rgba(54, 40, 23, 0.15);
    z-index: 60;
    font-size: 17px;
    color: var(--ink);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.eq-input:focus ~ .eq-live-preview.visible,
.eq-live-preview.visible {
    opacity: 1;
    transform: translateY(0);
}

.btn-add-func {
    background: var(--status-error);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.05s ease;
    flex-shrink: 0;
}

.btn-add-func:hover {
    background: #8e2828;
}

.btn-add-func:active {
    transform: scale(0.94);
}

/* Keyboard Toggle Button */
.kb-toggle-btn {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    border: 1px solid var(--rule);
    background: var(--panel-bg);
    color: var(--ink);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px var(--shadow-light);
    z-index: 50;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.kb-toggle-btn:hover {
    background: var(--accent-light);
    color: var(--accent);
    transform: translateY(-2px);
}

.kb-toggle-btn:active {
    transform: translateY(0);
}

/* Slide-Up Math Keyboard Panel */
.math-keyboard-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 260px;
    background: rgba(245, 241, 234, 0.96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--rule);
    z-index: 1000;
    display: grid;
    grid-template-columns: 4.5fr 4.5fr 2fr;
    gap: 12px;
    padding: 12px;
    box-shadow: 0 -8px 30px rgba(54, 40, 23, 0.15);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.1, 0.76, 0.55, 0.94);
}

.math-keyboard-panel.open {
    transform: translateY(0);
}

.kb-section {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 6px;
}

.kb-section-right {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, 1fr);
}

.kb-row-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.kb-btn {
    border: 1px solid var(--rule);
    border-radius: 6px;
    background: #ffffff;
    color: var(--ink);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: all 0.12s ease;
    user-select: none;
    -webkit-user-select: none;
}

.kb-btn:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.kb-btn:active {
    transform: scale(0.95);
    background: var(--accent-light);
}

.btn-num {
    background: #e9e3d9;
    font-size: 16px;
    font-weight: 600;
}

.btn-op {
    background: #ffffff;
    font-size: 16px;
    font-weight: 600;
}

.btn-math i {
    font-family: Georgia, serif;
    font-weight: 700;
}

.btn-toggle, .btn-special {
    background: #d8cec3;
    font-size: 13px;
    font-weight: 600;
}

.btn-nav {
    background: #d8cec3;
    font-size: 16px;
}

.btn-backspace {
    background: #d8cec3;
    color: #a83232;
}

.btn-submit {
    background: var(--status-error);
    color: #ffffff;
    border-color: #8e2828;
}

.btn-submit:hover {
    background: #8e2828;
    color: #ffffff;
}

.btn-submit:active {
    background: #701e1e;
}

/* -------------------------------------------------------------
 * Parameter Slider Box (GeoGebra style constants sliders)
 * ------------------------------------------------------------- */
.param-slider-box {
    display: flex;
    flex-direction: column;
    width: 100%;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid var(--rule-light);
    border-radius: 8px;
    padding: 8px 10px;
    margin-top: 6px;
    margin-bottom: 4px;
    box-sizing: border-box;
    position: relative;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    transition: opacity 0.2s ease;
}

.param-slider-box.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.param-slider-box .param-range-input:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.param-slider-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    color: var(--ink);
    margin-bottom: 6px;
}

.param-name-label {
    display: flex;
    align-items: center;
    gap: 4px;
}

.param-name-label strong {
    font-family: 'Georgia', serif;
    font-size: 14px;
    color: var(--accent);
}

.param-val-text {
    font-family: 'Inter', monospace;
    font-weight: 600;
    color: var(--ink);
    background: rgba(0, 0, 0, 0.05);
    padding: 1px 6px;
    border-radius: 4px;
}

.btn-param-dots {
    background: none;
    border: none;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.btn-param-dots:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--ink);
}

.param-slider-track-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.param-bound {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    font-family: 'Inter', sans-serif;
    min-width: 24px;
    text-align: center;
}

.param-range-input {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: #d8cec3;
    outline: none;
    cursor: pointer;
    transition: background 0.15s;
}

.param-range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: transform 0.1s ease, background 0.15s ease;
}

.param-range-input::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    background: var(--accent-hover);
}

.param-settings-popover {
    position: absolute;
    top: 100%;
    right: 8px;
    z-index: 100;
    background: #ffffff;
    border: 1px solid var(--rule);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    padding: 12px;
    width: 190px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    animation: fadeInPopover 0.15s ease-out;
}

@keyframes fadeInPopover {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.popover-title {
    font-weight: 700;
    color: var(--ink);
    font-size: 12px;
    border-bottom: 1px solid var(--rule-light);
    padding-bottom: 4px;
}

.popover-fields {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.popover-fields label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
    color: var(--muted);
}

.popover-fields input {
    width: 75px;
    padding: 3px 6px;
    border: 1px solid var(--rule);
    border-radius: 4px;
    font-size: 12px;
    text-align: right;
}

.popover-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 4px;
}

.btn-popover-save {
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.btn-popover-save:hover {
    background: var(--accent-hover);
}

.btn-popover-cancel {
    background: #e5e0d7;
    color: var(--ink);
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
}
