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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1450px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 24px;
    font-size: 2.3em;
}

.controls {
    display: flex;
    gap: 14px;
    justify-content: center;
    align-items: flex-end;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.controls.secondary {
    align-items: center;
    margin-bottom: 20px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-group.wide {
    min-width: 360px;
}

input.grayed-text {
    color: #999 !important;
}

label {
    font-weight: 600;
    color: #555;
    font-size: 0.9em;
}

input[type="number"],
input[type="text"] {
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 15px;
    min-width: 90px;
    transition: border-color 0.2s;
}

input[type="text"] {
    min-width: 160px;
}

input:focus {
    outline: none;
    border-color: #667eea;
}

button {
    padding: 11px 18px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.25s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    background: #667eea;
    color: white;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

button:disabled {
    background: #cfcfcf;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#clearBtn {
    background: #f56565;
}

#labelBalancesBtn {
    background: #805ad5;
}

#insertBtn {
    background: #38a169;
}

#removeBtn {
    background: #dd6b20;
}

.row-group {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f7fafc;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px;
}

.group-title {
    font-weight: 700;
    color: #2d3748;
    min-width: 56px;
}

.inline {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 6px;
}

.message {
    text-align: center;
    padding: 14px;
    margin-bottom: 16px;
    border-radius: 6px;
    font-weight: 600;
    border: 2px solid transparent;
}

.message.error {
    background: #fed7d7;
    color: #c53030;
    border-color: #fc8181;
}

.message.success {
    background: #c6f6d5;
    color: #22543d;
    border-color: #68d391;
}

.message.info {
    background: #bee3f8;
    color: #2c5282;
    border-color: #63b3ed;
}

.practice-stats {
    margin: 16px 0 20px;
    display: flex;
    justify-content: center;
    gap: 55px;
    font-weight: 700;
    color: #2d3748;
    font-size: 1.7em;
    background: #f0f4f8;
    padding: 16px;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
}

.stat-error {
    color: #c53030;
}

.visualization {
    display: grid;
    grid-template-columns: 2.2fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.section {
    background: #f7fafc;
    padding: 16px;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
}

.section h2 {
    color: #2d3748;
    margin-bottom: 12px;
    text-align: center;
}

#treeView {
    min-height: 480px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: auto;
    padding: 20px;
    width: 100%;
    --node-size: 50px;
    --node-font-size: 16px;
}

.tree-container {
    position: relative;
    display: inline-block;
    margin: 0 auto;
}

.tree-edge {
    position: absolute;
    background: #cbd5e0;
    height: 3px;
    transform-origin: left center;
    pointer-events: none;
}

.tree-node {
    position: absolute;
    width: var(--node-size);
    height: var(--node-size);
    border-radius: 50%;
    background: #667eea;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: var(--node-font-size);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.14);
    user-select: none;
}

.tree-node:hover {
    transform: scale(1.07);
}

.tree-node.highlight {
    background: #f6ad55;
}

.tree-node.correct {
    background: #38a169;
}

.tree-node.wrong {
    background: #e53e3e;
}

.tree-node.path {
    box-shadow: 0 0 0 5px rgba(246, 173, 85, 0.55);
}

.tree-node.selected-rotation {
    box-shadow: 0 0 0 6px rgba(128, 90, 213, 0.5);
}

.tree-node.placeholder {
    background: white;
    border: 2px dashed #667eea;
    color: #667eea;
    font-size: calc(var(--node-font-size) - 1px);
}

.exercise-panel {
    min-height: 440px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    color: #2d3748;
}

.exercise-block {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
}

.exercise-block h3 {
    margin-bottom: 8px;
    font-size: 1.02em;
}

.radio-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 9px;
    flex-wrap: wrap;
}

.btn-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-row button {
    padding: 8px 12px;
    font-size: 14px;
}

.btn-secondary {
    background: #4a5568;
}

.instructions {
    background: #edf2f7;
    padding: 16px;
    border-radius: 10px;
    border-left: 4px solid #667eea;
}

.instructions h3 {
    color: #2d3748;
    margin-bottom: 8px;
}

.instructions ul {
    list-style-position: inside;
    color: #4a5568;
    line-height: 1.7;
}

@media (max-width: 1080px) {
    .visualization {
        grid-template-columns: 1fr;
    }

    #treeView {
        min-height: 400px;
    }
}
