:root {
    --primary: #007aff;
    --primary-hover: #0063d1;
    --bg: #f5f5f7;
    --card-bg: rgba(255, 255, 255, 0.8);
    --text-main: #1d1d1f;
    --text-muted: #86868b;
    --border: rgba(0, 0, 0, 0.1);
    --radius-lg: 20px;
    --radius-md: 12px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: var(--text-main);
}

.app-container {
    width: 100%;
    max-width: 1800px; /* Use more of the screen */
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
}


header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

header h2 {
    font-size: 24px;
    font-weight: 800;
    margin: 0;
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    gap: 12px;
}

/* Bento Grid */
.bento-grid {
    display: grid;
    /* 2 columns: Left(1.5fr) | Right(1fr) */
    grid-template-columns: 1.5fr 1fr;
    gap: 12px; /* Reduced gap */
    align-items: stretch;
}


.bento-item {
    background: var(--card-bg);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px; /* Reduced padding */
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);
    box-sizing: border-box; /* Prevent padding from causing overflow */
}

/* Hero Canvas Section */
.hero-canvas {
    grid-column: 1;
    padding: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background: transparent;
    position: relative;
}

#simCanvas {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    display: block;
    background: #e1e1e1;
    border-radius: var(--radius-lg);
}



#simCanvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}


/* Admin Section Logic */
#adminSection,
.admin-only {
    display: none;
}

.admin-mode #adminSection {
    display: block;
    grid-column: 1 / span 2;
    animation: slideIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}


.admin-mode .admin-only {
    display: inline-block;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Typography & Headers */
.section-header {
    margin-bottom: 12px; /* Reduced margin */
}

.section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Controls */
.button-stack,
.slider-stack {
    display: flex;
    flex-direction: column;
    gap: 8px; /* Reduced gap */
}

.controls-env .slider-stack {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
    align-content: start;
}

.grid-sliders {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    align-items: end;
}

.hole-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.button-row {
    display: flex;
    gap: 8px;
}

/* Apple Style Buttons */
button {
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
    background: var(--primary);
    color: white;
    width: 100%;
}

.btn-secondary {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-main);
    flex: 1;
}

.btn-secondary.active {
    background: #34c759;
    color: white;
}

button:hover {
    transform: scale(0.98);
    opacity: 0.9;
}

button:active {
    transform: scale(0.95);
}

/* Apple Style Sliders */
.apple-slider {
    display: flex;
    flex-direction: column;
    gap: 4px; /* Even tighter gap */
}

.slider-info {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 600;
}

.slider-info span {
    color: var(--primary);
    font-family: 'JetBrains Mono', monospace;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
    outline: none;
}

/* Debug Console Styles */
.debug-console-full {
    margin-top: 15px;
    background: rgba(0, 0, 0, 0.9) !important;
    border: 1px solid rgba(255, 255, 255, 0.1);
    min-height: 200px;
    display: flex;
    flex-direction: column;
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: bold;
    color: #3b82f6;
}

.debug-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-mini {
    background: #333;
    border: 1px solid #555;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.btn-mini:hover {
    background: #444;
}

.debug-card-container {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    position: relative;
    min-height: 0;
}

/* Custom scrollbar for dark debug console */
.debug-card-container::-webkit-scrollbar {
    width: 4px;
}
.debug-card-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.debug-card {
    background: rgba(20, 20, 20, 0.8);
    border-left: 3px solid #3b82f6;
    padding: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
    color: #d1d5db;
    white-space: pre-wrap;
    animation: fadeIn 0.3s ease;
}

.debug-time {
    color: #6b7280;
    font-size: 11px;
    margin-bottom: 8px;
    display: block;
    border-bottom: 1px dashed #333;
    padding-bottom: 4px;
}

.debug-card.empty {
    text-align: center;
    color: #4b5563;
    border: none;
    margin-top: 40px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: white;
    border: 0.5px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: transform 0.1s;
}

input[type="range"]:active::-webkit-slider-thumb {
    transform: scale(1.2);
}

