:root {
    --primary-color: #ea8400;
    --primary-hover: #d67300;
    --primary-light: rgba(234, 132, 0, 0.1);
    --success-color: #10b981;
    --success-hover: #059669;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --surface-color: #ffffff;
    --surface-elevated: #f8fafc;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;
    --toast-duration: 3s;
    --toast-fade-delay: 2.7s;
}

.dark-mode {
    --primary-color: #ff9d1a;
    --primary-hover: #ea8400;
    --primary-light: rgba(255, 157, 26, 0.15);
    --surface-color: #1e293b;
    --surface-elevated: #334155;
    --border-color: #475569;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
}


.tool-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px 40px;
}


.tool-header {
    text-align: center;
    padding: 40px 20px 30px;
    margin-bottom: 20px;
}

.header-content {
    max-width: 600px;
    margin: 0 auto;
}

.header-icon {
    margin-bottom: 16px;
}

.icon-sparkle {
    font-size: 3rem;
    display: inline-block;
    animation: sparkle 2s ease-in-out infinite;
}

@keyframes sparkle {

    0%,
    100% {
        transform: scale(1) rotate(0deg);
    }

    25% {
        transform: scale(1.1) rotate(-5deg);
    }

    50% {
        transform: scale(1) rotate(0deg);
    }

    75% {
        transform: scale(1.1) rotate(5deg);
    }
}

.tool-header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 12px;
    letter-spacing: -0.02em;
}

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

.keyboard-hint {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.85rem;
    color: var(--text-muted);
}

kbd {
    display: inline-block;
    padding: 4px 8px;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}


.stats-bar {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 16px 24px;
    background: var(--surface-elevated);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-icon {
    font-size: 1.2rem;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}


.tool-content {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
    align-items: start;
}


.options-sidebar {
    position: sticky;
    top: 20px;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--primary-light);
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.preset-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.preset-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: rotate(-180deg);
}


.option-card {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.option-card:last-child {
    border-bottom: none;
}

.option-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 12px 0;
    text-align: left;
}

.card-icon {
    font-size: 1.1rem;
}

.card-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: none;
    border: none;
    padding: 0;
    margin: 0 0 12px 0;
    cursor: pointer;
    color: inherit;
}

.card-toggle h3 {
    margin: 0;
}

.toggle-icon {
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.card-toggle[aria-expanded="false"] .toggle-icon {
    transform: rotate(-90deg);
}

.card-content {
    overflow: hidden;
    transition: max-height var(--transition-normal);
}

.card-toggle[aria-expanded="false"]+.card-content {
    max-height: 0;
    margin-top: 0;
}


.preset-card {
    background: var(--surface-elevated);
}


.input-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.input-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.input-group input,
.input-group select {
    padding: 10px 12px;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface-color);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.dark-mode .input-group input,
.dark-mode .input-group select {
    background: var(--surface-elevated);
}


.canvas-area {
    position: relative;
}

.canvas-container {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: box-shadow var(--transition-fast);
}

.canvas-container:focus-within {
    box-shadow: var(--shadow-lg), 0 0 0 3px var(--primary-light);
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface-elevated);
    border-bottom: 1px solid var(--border-color);
}

.canvas-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.canvas-wrapper {
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#sorting-canvas {
    display: block;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}


.action-bar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
}

.primary-actions {
    display: flex;
    justify-content: center;
}

.secondary-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}


.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.action-btn:hover {
    background: var(--surface-elevated);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

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

.action-btn.primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.action-btn.primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.action-btn.large {
    padding: 16px 32px;
    font-size: 1.1rem;
    border-radius: var(--radius-lg);
}

.action-btn.success {
    background: var(--success-color);
    border-color: var(--success-color);
    color: white;
}

.action-btn.success:hover {
    background: var(--success-hover);
    border-color: var(--success-hover);
}

.action-btn.warning {
    background: var(--warning-color);
    border-color: var(--warning-color);
    color: white;
}

.action-btn.danger {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: white;
}

.btn-icon {
    font-size: 1.1em;
}


.legend-panel {
    margin-top: 20px;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface-elevated);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.legend-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    text-align: left;
}

.legend-content {
    padding: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--surface-elevated);
    border-radius: var(--radius-sm);
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.legend-label {
    font-size: 0.85rem;
    color: var(--text-primary);
}


