* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Theme Variables */
[data-theme="ice-pink"] {
    --bg-color: #f0e6ef;
    --bg-gradient-1: #f5eaf4;
    --bg-gradient-2: #e8dce7;
    --accent: #f48fb1;
    --accent-bright: #ec407a;
    --shadow-light: #ffffff;
    --shadow-dark: #d4c4d3;
    --text-color: #6d4c6d;
    --line-color: #f48fb1;
}

[data-theme="ice-blue"] {
    --bg-color: #e3edf7;
    --bg-gradient-1: #e8f1fa;
    --bg-gradient-2: #dce6f0;
    --accent: #64b5f6;
    --accent-bright: #1e88e5;
    --shadow-light: #ffffff;
    --shadow-dark: #c5d4e3;
    --text-color: #4a6785;
    --line-color: #64b5f6;
}

[data-theme="mint"] {
    --bg-color: #e0f2ef;
    --bg-gradient-1: #e5f5f2;
    --bg-gradient-2: #d5ebe7;
    --accent: #4db6ac;
    --accent-bright: #00897b;
    --shadow-light: #ffffff;
    --shadow-dark: #c2d9d5;
    --text-color: #3d6b65;
    --line-color: #4db6ac;
}

[data-theme="lavender"] {
    --bg-color: #ebe4f3;
    --bg-gradient-1: #f0e9f7;
    --bg-gradient-2: #e2d9ed;
    --accent: #b39ddb;
    --accent-bright: #7e57c2;
    --shadow-light: #ffffff;
    --shadow-dark: #cfc5da;
    --text-color: #5e4a7d;
    --line-color: #b39ddb;
}

[data-theme="peach"] {
    --bg-color: #f5ebe0;
    --bg-gradient-1: #f9f0e6;
    --bg-gradient-2: #efe4d8;
    --accent: #ffab91;
    --accent-bright: #ff7043;
    --shadow-light: #ffffff;
    --shadow-dark: #ddd1c4;
    --text-color: #7d5a4f;
    --line-color: #ffab91;
}

[data-theme="slate"] {
    --bg-color: #e0e5ec;
    --bg-gradient-1: #e6ebf2;
    --bg-gradient-2: #d8dde4;
    --accent: #90a4ae;
    --accent-bright: #546e7a;
    --shadow-light: #ffffff;
    --shadow-dark: #a3b1c6;
    --text-color: #4a5568;
    --line-color: #90a4ae;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(145deg, var(--bg-gradient-1), var(--bg-gradient-2));
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    touch-action: none;
}

html {
    height: -webkit-fill-available;
}

/* Mobile Menu Toggle */
.menu-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    width: 48px;
    height: 48px;
    padding: 0;
    z-index: 1001;
    align-items: center;
    justify-content: center;
}

.menu-icon {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-color);
    position: relative;
    transition: all 0.3s ease;
}

.menu-icon::before,
.menu-icon::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background: var(--text-color);
    left: 0;
    transition: all 0.3s ease;
}

.menu-icon::before { top: -6px; }
.menu-icon::after { top: 6px; }

.menu-toggle.active .menu-icon {
    background: transparent;
}

.menu-toggle.active .menu-icon::before {
    transform: rotate(45deg);
    top: 0;
}

.menu-toggle.active .menu-icon::after {
    transform: rotate(-45deg);
    top: 0;
}

/* Toolbar */
.toolbar {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg-color);
    border-radius: 20px;
    box-shadow:
        8px 8px 16px var(--shadow-dark),
        -8px -8px 16px var(--shadow-light);
    z-index: 1000;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.toolbar.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.toolbar.dragging {
    cursor: grabbing;
    transition: none;
}

.toolbar.custom-position {
    transform: none !important;
    left: auto !important;
    top: auto !important;
}

/* Drag Handle */
.drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 30px;
    cursor: grab;
    margin-right: 4px;
}

.drag-handle:active {
    cursor: grabbing;
}

