#scale-length-header-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}
.scale-length-group {
    margin-left: 0;
}
#scale-length-controls .control-row {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: 0;
}
/* Scale Length Section */
#scale-length-section {
    margin-bottom: 20px;
}
.scale-length-group {
    margin-top: 10px;
}
#scale-length-controls .control-row {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}
#scale-length-controls label {
    min-width: 100px;
}
#scale-length-controls input[type="number"] {
    width: 80px;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
}
/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    overflow-x: hidden;
    /* iOS-specific: smooth scrolling */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
}

/* iOS Safari safe area support */
@supports (padding: max(0px)) {
    body {
        padding-top: max(0px, env(safe-area-inset-top));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
header {
    background: #000000;
    color: white;
    padding: 1rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: transform 0.3s ease-in-out;
}

/* Auto-hide header on mobile */
header.header-hidden {
    transform: translateY(-100%);
}

/* Header toggle button for mobile */
.header-toggle-btn {
    display: none;
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    width: 44px;
    height: 44px;
    background: #000000;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    font-size: 20px;
    transition: all 0.3s ease;
    align-items: center;
    justify-content: center;
}

.header-toggle-btn:active {
    transform: translateX(-50%) scale(0.95);
    background: #333333;
}

/* Show toggle button only on mobile when header is hidden */
body.mobile.header-collapsed .header-toggle-btn {
    display: flex;
}

/* Debug display for mobile touch events - DISABLED */
/*
#touch-debug {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: #0f0;
    padding: 10px;
    border-radius: 5px;
    font-family: monospace;
    font-size: 11px;
    z-index: 9999;
    max-width: 200px;
    display: none;
}

body.mobile #touch-debug {
    display: block;
}
*/

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 300;
}

header h1 i {
    margin-right: 10px;
    color: #f39c12;
}

nav ul {
    display: flex;
    list-style: none;
    gap: 2rem;
}

nav a {
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: background-color 0.3s;
}

nav a:hover,
nav a.active {
    background-color: rgba(255,255,255,0.2);
}

/* Main Layout */
main {
    display: flex;
    gap: 20px;
    padding: 0;
    height: calc(100vh - 90px);
    overflow: hidden;
    transition: margin-top 0.3s ease-in-out, height 0.3s ease-in-out;
}

/* Adjust main when header is hidden on mobile */
body.header-collapsed main {
    margin-top: -90px;
    height: 100vh;
}

/* Control Panel */
.control-panel {
    width: 350px;
    min-width: 350px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    height: 100%;
    overflow-y: auto;
}

/* Custom Scrollbar for Control Panel */
.control-panel::-webkit-scrollbar {
    width: 8px;
}

.control-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.control-panel::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.control-panel::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.panel-section {
    padding: 20px;
    border-bottom: 1px solid #eee;
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-section h3 {
    color: #000000;
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-section h3 i {
    color: #00AE42;
}

.panel-section h3 .add-all-btn {
    margin-left: auto;
}

.add-all-btn {
    padding: 6px 14px;
    font-size: 0.85rem;
    background: #00AE42;
    color: white;
    border: 1px solid #00AE42;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
    white-space: nowrap;
}

.add-all-btn:hover:not(:disabled) {
    background: #008A33;
    border-color: #008A33;
    transform: translateY(-1px);
}

.add-all-btn:disabled {
    background: #ccc;
    border-color: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

/* File Upload */
.file-upload {
    text-align: center;
}

.upload-btn {
    display: block;
    width: 100%;
    padding: 10px 20px;
    background: linear-gradient(135deg, #00AE42, #008A33);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    border: none;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    box-sizing: border-box;
}

.upload-btn:hover {
    background: linear-gradient(135deg, #008A33, #00AE42);
    transform: translateY(-2px);
}

.upload-btn i {
    margin-right: 8px;
}

.file-info {
    margin-top: 10px;
    padding: 8px;
    background: #d4edda;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #000000;
    display: none;
}

.outline-dimensions {
    margin-top: 6px;
    padding: 8px;
    background: #d4edda;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #333;
    line-height: 1.6;
}

/* Form Controls */
select, input[type="number"], input[type="text"], input[type="range"] {
    width: 100%;
    margin: 0;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.3s;
}

select:focus, input[type="number"]:focus, input[type="text"]:focus {
    outline: none;
    border-color: #00AE42;
    box-shadow: 0 0 0 2px rgba(0, 174, 66, 0.2);
}

input[type="color"] {
    width: 50px;
    height: 35px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

input[type="checkbox"] {
    margin-right: 8px;
    transform: scale(1.2);
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

/* Reference Controls */
.reference-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.reference-controls select {
    flex: 1;
    min-width: 0;
}

.reference-controls button {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    width: auto;
    flex-shrink: 0;
    background: #00AE42;
    color: white;
    border: 2px solid #00AE42;
}

.reference-controls button:hover:not(:disabled) {
    background: #008A33;
    border-color: #008A33;
}

.reference-controls button:disabled {
    background: #ccc;
    border-color: #ccc;
    cursor: not-allowed;
}

/* Brace Groups */
.brace-group {
    margin-bottom: 0;
    border: 1px solid #e8e8e8;
    border-radius: 6px;
    overflow: hidden;
}

.brace-group + .brace-group {
    margin-top: 20px;
}

.brace-group h4 {
    background: #f8f9fa;
    padding: 12px 15px;
    margin: 0;
    font-size: 1rem;
    color: #000000;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.3s;
}

.brace-group h4:hover {
    background: #e9ecef;
}

.brace-controls {
    padding: 15px;
    display: none;
}

.brace-group h4 input[type="checkbox"]:checked + .brace-controls,
.brace-group h4 input[type="checkbox"]:checked ~ .brace-controls {
    display: block;
}

.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.control-row:last-child {
    margin-bottom: 0;
}

.control-row label {
    margin-bottom: 0;
    margin-right: 10px;
    min-width: 120px;
    flex-shrink: 0;
}

.control-row input,
.control-row select {
    flex: 1;
    min-width: 80px;
}

/* Hide native number input spinner arrows (replaced by +/- buttons) */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

.value-display {
    min-width: 50px;
    text-align: right;
    font-weight: 500;
    color: #00AE42;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
    text-align: center;
    width: 100%;
    margin-bottom: 10px;
}

.btn:last-child {
    margin-bottom: 0;
}

.btn-primary {
    background: linear-gradient(135deg, #00AE42, #008A33);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #008A33, #00AE42);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 174, 66, 0.3);
}

.btn-secondary {
    background: linear-gradient(135deg, #95a5a6, #bdc3c7);
    color: white;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #bdc3c7, #95a5a6);
    transform: translateY(-2px);
}

.btn i {
    margin-right: 8px;
}

/* Configuration Controls */
.config-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.config-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, #00AE42, #008A33);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
    width: 100%;
}

.config-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #008A33, #00AE42);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 174, 66, 0.3);
}

.config-btn:disabled {
    background: linear-gradient(135deg, #ccc, #aaa);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 0.6;
}

.config-btn i {
    font-size: 0.9em;
}

.config-info {
    font-size: 0.8em;
    color: #666;
    margin-top: 4px;
    padding: 4px;
    background: #f9f9f9;
    border-radius: 3px;
    display: none;
}

.config-info.show {
    display: block;
}

.config-info.success {
    background: #d4edda;
    color: #155724;
    border-left: 3px solid #28a745;
}

.config-info.error {
    background: #f8d7da;
    color: #721c24;
    border-left: 3px solid #dc3545;
}

/* Drawing Area */
.drawing-area {
    flex: 1;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100%;
    touch-action: none; /* Disable default touch behaviors */
    -webkit-user-select: none;
    user-select: none;
    overscroll-behavior: none;
}

.canvas-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.toolbar-btn {
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    color: #555;
    font-size: 14px;
    transition: all 0.3s;
}

.toolbar-btn:hover {
    background: #e9ecef;
    border-color: #ccc;
}

.toolbar-btn.active,
.view-btn.active {
    background: #00AE42;
    color: white;
    border-color: #00AE42;
}

.zoom-level {
    font-weight: 500;
    color: #666;
    min-width: 50px;
    text-align: center;
}

.zoom-input {
    width: 50px;
    padding: 4px 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    color: #666;
    background: #f8f9fa;
}

.zoom-input:focus {
    outline: none;
    border-color: #00AE42;
    background: #fff;
}

.zoom-percent {
    font-weight: 500;
    color: #666;
    margin-left: 2px;
}

/* Canvas */
.canvas-container {
    flex: 1;
    overflow: visible; /* Allow zoomed SVG to extend beyond container for proper panning */
    position: relative;
    background: #fff;
    touch-action: none; /* Disable default touch behaviors for custom panning */
    -webkit-user-select: none;
    user-select: none;
    overscroll-behavior: none;
}

#main-canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: white;
    touch-action: none; /* Disable default touch behaviors */
    -webkit-user-select: none;
    user-select: none;
}

/* SVG Styles for Braces */
.brace-element {
    fill: none;
    stroke: #8B4513;
    stroke-width: 0.02;
    cursor: pointer;
    transition: stroke-width 0.3s;
}

.brace-element:hover {
    stroke-width: 0.04;
    stroke: #A0522D;
}

.brace-element.selected {
    stroke: #e74c3c;
    stroke-width: 0.04;
}

.outline-element {
    fill: none;
    stroke: #000;
    stroke-width: 0.02;
}

.dimension-line {
    stroke: #666;
    stroke-width: 1;
    marker-end: url(#arrowhead);
}

.dimension-text {
    font-family: Arial, sans-serif;
    font-size: 12px;
    fill: #666;
    text-anchor: middle;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 8px;
    width: 80%;
    max-width: 800px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

.modal-header h2 {
    color: #000000;
    font-weight: 400;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.3s;
}

.close-btn:hover {
    background: #e9ecef;
    color: #333;
}

.modal-body {
    padding: 25px;
    max-height: calc(80vh - 100px);
    overflow-y: auto;
}

.modal-body ul {
    margin-left: 20px;
    padding-left: 20px;
    list-style-type: disc;
    margin-bottom: 15px;
}

.modal-body li {
    margin-bottom: 8px;
    line-height: 1.6;
}

/* Template Grid */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.template-card {
    border: 1px solid #e9ecef;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s;
    background: white;
}

.template-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    border-color: #00AE42;
}

.template-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    background: #f8f9fa;
}

.template-card h3 {
    padding: 15px 15px 5px;
    font-size: 1.1rem;
    color: #000000;
}

.template-card p {
    padding: 0 15px 15px;
    color: #666;
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Settings */
.settings-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e9ecef;
}

.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.settings-section h3 {
    color: #000000;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.settings-section label {
    display: block;
    margin-bottom: 10px;
    cursor: pointer;
}

.settings-section input[type="radio"] {
    margin-right: 8px;
}

/* Loading Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    text-align: center;
    color: white;
}

.loading-spinner i {
    font-size: 3rem;
    margin-bottom: 20px;
    display: block;
}

.loading-spinner p {
    font-size: 1.2rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
    main {
        flex-direction: column;
    }
    
    .control-panel {
        width: 100%;
        position: static;
    }
    
    .drawing-area {
        min-height: 600px;
        height: 600px;
    }
    
    .canvas-container {
        flex: 1;
        min-height: 500px;
        height: 100%;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }
    
    header .container {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    nav ul {
        gap: 1rem;
    }
    
    .canvas-toolbar {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .toolbar-group {
        gap: 5px;
    }
    
    .modal-content {
        width: 95%;
        margin: 2% auto;
    }
}

@media (max-width: 480px) {
    .control-panel {
        padding: 0;
    }
    
    .panel-section {
        padding: 15px;
    }
    
    .control-row {
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
    }
    
    .control-row label {
        margin-right: 0;
        min-width: auto;
    }
    
    .toolbar-btn {
        padding: 6px 8px;
        font-size: 12px;
    }
    
    .template-grid {
        grid-template-columns: 1fr;
    }
}

/* Animation classes */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

.slide-in {
    animation: slideIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { 
        opacity: 0;
        transform: translateY(-20px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

/* Utility classes */
.hidden {
    display: none !important;
}

.disabled {
    pointer-events: none;
    opacity: 0.6;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: #6c757d;
}

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }

/* View-based element visibility */
#imported-outline[data-view="back"] .top-element,
#imported-outline[data-view="back"] [id^="x-brace-"],
#imported-outline[data-view="back"] [id^="tonebar1-"],
#imported-outline[data-view="back"] [id^="tonebar2-"],
#imported-outline[data-view="back"] [id^="upper-graft-"],
#imported-outline[data-view="back"] [id^="upper-transverse-"],
#imported-outline[data-view="back"] [id^="upper-finger-"],
#imported-outline[data-view="back"] [id^="lower-finger-"],
#imported-outline[data-view="back"] #soundhole-circle,
#imported-outline[data-view="back"] #saddle-location-line {
    display: none !important;
}

#imported-outline[data-view="top"] .back-element,
#imported-outline[data-view="top"] [id^="back-brace-1-"],
#imported-outline[data-view="top"] [id^="back-brace-2-"],
#imported-outline[data-view="top"] [id^="back-brace-3-"],
#imported-outline[data-view="top"] [id^="back-brace-4-"] {
    display: none !important;
}

/* Lightbox styles for diagram enlargement */
.lightbox {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9);
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lightbox-content {
    margin: auto;
    display: block;
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    object-fit: contain;
    animation: zoomIn 0.3s;
}

@keyframes zoomIn {
    from { transform: scale(0.8); }
    to { transform: scale(1); }
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 40px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
    z-index: 10001;
}

.lightbox-close:hover,
.lightbox-close:focus {
    color: #bbb;
}

.lightbox-caption {
    margin: auto;
    display: block;
    width: 90%;
    max-width: 1200px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    font-size: 14px;
}

#y-offset-diagram-thumb:hover {
    transform: scale(1.02);
}

#y-offset-diagram-back-thumb:hover {
    transform: scale(1.02);
}

/* Mobile-Friendly Number Input Controls */
.number-input-wrapper {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.number-input-wrapper input[type="number"] {
    flex: 1;
    min-width: 60px;
    text-align: center;
}

.number-input-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    padding: 0;
    border: 1px solid #ccc;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    transition: all 0.15s ease;
    color: #333;
}

.number-input-btn:hover {
    background: #f0f0f0;
    border-color: #00AE42;
}

.number-input-btn:active {
    background: #00AE42;
    color: white;
    transform: scale(0.95);
}

.number-input-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.number-input-btn:disabled:hover {
    background: #fff;
    border-color: #ccc;
}

/* Make buttons more touch-friendly on mobile */
@media (max-width: 768px) {
    /* Ensure horizontal layout for number input wrappers on all mobile devices */
    .control-row .number-input-wrapper {
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        gap: 6px;
    }
    
    .control-row .number-input-wrapper input[type="number"] {
        flex: 1;
        min-width: 50px;
    }
    
    .control-row .number-input-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        flex-shrink: 0;
        font-size: 22px;
    }
}