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

:root {
    --paper-color: #fdfbf7;
    --ink-black: #2d2926;
    --ink-red: #c41e3a;
    --ink-green: #228b22;
    --ink-blue: #1e5aa8;
    --ink-orange: #e67300;
    --ink-purple: #7b2d8e;
    --ui-bg: #1a1a1a;
    --ui-surface: #252525;
    --ui-border: #3a3a3a;
    --ui-text: #e8e4dc;
    --shadow: rgba(0, 0, 0, 0.4);
}

body {
    font-family: 'JetBrains Mono', monospace;
    background: linear-gradient(135deg, #0d0d0d 0%, #1a1a1a 50%, #0d0d0d 100%);
    min-height: 100vh;
    overflow: hidden;
    color: var(--ui-text);
}

#app-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

#toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: var(--ui-bg);
    border-bottom: 1px solid var(--ui-border);
    box-shadow: 0 4px 20px var(--shadow);
    z-index: 100;
    flex-wrap: wrap;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tool-group.colors {
    gap: 4px;
}

.tool-group.thickness {
    gap: 10px;
}

.tool-group.zoom-controls {
    gap: 8px;
    padding: 0 8px;
    border-left: 1px solid var(--ui-border);
    border-right: 1px solid var(--ui-border);
}

#zoom-level {
    font-size: 11px;
    min-width: 40px;
    text-align: center;
    color: var(--ui-text);
    opacity: 0.7;
}

.tool-btn, .action-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    background: var(--ui-surface);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    color: var(--ui-text);
}

.tool-btn svg, .action-btn svg {
    width: 20px;
    height: 20px;
}

.tool-btn:hover, .action-btn:hover {
    background: #333;
    transform: translateY(-1px);
    border-color: #555;
}

.tool-btn.active {
    background: var(--ink-blue);
    color: white;
    border-color: var(--ink-blue);
    box-shadow: 0 0 12px rgba(30, 90, 168, 0.5);
}

.action-btn.small {
    width: 28px;
    height: 28px;
    font-size: 16px;
    font-weight: 700;
}

.action-btn.danger {
    border-color: var(--ink-red);
    color: var(--ink-red);
}

.action-btn.danger:hover {
    background: var(--ink-red);
    color: white;
}

.color-btn {
    width: 28px;
    height: 28px;
    border: 2px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

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

.color-btn.active {
    border-color: white;
    transform: scale(1.1);
    box-shadow: 0 0 8px rgba(255,255,255,0.3), inset 0 2px 4px rgba(0,0,0,0.3);
}

#thickness-slider {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    background: var(--ui-border);
    border-radius: 2px;
    cursor: pointer;
}

#thickness-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--ink-blue);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px var(--shadow);
}

#thickness-value {
    font-size: 11px;
    color: var(--ui-text);
    opacity: 0.7;
    min-width: 35px;
}

#canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--paper-color);
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#paper-roll-left, #paper-roll-right {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 60px;
    pointer-events: none;
    z-index: 10;
}

#paper-roll-left {
    left: 0;
    background: linear-gradient(to right, 
        rgba(60, 50, 40, 0.5) 0%,
        rgba(100, 80, 60, 0.3) 20%,
        rgba(139, 119, 101, 0.15) 50%,
        transparent 100%
    );
    box-shadow: inset 20px 0 30px -10px rgba(0,0,0,0.3);
}

#paper-roll-right {
    right: 0;
    background: linear-gradient(to left, 
        rgba(60, 50, 40, 0.5) 0%,
        rgba(100, 80, 60, 0.3) 20%,
        rgba(139, 119, 101, 0.15) 50%,
        transparent 100%
    );
    box-shadow: inset -20px 0 30px -10px rgba(0,0,0,0.3);
}

#minimap-container {
    position: absolute;
    bottom: 80px;
    right: 20px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    z-index: 50;
}

#minimap-toggle {
    padding: 6px 10px;
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--ui-text);
    cursor: pointer;
    transition: all 0.15s ease;
}

#minimap-toggle:hover {
    background: #333;
}

#minimap {
    width: 200px;
    height: 60px;
    background: var(--paper-color);
    border: 1px solid var(--ui-border);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 4px 16px var(--shadow);
    transition: all 0.3s ease;
}

#minimap.collapsed {
    width: 0;
    border-width: 0;
    opacity: 0;
}

#minimap-canvas {
    width: 100%;
    height: 100%;
}

#minimap-viewport {
    position: absolute;
    top: 0;
    height: 100%;
    background: rgba(30, 90, 168, 0.25);
    border: 2px solid var(--ink-blue);
    border-radius: 3px;
    pointer-events: none;
}

#nav-panel {
    position: absolute;
    bottom: 80px;
    left: 20px;
    display: flex;
    gap: 4px;
    z-index: 50;
}

#nav-panel button {
    width: 36px;
    height: 36px;
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: 6px;
    color: var(--ui-text);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
}

#nav-panel button:hover {
    background: #333;
    transform: translateY(-1px);
}

#scroll-indicator {
    height: 6px;
    background: var(--ui-bg);
    position: relative;
}