/* Toggle Button */
.toggle-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.toggle-icon {
    display: block;
    width: 16px;
    height: 16px;
    position: relative;
}

.toggle-icon::before,
.toggle-icon::after {
    content: '';
    position: absolute;
    left: 50%;
    width: 16px;
    height: 2px;
    background: var(--text-color);
    border-radius: 1px;
    transition: all 0.3s ease;
    transform-origin: center;
    transform: translateX(-50%);
}

.toggle-icon::before {
    top: 2px;
}

.toggle-icon::after {
    bottom: 2px;
}

.toggle-btn.active .toggle-icon::before {
    top: 50%;
    transform: translateX(-50%) translateY(-50%) rotate(45deg);
}

.toggle-btn.active .toggle-icon::after {
    bottom: auto;
    top: 50%;
    transform: translateX(-50%) translateY(-50%) rotate(-45deg);
}

.drag-dots {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.drag-dots::before,
.drag-dots::after {
    content: '';
    display: block;
    width: 12px;
    height: 3px;
    background: var(--shadow-dark);
    border-radius: 2px;
}

.toolbar-row {
    display: flex;
    gap: 10px;
}

.toolbar-divider {
    width: 2px;
    height: 30px;
    background: var(--shadow-dark);
    border-radius: 1px;
}

.neo-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 12px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow:
        4px 4px 8px var(--shadow-dark),
        -4px -4px 8px var(--shadow-light);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-icon {
    display: none;
    font-weight: 700;
    font-size: 16px;
}

.neo-btn:hover {
    color: var(--accent-bright);
}

.neo-btn:active,
.neo-btn.active {
    box-shadow:
        inset 4px 4px 8px var(--shadow-dark),
        inset -4px -4px 8px var(--shadow-light);
    color: var(--accent-bright);
}

/* Bottom Bar */
.bottom-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 12px 20px;
    background: var(--bg-color);
    border-radius: 20px;
    box-shadow:
        8px 8px 16px var(--shadow-dark),
        -8px -8px 16px var(--shadow-light);
    z-index: 1000;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.bottom-bar.dragging {
    cursor: grabbing;
    transition: none;
}

.bottom-bar.custom-position {
    transform: none !important;
    left: auto !important;
    bottom: auto !important;
}

/* Zoom Controls */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.zoom-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
}

.reset-btn {
    width: auto;
    padding: 0 12px;
    font-size: 12px;
}

.zoom-level {
    color: var(--text-color);
    font-size: 12px;
    font-weight: 600;
    min-width: 45px;
    text-align: center;
}

/* Color Picker */
.color-picker {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow:
        3px 3px 6px var(--shadow-dark),
        -3px -3px 6px var(--shadow-light);
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    box-shadow:
        inset 2px 2px 4px rgba(0,0,0,0.2),
        0 0 0 3px var(--bg-color),
        0 0 0 5px var(--accent);
}

