:root {
    --primary: #2c3e50;
    --secondary: #3498db;
    --accent: #e74c3c;
    --light: #ecf0f1;
    --dark: #2c3e50;
    --success: #2ecc71;
    --warning: #f39c12;
    --timber: #c19a6b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #1a2980, #26d0ce);
    color: #333;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

header {
    background: var(--primary);
    color: white;
    padding: 20px;
    text-align: center;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.2rem;
    opacity: 0.8;
}

.main-content {
    display: flex;
    flex-wrap: wrap;
    padding: 20px;
}

.input-section {
    flex: 1;
    min-width: 300px;
    padding: 20px;
    background: var(--light);
    border-radius: 10px;
    margin-right: 20px;
    margin-bottom: 20px;
}

.output-section {
    flex: 2;
    min-width: 500px;
    padding: 20px;
}

.input-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--dark);
}

input, select {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
}

input:focus, select:focus {
    border-color: var(--secondary);
    outline: none;
}

button {
    background: linear-gradient(to right, var(--secondary), var(--primary));
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    font-weight: 600;
    display: block;
    margin: 20px auto;
    transition: transform 0.3s, box-shadow 0.3s;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.visualization {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    height: 300px;
    position: relative;
    overflow: hidden;
}

.results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.result-card {
    background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.result-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 8px;
}

.result-value {
    font-size: 20px;
    font-weight: 700;
    color: #333;
}

.export-options {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.export-btn {
    background: var(--success);
    padding: 10px 20px;
    font-size: 16px;
}

.template-btn {
    background: var(--warning);
    padding: 8px 16px;
    font-size: 14px;
    margin: 5px;
}

footer {
    text-align: center;
    padding: 20px;
    background: var(--dark);
    color: white;
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }
    
    .input-section {
        margin-right: 0;
    }
}

/* Visualization CSS */
.platform-base {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 20px;
    background: #95a5a6;
    border-radius: 5px;
}

.platform-top {
    position: absolute;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%) rotate(0deg);
    width: 180px;
    height: 15px;
    background: #3498db;
    border-radius: 5px;
    transform-origin: center bottom;
    transition: transform 1s ease;
}

.telescope {
    position: absolute;
    bottom: 135px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 100px;
    background: linear-gradient(to right, #7f8c8d, #bdc3c7);
    border-radius: 5px 5px 0 0;
}

.bearing {
    position: absolute;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 30px;
    background: #e74c3c;
    border-radius: 50%;
}

.latitude-line {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 70px;
    background: #34495e;
    opacity: 0.5;
}

.angle-label {
    position: absolute;
    bottom: 40px;
    right: 50%;
    transform: translateX(100%);
    font-size: 12px;
    color: #34495e;
}

.north-bearing {
    position: absolute;
    bottom: 70px;
    left: 30%;
    width: 20px;
    height: 50px;
    background: #e74c3c;
    border-radius: 5px;
}

.south-bearing {
    position: absolute;
    bottom: 70px;
    left: 70%;
    width: 20px;
    height: 50px;
    background: #e74c3c;
    border-radius: 5px;
}

.cog-marker {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #f1c40f;
    border-radius: 50%;
    border: 2px solid #d35400;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid #ddd;
    flex-wrap: wrap;
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    background: #f8f9fa;
    border-radius: 5px 5px 0 0;
    margin-right: 5px;
    border: 1px solid #ddd;
    border-bottom: none;
}

.tab.active {
    background: white;
    border-bottom: 2px solid white;
    margin-bottom: -2px;
}

.openscad-output {
    background: #2c3e50;
    color: white;
    padding: 15px;
    border-radius: 5px;
    font-family: monospace;
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
    position: relative;
}

.copy-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--success);
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

/* Timber Parts Visualization */
.timber-parts {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 20px;
}

.timber-part {
    flex: 1;
    min-width: 300px;
    background: white;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.part-title {
    text-align: center;
    margin-bottom: 15px;
    color: var(--primary);
    font-weight: 600;
}

.part-canvas {
    width: 100%;
    height: 200px;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 5px;
    margin-bottom: 10px;
}

.part-dimensions {
    font-size: 14px;
    line-height: 1.6;
}

.dimension-line {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed #ddd;
    padding: 5px 0;
}

.dimension-label {
    font-weight: 600;
}

.dimension-value {
    color: var(--secondary);
}

/* Timber Visualization */
.timber-base {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--timber);
    border: 2px solid #8b5a2b;
    overflow: hidden;
}

.timber-platform {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--timber);
    border: 2px solid #8b5a2b;
    overflow: hidden;
    transform-origin: center;
}

.dimension-text {
    position: absolute;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.8);
    padding: 2px 5px;
    border-radius: 3px;
}

.dimension-line-h {
    position: absolute;
    height: 2px;
    background: #e74c3c;
}

.dimension-line-v {
    position: absolute;
    width: 2px;
    background: #e74c3c;
}

.bearing-hole {
    position: absolute;
    width: 15px;
    height: 15px;
    background: #e74c3c;
    border-radius: 50%;
    border: 2px solid #8b5a2b;
}

.part-selector {
    margin-top: 20px;
    padding: 15px;
    background: var(--light);
    border-radius: 10px;
}

.part-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.part-option {
    padding: 10px 15px;
    background: white;
    border: 2px solid #ddd;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s;
}

.part-option.selected {
    background: var(--secondary);
    color: white;
    border-color: var(--primary);
}

/* Template Styles */
.template-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.template-card {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    border-left: 4px solid var(--secondary);
}

.template-card h3 {
    color: var(--primary);
    margin-bottom: 10px;
}

.template-card p {
    color: #666;
    margin-bottom: 15px;
    line-height: 1.5;
}

.template-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.template-preview {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    min-height: 300px;
}

.preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    background: #f8f9fa;
    border: 2px dashed #ddd;
    border-radius: 5px;
    color: #666;
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--secondary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.status-message {
    padding: 10px;
    border-radius: 5px;
    margin: 10px 0;
    text-align: center;
}

.status-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.status-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.status-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}
.preview-gallery {
    margin-top: 2rem;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.preview-item {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1rem;
    background: white;
}

.preview-item h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.9rem;
    color: #333;
}

.preview-container {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9f9f9;
    border-radius: 4px;
}

.part-preview-image {
    max-width: 100%;
    max-height: 180px;
    border: 1px solid #ddd;
}

.preview-actions {
    margin-top: 0.5rem;
}

.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    background: #007cba;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

.btn-small:hover {
    background: #005a87;
}

.loading-small {
    font-size: 0.8rem;
    color: #666;
}

.error-small {
    font-size: 0.8rem;
    color: #d33;
}

.download-contents {
    background: #f0f8ff;
    padding: 1rem;
    border-radius: 4px;
    margin-top: 1rem;
}

.download-contents ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.download-contents li {
    margin: 0.25rem 0;
}