/* Toggle Switch */
.checkbox-apple {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    flex: 1;
    background: rgba(0, 0, 0, 0.05);
    padding: 6px 12px;
    border-radius: var(--radius-md);
}

.checkbox-apple input {
    display: none;
}

.slider-check {
    width: 36px;
    height: 20px;
    background: #ccc;
    border-radius: 10px;
    position: relative;
    transition: 0.3s;
}

.slider-check:before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    left: 2px;
    top: 2px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input:checked+.slider-check {
    background: #34c759;
}

input:checked+.slider-check:before {
    transform: translateX(16px);
}

.label-text {
    font-size: 14px;
    font-weight: 600;
}

/* Segmented Control */
.segmented-control {
    display: flex;
    background: rgba(0, 0, 0, 0.05);
    padding: 2px;
    border-radius: 9px;
    gap: 2px;
}

.hole-btn {
    flex: 1;
    padding: 6px;
    font-size: 13px;
    background: transparent;
    color: var(--text-main);
    border-radius: 7px;
}

.hole-btn.active {
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.disabled-group {
    opacity: 0.4;
    pointer-events: none;
}

/* Side Panel System */
.side-panel-group {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 0; /* Ignore intrinsic height for grid row calculation */
    min-height: 100%; /* Stretch to match the row height dictated by hero-canvas */
}

.panel-header-toggle {
    background: var(--card-bg);
    padding: 8px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    backdrop-filter: blur(20px);
}

.tab-btn {
    flex: 1;
    padding: 8px;
    font-size: 13px;
    background: transparent;
    color: var(--text-muted);
    border-radius: 7px;
    transition: all 0.2s;
}

.tab-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ai-chat-panel, .debug-console-panel {
    display: none !important;
}

.ai-chat-panel.active-panel, .debug-console-panel.active-panel {
    display: flex !important;
}

/* AI Chatbox Panel */
.ai-chat-panel {
    flex: 1; /* Fill available height */
    display: flex;
    flex-direction: column;
    gap: 8px; /* Reduced gap */
    min-height: 0; /* Allow shrinking */
}

.ai-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 4px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #34c759;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(52, 199, 89, 0.5);
    transition: all 0.3s ease;
}

.status-dot.resting {
    background: #ff9f0a;
    /* Orange */
    box-shadow: 0 0 8px rgba(255, 159, 10, 0.5);
}

.status-dot.thinking {
    background: #0a84ff;
    /* Blue */
    box-shadow: 0 0 8px rgba(10, 132, 255, 0.5);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.7;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}


.status-text {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 8px;
}

/* Custom Scrollbar for Chat */
.chat-history::-webkit-scrollbar {
    width: 4px;
}

.chat-history::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: messageIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-msg {
    align-self: flex-start;
}

.user-msg {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    background: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.msg-content {
    background: white;
    padding: 10px 14px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-main);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
}

.user-msg .msg-content {
    background: var(--primary);
    color: white;
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 4px;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.chat-input-area input {
    flex: 1;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: background 0.2s;
}

.chat-input-area input:focus {
    background: rgba(0, 0, 0, 0.08);
}

.chat-input-area button {
    width: auto;
    padding: 0 24px;
    white-space: nowrap;
}

/* Debug Console Styles - Tabbed version */
.debug-console-panel {
    flex: 1; /* Fill available height */
    background: rgba(15, 23, 42, 0.9) !important;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px;
    font-family: 'JetBrains Mono', monospace;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-height: 0; /* Allow shrinking */
}

.controls-basic {
    grid-column: 1;
}

.controls-env {
    grid-column: 2;
}

.controls-basic, .controls-env {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.debug-header {
    font-size: 11px;
    color: #34c759;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 6px;
}

#debugLog {
    font-size: 11px;
    color: #cbd5e1;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow-y: auto;
}

/* Responsive */
@media (max-width: 1200px) {
    .bento-grid {
        grid-template-columns: 1fr;
    }

    .side-panel-group {
        grid-column: 1;
        grid-row: auto;
    }
}