.color-btn[data-theme="ice-pink"] { background: #f48fb1; }
.color-btn[data-theme="ice-blue"] { background: #64b5f6; }
.color-btn[data-theme="mint"] { background: #4db6ac; }
.color-btn[data-theme="lavender"] { background: #b39ddb; }
.color-btn[data-theme="peach"] { background: #ffab91; }
.color-btn[data-theme="slate"] { background: #78909c; }

/* Help Button */
.help-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-color);
}

.help-btn:hover {
    color: var(--accent-bright);
}

.help-icon {
    display: block;
    line-height: 1;
}

/* Pan Toggle (Mobile) */
.pan-toggle {
    display: none;
    position: fixed;
    top: 15px;
    right: 15px;
    width: 48px;
    height: 48px;
    padding: 0;
    z-index: 1001;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.pan-icon {
    display: block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--text-color);
    border-radius: 4px;
    position: relative;
}

.pan-icon::before,
.pan-icon::after {
    content: '';
    position: absolute;
    background: var(--text-color);
}

.pan-icon::before {
    width: 8px;
    height: 2px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.pan-icon::after {
    width: 2px;
    height: 8px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.pan-toggle.active .pan-icon {
    border-color: var(--accent-bright);
    background: var(--accent-bright);
    opacity: 0.2;
}

.pan-toggle.active .pan-icon::before,
.pan-toggle.active .pan-icon::after {
    background: var(--accent-bright);
}

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

/* Canvas Container */
.canvas-container {
    width: 100vw;
    height: 100vh;
    height: -webkit-fill-available;
    position: fixed;
    top: 0;
    left: 0;
    cursor: default;
    overflow: hidden;
}

.canvas-container.panning {
    cursor: grabbing;
}

.canvas-container.can-pan {
    cursor: grab;
}

/* Canvas */
.canvas {
    width: 6000px;
    height: 6000px;
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
}

#connections {
    position: absolute;
    top: 0;
    left: 0;
    width: 6000px;
    height: 6000px;
    pointer-events: none;
    z-index: 1;
    overflow: visible;
}

#connections line {
    stroke: var(--line-color);
    stroke-width: 3;
    stroke-linecap: round;
}

#connections line.temp-line {
    stroke: var(--accent-bright);
    stroke-dasharray: 8, 4;
    opacity: 0.7;
}

/* Nodes */
.node {
    position: absolute;
    min-width: 100px;
    max-width: 180px;
    padding: 16px 20px;
    background: var(--bg-color);
    border-radius: 16px;
    cursor: grab;
    z-index: 10;
    box-shadow:
        8px 8px 16px var(--shadow-dark),
        -8px -8px 16px var(--shadow-light);
    transition: box-shadow 0.2s ease, transform 0.1s ease;
    touch-action: none;
}

.node:hover {
    box-shadow:
        10px 10px 20px var(--shadow-dark),
        -10px -10px 20px var(--shadow-light);
}

.node.dragging {
    cursor: grabbing;
    z-index: 100;
    box-shadow:
        12px 12px 24px var(--shadow-dark),
        -12px -12px 24px var(--shadow-light);
    transform: scale(1.02);
}

.node.selected {
    box-shadow:
        inset 4px 4px 8px var(--shadow-dark),
        inset -4px -4px 8px var(--shadow-light),
        0 0 0 3px var(--accent-bright);
}

.node.connect-source {
    box-shadow:
        8px 8px 16px var(--shadow-dark),
        -8px -8px 16px var(--shadow-light),
        0 0 0 4px var(--accent-bright),
        0 0 20px var(--accent);
}

.node.delete-hover {
    box-shadow:
        8px 8px 16px var(--shadow-dark),
        -8px -8px 16px var(--shadow-light),
        0 0 0 3px #e57373;
    opacity: 0.8;
}

.node-content {
    color: var(--text-color);
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    outline: none;
    min-height: 20px;
    word-wrap: break-word;
    -webkit-user-select: text;
    user-select: text;
}

.node-content:focus {
    border-bottom: 2px solid var(--accent-bright);
}

/* Image Nodes */
.image-node {
    position: absolute;
    padding: 8px;
    background: var(--bg-color);
    border-radius: 16px;
    cursor: grab;
    z-index: 10;
    box-shadow:
        8px 8px 16px var(--shadow-dark),
        -8px -8px 16px var(--shadow-light);
    transition: box-shadow 0.2s ease;
    touch-action: none;
    min-width: 80px;
    min-height: 80px;
}

.image-node:hover {
    box-shadow:
        10px 10px 20px var(--shadow-dark),
        -10px -10px 20px var(--shadow-light);
}

.image-node.dragging {
    cursor: grabbing;
    z-index: 100;
    box-shadow:
        12px 12px 24px var(--shadow-dark),
        -12px -12px 24px var(--shadow-light);
}

.image-node.connect-source {
    box-shadow:
        8px 8px 16px var(--shadow-dark),
        -8px -8px 16px var(--shadow-light),
        0 0 0 4px var(--accent-bright),
        0 0 20px var(--accent);
}

.image-node.delete-hover {
    box-shadow:
        8px 8px 16px var(--shadow-dark),
        -8px -8px 16px var(--shadow-light),
        0 0 0 3px #e57373;
    opacity: 0.8;
}

.image-node img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 10px;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

.image-node .resize-handle {
    position: absolute;
    width: 16px;
    height: 16px;
    background: var(--bg-color);
    border: 2px solid var(--accent);
    border-radius: 4px;
    cursor: nwse-resize;
    z-index: 20;
    opacity: 0;
    transition: opacity 0.2s ease;
    box-shadow:
        2px 2px 4px var(--shadow-dark),
        -2px -2px 4px var(--shadow-light);
}

.image-node:hover .resize-handle,
.image-node.resizing .resize-handle {
    opacity: 1;
}

.image-node .resize-handle.se {
    bottom: -8px;
    right: -8px;
    cursor: nwse-resize;
}

.image-node .resize-handle.sw {
    bottom: -8px;
    left: -8px;
    cursor: nesw-resize;
}

.image-node .resize-handle.ne {
    top: -8px;
    right: -8px;
    cursor: nesw-resize;
}

.image-node .resize-handle.nw {
    top: -8px;
    left: -8px;
    cursor: nwse-resize;
}

.image-node.resizing {
    transition: none;
}

body.delete-mode .image-node {
    cursor: not-allowed;
}

body.connect-mode .image-node {
    cursor: crosshair;
}

.image-node.new {
    animation: nodeAppear 0.3s ease-out;
}

/* Instructions */
.instructions {
    position: fixed;
    bottom: 90px;
    right: 20px;
    padding: 12px 15px;
    background: var(--bg-color);
    border-radius: 16px;
    box-shadow:
        6px 6px 12px var(--shadow-dark),
        -6px -6px 12px var(--shadow-light);
    z-index: 1001;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.instructions.custom-position {
    bottom: auto;
    right: auto;
}

.instructions-content p {
    color: var(--text-color);
    font-size: 11px;
    margin-bottom: 5px;
}

.instructions-content p:last-child {
    margin-bottom: 0;
}

.instructions strong {
    color: var(--accent-bright);
}

/* Delete mode cursor */
body.delete-mode .node {
    cursor: not-allowed;
}

body.delete-mode .node-content {
    user-select: none;
    -webkit-user-select: none;
}

/* Connect mode cursor */
body.connect-mode .node {
    cursor: crosshair;
}

body.connect-mode .node-content {
    user-select: none;
    -webkit-user-select: none;
}

/* Animation for new nodes */
@keyframes nodeAppear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.node.new {
    animation: nodeAppear 0.3s ease-out;
}

/* Save indicator */
.save-indicator {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    background: var(--bg-color);
    color: var(--accent-bright);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    box-shadow:
        4px 4px 8px var(--shadow-dark),
        -4px -4px 8px var(--shadow-light);
    z-index: 1002;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.save-indicator.show {
    opacity: 1;
}

/* ==================== RESPONSIVE STYLES ==================== */

/* Large screens - toolbar always visible */
@media (min-width: 901px) {
    .menu-toggle,
    .pan-toggle {
        display: none !important;
    }

    .toolbar {
        display: flex !important;
    }

    .toolbar:not(.custom-position) {
        transform: translateX(-50%);
    }
}

/* Tablet - slightly smaller buttons */
@media (max-width: 900px) and (min-width: 751px) {
    .menu-toggle,
    .pan-toggle {
        display: none !important;
    }

    .toolbar {
        padding: 10px 15px;
        gap: 10px;
    }

    .toolbar-row {
        gap: 8px;
    }

    .neo-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    .instructions {
        display: none;
    }

    .bottom-bar {
        padding: 10px 15px;
        gap: 15px;
    }
}

/* Breakpoint where toolbar needs to collapse */
@media (max-width: 750px) {
    /* Show mobile controls */
    .menu-toggle,
    .pan-toggle {
        display: flex;
    }

    /* Make pan button more touch-friendly */
    .pan-toggle {
        width: 52px;
        height: 52px;
        top: 12px;
        right: 12px;
    }

    .pan-icon {
        width: 20px;
        height: 20px;
        border: 2.5px solid var(--text-color);
    }

    .pan-icon::before {
        width: 10px;
        height: 2.5px;
    }

    .pan-icon::after {
        width: 2.5px;
        height: 10px;
    }

    /* Nodes - responsive sizing for tablets/mobile */
    .node {
        min-width: 90px;
        max-width: 150px;
        padding: 14px 16px;
    }

    .node-content {
        font-size: 13px;
    }

    /* Toolbar becomes slide-out menu */
    .toolbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: auto;
        transform: translateY(-100%);
        border-radius: 0 0 20px 20px;
        flex-direction: column;
        padding: 70px 20px 20px;
        gap: 15px;
        transition: transform 0.3s ease;
    }

    .toolbar.open {
        transform: translateY(0);
    }

    .toolbar-row {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .toolbar-divider {
        width: 100%;
        height: 2px;
    }

    .neo-btn {
        padding: 12px 16px;
        justify-content: center;
    }

    .btn-icon {
        display: none;
    }

    .btn-text {
        display: block;
    }

    .instructions {
        display: none;
    }

    /* Bottom bar adjustments */
    .bottom-bar {
        left: 15px;
        right: 15px;
        bottom: 15px;
        transform: none;
        padding: 10px 15px;
        gap: 12px;
        justify-content: space-between;
        flex-wrap: nowrap;
    }

    .bottom-bar .drag-handle {
        display: none;
    }

    .zoom-controls {
        gap: 6px;
    }

    .zoom-btn {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }

    .zoom-level {
        min-width: 42px;
        font-size: 11px;
    }

    .color-picker {
        gap: 6px;
    }

    .color-btn {
        width: 26px;
        height: 26px;
    }

    .help-btn {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }

    /* Instructions positioning */
    .instructions {
        right: 15px;
        bottom: 75px;
    }

    /* Save indicator */
    .save-indicator {
        top: auto;
        bottom: 85px;
    }
}

/* Small phones */
@media (max-width: 500px) {
    .bottom-bar {
        left: 10px;
        right: 10px;
        bottom: 10px;
        padding: 10px 12px;
        gap: 10px;
    }

    .zoom-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .reset-btn {
        display: none;
    }

    .zoom-level {
        min-width: 40px;
        font-size: 11px;
    }

    .color-btn {
        width: 24px;
        height: 24px;
    }

    .color-picker {
        gap: 5px;
    }

    .help-btn {
        width: 32px;
        height: 32px;
        font-size: 15px;
    }

    /* Nodes */
    .node {
        min-width: 80px;
        max-width: 140px;
        padding: 12px 14px;
    }

    .node-content {
        font-size: 12px;
    }

    .save-indicator {
        bottom: 75px;
    }

    .instructions {
        right: 10px;
        bottom: 65px;
        font-size: 10px;
    }
}

/* Very small phones */
@media (max-width: 380px) {
    .bottom-bar {
        padding: 8px 10px;
        gap: 8px;
    }

    .zoom-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .zoom-level {
        min-width: 35px;
        font-size: 10px;
    }

    .color-btn {
        width: 22px;
        height: 22px;
    }

    .color-picker {
        gap: 4px;
    }

    /* Nodes - extra small */
    .node {
        min-width: 70px;
        max-width: 120px;
        padding: 10px 12px;
    }

    .node-content {
        font-size: 11px;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .toolbar {
        padding: 60px 20px 15px;
    }

    .toolbar-row {
        gap: 15px;
    }

    .bottom-bar {
        bottom: 8px;
        padding: 8px 12px;
    }

    .menu-toggle,
    .pan-toggle {
        width: 40px;
        height: 40px;
        top: 10px;
    }

    .menu-toggle {
        left: 10px;
    }

    .pan-toggle {
        right: 10px;
    }
}
