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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    background: #1a1a2e;
}

#app {
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* Toolbar wrapper for scrollbar */
#toolbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 72px;
    background: linear-gradient(180deg, #2d2d44 0%, #1f1f35 100%);
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    overflow: visible;
}

#toolbar-scroll {
    width: 100%;
    height: 100%;
    overflow: visible;
    -webkit-overflow-scrolling: touch;
}

#toolbar-inner {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
    height: 60px;
    white-space: nowrap;
    width: 100%;
    justify-content: center;
}

/* Visible scrollbar */
#toolbar-scroll::-webkit-scrollbar {
    height: 12px;
}

#toolbar-scroll::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.4);
}

#toolbar-scroll::-webkit-scrollbar-thumb {
    background: #4ade80;
    border-radius: 6px;
    border: 2px solid rgba(0,0,0,0.4);
}

#toolbar-scroll::-webkit-scrollbar-thumb:hover {
    background: #22c55e;
}

/* Firefox scrollbar */
#toolbar-scroll {
    scrollbar-width: auto;
    scrollbar-color: #4ade80 rgba(0,0,0,0.4);
}

.toolbar-section {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.toolbar-section.tools {
    flex: 0 0 auto;
}

.toolbar-section.actions {
    flex: 0 0 auto;
}

.toolbar-title {
    font-size: 18px;
    font-weight: bold;
    color: #4ade80;
    text-shadow: 0 0 10px rgba(74, 222, 128, 0.3);
}

.tool-btn, .action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(255,255,255,0.1);
    color: #fff;
    min-width: 60px;
}

.tool-btn .icon, .action-btn .icon {
    font-size: 18px;
    margin-bottom: 2px;
}

.tool-btn .label, .action-btn .label {
    font-size: 10px;
    opacity: 0.8;
}

.tool-btn:hover, .action-btn:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

.tool-btn.active {
    background: #4ade80;
    color: #1a1a2e;
}

.action-btn.play {
    background: #4ade80;
    color: #1a1a2e;
}

.action-btn.play:hover {
    background: #22c55e;
}

.action-btn.danger:hover {
    background: #ef4444;
}

/* Tool Dropdowns */
.tool-dropdown {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

.dropdown-trigger {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(255,255,255,0.1);
    color: #fff;
    min-width: 60px;
}

.dropdown-trigger .icon {
    font-size: 18px;
    margin-bottom: 2px;
}

.dropdown-trigger .label {
    font-size: 10px;
    opacity: 0.8;
}

.dropdown-trigger:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

.dropdown-trigger.has-active {
    background: rgba(74, 222, 128, 0.3);
    border: 1px solid #4ade80;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 6px;
    background: linear-gradient(180deg, #2d2d44 0%, #1f1f35 100%);
    border-radius: 10px;
    padding: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 200;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    min-width: 180px;
}

.tool-dropdown.open .dropdown-menu {
    display: grid;
}

.dropdown-menu .tool-btn {
    min-width: unset;
    padding: 8px 6px;
    font-size: 10px;
}

.dropdown-menu .tool-btn .icon {
    font-size: 20px;
}

.dropdown-menu .tool-btn .label {
    font-size: 9px;
}

.tool-divider {
    width: 1px;
    height: 40px;
    background: rgba(255,255,255,0.2);
    margin: 0 5px;
}

/* Properties Panel */
#properties-panel {
    position: absolute;
    top: 70px;
    right: 10px;
    width: 220px;
    background: rgba(30, 30, 50, 0.95);
    border-radius: 12px;
    padding: 15px;
    z-index: 90;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    color: #fff;
}

#properties-panel h3 {
    font-size: 14px;
    color: #4ade80;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

#no-selection p {
    color: rgba(255,255,255,0.5);
    font-size: 12px;
    text-align: center;
    padding: 20px 0;
}

.property-group {
    margin-bottom: 15px;
}

.property-group label {
    display: block;
    font-size: 11px;
    color: rgba(255,255,255,0.6);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.property-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.property-row span {
    font-size: 12px;
    color: rgba(255,255,255,0.7);
    min-width: 45px;
}

.property-row input[type="number"] {
    flex: 1;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    padding: 6px 8px;
    color: #fff;
    font-size: 12px;
    width: 80px;
}

.property-row input[type="number"]:focus {
    outline: none;
    border-color: #4ade80;
}

.property-row input[type="color"] {
    flex: 1;
    height: 32px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}

/* Canvas Container */
#canvas-container {
    position: absolute;
    top: 72px;
    left: 0;
    right: 0;
    bottom: 0;
    /* Prevent iOS bounce/scroll behavior */
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#canvas-container canvas {
    display: block;
    /* Prevent touch-action issues on the canvas */
    touch-action: none;
}

/* Play Mode UI */
#play-ui {
    position: absolute;
    top: 70px;
    left: 10px;
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#stroke-counter {
    background: rgba(30, 30, 50, 0.95);
    padding: 12px 20px;
    border-radius: 8px;
    color: #fff;
    font-size: 18px;
    font-weight: bold;
}

#stroke-counter span {
    color: #4ade80;
}

#power-indicator {
    width: 200px;
    height: 20px;
    background: rgba(30, 30, 50, 0.95);
    border-radius: 10px;
    overflow: hidden;
    display: none;
}

#power-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4ade80, #fbbf24, #ef4444);
    transition: width 0.05s ease;
}

#play-ui .action-btn {
    flex-direction: row;
    gap: 8px;
    padding: 10px 15px;
}

/* Instructions */
#instructions {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(30, 30, 50, 0.9);
    padding: 12px 15px;
    border-radius: 8px;
    color: rgba(255,255,255,0.7);
    font-size: 11px;
    z-index: 90;
    max-width: 280px;
}

#instructions h4 {
    color: #4ade80;
    margin-bottom: 8px;
    font-size: 12px;
}

#instructions p {
    margin-bottom: 4px;
    line-height: 1.4;
}

#instructions .handle-legend {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
    margin-top: 4px;
}

#instructions .handle-legend span {
    display: inline-block;
}

.handle-green, .handle-yellow, .handle-blue, .handle-pink {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 2px;
}

.handle-green {
    background: #4ade80;
}

.handle-yellow {
    background: #fbbf24;
    margin-left: 8px;
}

.handle-blue {
    background: #60a5fa;
    margin-left: 8px;
}

.handle-pink {
    background: #f472b6;
    margin-left: 8px;
}

/* Win Modal */
#win-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-content {
    background: linear-gradient(180deg, #2d2d44 0%, #1f1f35 100%);
    padding: 40px 50px;
    border-radius: 16px;
    text-align: center;
    color: #fff;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.modal-content h2 {
    font-size: 32px;
    margin-bottom: 15px;
    color: #4ade80;
}

.modal-content p {
    margin-bottom: 25px;
    color: rgba(255,255,255,0.7);
}

.modal-content button {
    padding: 12px 25px;
    margin: 0 8px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

#btn-play-again {
    background: #4ade80;
    color: #1a1a2e;
}

#btn-back-edit {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.modal-content button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

/* Responsive adjustments */
@media (max-width: 900px) {
    .tool-btn .label, .action-btn .label, .dropdown-trigger .label {
        display: none;
    }

    .tool-btn, .action-btn {
        min-width: 45px;
        padding: 8px;
    }

    .dropdown-trigger {
        min-width: 45px;
        padding: 8px;
    }

    .dropdown-menu .tool-btn .label {
        display: block;
    }

    #properties-panel {
        width: 180px;
    }
}

@media (max-width: 600px) {
    #canvas-container {
        top: 72px;
    }

    #properties-panel {
        display: none;
    }
}