#scroll-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--ink-blue), var(--ink-green), var(--ink-orange));
    border-radius: 0 3px 3px 0;
    transition: width 0.1s ease;
}

#milestone-markers {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    pointer-events: none;
}

.milestone-tick {
    position: absolute;
    top: -2px;
    width: 4px;
    height: 10px;
    border-radius: 2px;
    transform: translateX(-50%);
}

#position-display {
    position: absolute;
    bottom: 32px;
    left: 20px;
    font-size: 11px;
    color: rgba(45, 41, 38, 0.8);
    font-family: 'JetBrains Mono', monospace;
    background: var(--paper-color);
    padding: 4px 10px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#distance-metaphor {
    display: block;
    font-family: 'Caveat', cursive;
    font-size: 14px;
    color: var(--ink-blue);
    margin-top: 2px;
}

#journey-stats {
    position: absolute;
    bottom: 32px;
    right: 240px;
    display: flex;
    gap: 16px;
    font-size: 10px;
    color: rgba(45, 41, 38, 0.6);
    font-family: 'JetBrains Mono', monospace;
    background: var(--paper-color);
    padding: 4px 10px;
    border-radius: 4px;
}

#footer {
    padding: 6px 20px;
    background: var(--ui-bg);
    border-top: 1px solid var(--ui-border);
    text-align: center;
    font-size: 11px;
    color: var(--ui-text);
    opacity: 0.7;
}

#footer a {
    color: #ff6b9d;
    text-decoration: none;
}

#footer a:hover {
    text-decoration: underline;
}

/* Milestone Toast */
#milestone-toast {
    position: absolute;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    animation: toastSlide 0.5s ease;
}

#milestone-toast.hidden {
    display: none;
}

#milestone-content {
    padding: 16px 32px;
    border-radius: 50px;
    font-family: 'Caveat', cursive;
    font-size: 24px;
    color: white;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    white-space: nowrap;
}

.milestone-emoji {
    font-size: 28px;
    margin-right: 8px;
}

@keyframes toastSlide {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Encouragement */
#encouragement {
    position: absolute;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Caveat', cursive;
    font-size: 22px;
    color: var(--ink-purple);
    background: rgba(255,255,255,0.9);
    padding: 10px 24px;
    border-radius: 30px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    animation: fadeUp 0.4s ease;
    z-index: 100;
}

#encouragement.hidden {
    display: none;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Confetti */
#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    animation: confettiFall 3s ease-out forwards;
}

@keyframes confettiFall {
    0% {
        top: -10px;
        opacity: 1;
    }
    100% {
        top: 100%;
        opacity: 0;
        transform: rotate(720deg) translateX(100px);
    }
}

/* Modals */
.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: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--paper-color);
    border-radius: 16px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: modalPop 0.2s ease;
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.modal-content p {
    font-family: 'Caveat', cursive;
    font-size: 20px;
    margin-bottom: 20px;
    color: var(--ink-black);
    line-height: 1.4;
}

.modal-content textarea {
    width: 100%;
    min-height: 100px;
    padding: 16px;
    border: 2px solid #d4cbbe;
    border-radius: 12px;
    font-family: 'Caveat', cursive;
    font-size: 20px;
    background: white;
    resize: vertical;
    margin-bottom: 16px;
    color: var(--ink-black);
}

.modal-content textarea:focus {
    outline: none;
    border-color: var(--ink-blue);
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.modal-actions button {
    padding: 10px 20px;
    border: 1px solid #d4cbbe;
    border-radius: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
    background: white;
    color: var(--ink-black);
}

.modal-actions button:hover {
    transform: translateY(-1px);
}

.modal-actions button.danger {
    background: var(--ink-red);
    color: white;
    border-color: var(--ink-red);
}

.modal-actions button#text-confirm {
    background: var(--ink-blue);
    color: white;
    border-color: var(--ink-blue);
}

/* Mobile styles */
@media (max-width: 768px) {
    #toolbar {
        padding: 8px 12px;
        gap: 8px;
    }
    
    .tool-btn, .action-btn {
        width: 36px;
        height: 36px;
    }
    
    .tool-btn svg, .action-btn svg {
        width: 18px;
        height: 18px;
    }
    
    .color-btn {
        width: 24px;
        height: 24px;
    }
    
    .tool-group.thickness,
    .tool-group.zoom-controls {
        display: none;
    }
    
    #minimap-container {
        bottom: 70px;
        right: 10px;
    }
    
    #minimap {
        width: 120px;
        height: 40px;
    }
    
    #nav-panel {
        bottom: 70px;
        left: 10px;
    }
    
    #nav-panel button {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }
    
    #position-display {
        font-size: 10px;
        bottom: 26px;
        left: 10px;
    }
    
    #journey-stats {
        display: none;
    }
    
    #footer {
        padding: 5px 12px;
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    .tool-group.actions {
        position: absolute;
        right: 12px;
    }
    
    #toolbar {
        padding-right: 90px;
    }
    
    .tool-group.colors {
        gap: 3px;
    }
    
    .color-btn {
        width: 22px;
        height: 22px;
    }
}