.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--surface-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    border-left: 4px solid var(--primary-color);
    animation: slideIn 0.3s ease, fadeOut 0.3s ease var(--toast-fade-delay) forwards;
}

.toast.success {
    border-left-color: var(--success-color);
}

.toast.error {
    border-left-color: var(--danger-color);
}

.toast-icon {
    font-size: 1.2rem;
}

.toast-message {
    font-size: 0.9rem;
    color: var(--text-primary);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}


input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    outline: none;
    transition: background var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-md);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow-sm);
}


input[type="number"] {
    padding: 10px 12px;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface-color);
    color: var(--text-primary);
    transition: all var(--transition-fast);
    width: 100%;
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.dark-mode input[type="number"] {
    background: var(--surface-elevated);
}


select {
    padding: 10px 12px;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface-color);
    color: var(--text-primary);
    transition: all var(--transition-fast);
    width: 100%;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.dark-mode select {
    background: var(--surface-elevated);
}


@media (max-width: 1024px) {
    .tool-content {
        grid-template-columns: 1fr;
    }

    .options-sidebar {
        position: static;
    }
}

@media (max-width: 768px) {
    .tool-header h1 {
        font-size: 1.8rem;
    }

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

    .stats-bar {
        gap: 16px;
        padding: 12px 16px;
    }

    .stat-item {
        flex-direction: column;
        gap: 4px;
        text-align: center;
    }

    .secondary-actions {
        gap: 6px;
    }

    .action-btn {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    .action-btn.large {
        padding: 14px 24px;
        font-size: 1rem;
    }

    .keyboard-hint {
        display: none;
    }

    .legend-content {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .tool-header {
        padding: 24px 16px;
    }

    .tool-header h1 {
        font-size: 1.5rem;
    }

    .tool-main {
        padding: 0 12px 32px;
    }

    .secondary-actions {
        flex-direction: column;
        width: 100%;
    }

    .action-btn {
        width: 100%;
        justify-content: center;
    }

    .toast-container {
        left: 12px;
        right: 12px;
        bottom: 12px;
    }
}


.help-box {
    margin-top: 30px;
    padding: 20px;
    background: var(--primary-light);
    border-radius: var(--radius-lg);
    border-left: 4px solid var(--primary-color);
}

.help-box strong {
    display: block;
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.help-box ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-box li {
    padding: 6px 0;
    color: var(--text-secondary);
    line-height: 1.6;
}

.help-box li:before {
    content: "→ ";
    color: var(--primary-color);
    font-weight: bold;
    margin-right: 8px;
}


.explanation-section {
    margin-top: 40px;
    padding: 30px;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}

.section-header h2 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 12px;
}

.explanation-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.explanation-card {
    padding: 24px;
    background: var(--surface-elevated);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.explanation-card h3 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.explanation-card h4 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 16px 0 10px 0;
}

.explanation-card p {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.explanation-card ul {
    list-style: none;
    padding-left: 0;
    margin: 12px 0;
}

.explanation-card li {
    padding: 8px 0;
    padding-left: 24px;
    color: var(--text-secondary);
    line-height: 1.6;
    position: relative;
}

.explanation-card li:before {
    content: "▸";
    color: var(--primary-color);
    font-weight: bold;
    position: absolute;
    left: 0;
}

.formula-box {
    padding: 16px 20px;
    background: white;
    border: 2px solid var(--primary-color);
    border-radius: var(--radius-sm);
    margin: 16px 0;
    font-family: 'Courier New', monospace;
}

.dark-mode .formula-box {
    background: #2d3748;
    border-color: var(--primary-color);
}

.formula-box p {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 8px 0;
    text-align: center;
}

.comparison-table table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.comparison-table th,
.comparison-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.comparison-table th {
    background: var(--card-background);
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    color: var(--text-primary);
}

.comparison-table td {
    color: var(--text-secondary);
}


@media (max-width: 480px) {
    .explanation-section {
        padding: 20px 16px;
        margin-top: 24px;
    }

    .section-header h2 {
        font-size: 1.4rem;
    }

    .explanation-card {
        padding: 16px;
    }

    .explanation-card h3 {
        font-size: 1.1rem;
    }

    .formula-box {
        padding: 12px;
        font-size: 0.9rem;
    }

    .comparison-table {
        font-size: 0.85rem;
    }

    .comparison-table th,
    .comparison-table td {
        padding: 0.5rem;
    }
}