* {
    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;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    position: relative;
    overflow-x: hidden;
}

/* Animated background elements */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(102, 126, 234, 0.3) 0%, transparent 50%);
    animation: backgroundMove 20s ease-in-out infinite;
    z-index: 0;
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        repeating-linear-gradient(45deg, transparent, transparent 35px, rgba(255,255,255,.03) 35px, rgba(255,255,255,.03) 70px);
    z-index: 0;
}

@keyframes backgroundMove {
    0%, 100% {
        transform: translate(0, 0) rotate(0deg);
    }
    33% {
        transform: translate(30px, -50px) rotate(120deg);
    }
    66% {
        transform: translate(-20px, 20px) rotate(240deg);
    }
}

/* Floating shapes */
.background-shapes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.shape {
    position: absolute;
    opacity: 0.1;
    animation: float 20s infinite ease-in-out;
}

.shape-1 {
    top: 10%;
    left: 10%;
    width: 80px;
    height: 80px;
    background: white;
    border-radius: 50%;
    animation-delay: 0s;
    animation-duration: 25s;
}

.shape-2 {
    top: 60%;
    left: 80%;
    width: 120px;
    height: 120px;
    background: white;
    border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
    animation-delay: 3s;
    animation-duration: 20s;
}

.shape-3 {
    top: 80%;
    left: 20%;
    width: 100px;
    height: 100px;
    background: white;
    border-radius: 50%;
    animation-delay: 6s;
    animation-duration: 30s;
}

.shape-4 {
    top: 20%;
    left: 70%;
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.15);
    transform: rotate(45deg);
    animation-delay: 2s;
    animation-duration: 22s;
}

.shape-5 {
    top: 50%;
    left: 5%;
    width: 90px;
    height: 90px;
    background: white;
    border-radius: 30% 70% 30% 70% / 60% 40% 60% 40%;
    animation-delay: 4s;
    animation-duration: 28s;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0) translateX(0) rotate(0deg);
    }
    33% {
        transform: translateY(-30px) translateX(20px) rotate(120deg);
    }
    66% {
        transform: translateY(20px) translateX(-20px) rotate(240deg);
    }
}

.container {
    width: 100%;
    max-width: 1200px;
    position: relative;
    z-index: 1;
}

h1 {
    color: white;
    text-align: center;
    margin-bottom: 30px;
    font-size: 2.5em;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    position: relative;
    z-index: 1;
}

.controls {
    background: rgba(255, 255, 255, 0.95);
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    margin-bottom: 30px;
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 1;
}

.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

input[type="text"] {
    flex: 1;
    min-width: 200px;
    padding: 12px 18px;
    font-size: 16px;
    border: 2px solid #667eea;
    border-radius: 8px;
    outline: none;
    transition: all 0.3s;
}

input[type="text"]:focus {
    border-color: #764ba2;
    box-shadow: 0 0 0 3px rgba(118, 75, 162, 0.1);
}

button {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    color: white;
}

.btn-insert {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.btn-insert:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-undo {
    background: linear-gradient(135deg, #f093fb, #f5576c);
}

.btn-undo:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(245, 87, 108, 0.4);
}

.btn-clear {
    background: linear-gradient(135deg, #4facfe, #00f2fe);
}

.btn-clear:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(79, 172, 254, 0.4);
}

.btn-log {
    background: linear-gradient(135deg, #ffecd2, #fcb69f);
    color: #764ba2;
}

.btn-log:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(252, 182, 159, 0.4);
}

button:active {
    transform: translateY(0);
}

.canvas-container {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 50%, #e0c3fc 100%);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    overflow: auto;
    position: relative;
    z-index: 1;
}

#treeCanvas {
    display: block;
    margin: 0 auto;
    background: transparent;
}

.status {
    text-align: center;
    color: #667eea;
    margin-top: 15px;
    font-size: 14px;
    min-height: 20px;
}

/* Side Panel for Operation Log */
.log-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    box-shadow: -5px 0 20px rgba(0,0,0,0.3);
    z-index: 1000;
    transition: right 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    display: flex;
    flex-direction: column;
}

.log-panel.open {
    right: 0;
}

.log-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid rgba(118, 75, 162, 0.2);
}

.log-panel-header h3 {
    color: #764ba2;
    margin: 0;
    font-size: 1.3em;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.5);
}

.close-btn {
    background: rgba(245, 87, 108, 0.2);
    color: #f5576c;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    padding: 0;
    transition: all 0.3s;
}

.close-btn:hover {
    background: #f5576c;
    color: white;
    transform: rotate(90deg);
}

.log-panel-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.log-entry {
    padding: 10px 15px;
    margin-bottom: 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.7);
    border-left: 4px solid #667eea;
    animation: slideInLog 0.3s ease-out;
    backdrop-filter: blur(10px);
}

.log-entry.rotation {
    border-left-color: #f5576c;
}

.log-entry.insert {
    border-left-color: #4facfe;
}

.log-entry.complete {
    border-left-color: #50c878;
}

.log-entry strong {
    color: #667eea;
}

.log-entry .rotation-type {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(245, 87, 108, 0.2);
    border-radius: 4px;
    font-weight: bold;
    color: #f5576c;
    margin: 0 4px;
}

@keyframes slideInLog {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.rotation-diagram {
    margin-top: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 6px;
    font-family: monospace;
    font-size: 12px;
    color: #666;
    line-height: 1.6;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

/* Responsive */
@media (max-width: 768px) {
    .log-panel {
        width: 100%;
        right: -100%;
    }
}