/* ==========================================================================
   HYANG — MATERIAL DESIGN 3 (M3 EXPRESSIVE DARK THEME) SYSTEM DESIGN
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    /* M3 Expressive Dark Color System */
    --md-sys-color-background: #0d1117;
    --md-sys-color-on-background: #e6e1e5;
    
    --md-sys-color-surface: #141922;
    --md-sys-color-surface-dim: #10141c;
    --md-sys-color-surface-container-low: #1a202c;
    --md-sys-color-surface-container: #212836;
    --md-sys-color-surface-container-high: #283142;
    --md-sys-color-surface-container-highest: #333d52;
    --md-sys-color-on-surface: #e6e1e5;
    --md-sys-color-on-surface-variant: #cac4d0;

    --md-sys-color-primary: #a8c7fa;
    --md-sys-color-on-primary: #062e6f;
    --md-sys-color-primary-container: #0842a0;
    --md-sys-color-on-primary-container: #d3e3fd;

    --md-sys-color-secondary: #c2c7cf;
    --md-sys-color-on-secondary: #2c313a;
    --md-sys-color-secondary-container: #3e4758;
    --md-sys-color-on-secondary-container: #dde3ea;

    --md-sys-color-tertiary: #ffb77d;
    --md-sys-color-on-tertiary: #4c2700;
    --md-sys-color-tertiary-container: #6d3a00;
    --md-sys-color-on-tertiary-container: #ffdcc2;

    --md-sys-color-outline: #8e9199;
    --md-sys-color-outline-variant: #444b5a;

    /* M3 Elevation & Shadows */
    --md-sys-elevation-level1: 0px 1px 3px 1px rgba(0, 0, 0, 0.4), 0px 1px 2px 0px rgba(0, 0, 0, 0.3);
    --md-sys-elevation-level2: 0px 4px 8px 3px rgba(0, 0, 0, 0.45), 0px 1px 3px 0px rgba(0, 0, 0, 0.3);
    --md-sys-elevation-level3: 0px 8px 24px 6px rgba(0, 0, 0, 0.55), 0px 2px 6px 0px rgba(0, 0, 0, 0.4);

    /* M3 Shape System */
    --md-sys-shape-corner-full: 9999px;
    --md-sys-shape-corner-extra-large: 24px;
    --md-sys-shape-corner-large: 18px;
    --md-sys-shape-corner-medium: 14px;
    --md-sys-shape-corner-small: 8px;

    /* Typography */
    --font-sans: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
}

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

/* ==========================================================================
   M3 TOP APP BAR
   ========================================================================== */
header {
    height: 64px;
    background: rgba(20, 25, 34, 0.88);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
    box-shadow: var(--md-sys-elevation-level1);
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--md-sys-color-primary-container), #1d6df4);
    border-radius: var(--md-sys-shape-corner-medium);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 4px 12px rgba(168, 199, 250, 0.25);
}

.logo-text h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--md-sys-color-on-surface);
}

.logo-text span {
    font-size: 11px;
    color: var(--md-sys-color-on-surface-variant);
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 600;
    display: block;
}

.controls-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.input-group {
    display: flex;
    align-items: center;
    background: var(--md-sys-color-surface-container-high);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-full);
    padding: 5px 14px;
    transition: all 0.2s ease;
}

.input-group:focus-within {
    border-color: var(--md-sys-color-primary);
    box-shadow: 0 0 0 2px rgba(168, 199, 250, 0.2);
    background: var(--md-sys-color-surface-container-highest);
}

.input-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--md-sys-color-on-surface-variant);
    margin-right: 8px;
}

.input-group input {
    background: transparent;
    border: none;
    color: var(--md-sys-color-on-surface);
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 500;
    outline: none;
    width: 120px;
}

.btn-generate {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    border-radius: var(--md-sys-shape-corner-full);
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 14px rgba(168, 199, 250, 0.3);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-generate:hover {
    background: #bce0ff;
    box-shadow: 0 6px 20px rgba(168, 199, 250, 0.45);
    transform: translateY(-1px);
}

.btn-generate:active {
    transform: translateY(0);
}

.btn-toggle-view {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    border: 1px solid transparent;
    border-radius: var(--md-sys-shape-corner-full);
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-toggle-view:hover {
    background: var(--md-sys-color-surface-container-highest);
    border-color: var(--md-sys-color-outline-variant);
}

/* ==========================================================================
   MAIN VIEWPORT & CANVAS
   ========================================================================== */
main {
    flex: 1;
    position: relative;
    display: flex;
    overflow: hidden;
    background: radial-gradient(circle at 50% 50%, #161b24 0%, #0c1017 100%);
}

#canvas-container, #globe-container {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

#canvas-container:active {
    cursor: grabbing;
}

#map-canvas, #hud-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

#map-canvas {
    box-shadow: var(--md-sys-elevation-level3);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-medium);
}

/* Finite-world mode: natural-size canvas (1024×1024), JS handles transform for zoom/pan */
#map-canvas.finite-mode {
    position: absolute;
    top: 50%;
    left: 50%;
    width: auto;
    height: auto;
    transform-origin: center center;
    /* Initial centering is overridden by applyTransform() in main.js */
}

#hud-canvas.finite-mode {
    position: absolute;
    top: 50%;
    left: 50%;
    width: auto;
    height: auto;
    pointer-events: none;
}

/* Endless mode: canvas fills the entire container */
#map-canvas.endless-mode, #hud-canvas.endless-mode {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: none !important;
}

#hud-canvas {
    pointer-events: none;
    background: transparent;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
}

/* ==========================================================================
   ENDLESS STREAMING WIDGET (TOP LEFT)
   ========================================================================== */
.endless-toolbar {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(28, 35, 48, 0.88);
    backdrop-filter: blur(20px);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-full);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--md-sys-elevation-level2);
    z-index: 40;
}

.stream-status {
    display: flex;
    align-items: center;
    gap: 10px;
}

.live-dot {
    width: 8px;
    height: 8px;
    background-color: #4ade80;
    border-radius: 50%;
    box-shadow: 0 0 8px #4ade80;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

.stream-label {
    color: var(--md-sys-color-on-surface);
    font-weight: 700;
    font-size: 13px;
}

.stream-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.stats-label {
    font-size: 12px;
    color: var(--md-sys-color-on-surface-variant);
    font-weight: 500;
}

.nav-btn {
    background: var(--md-sys-color-surface-container-high);
    border: 1px solid var(--md-sys-color-outline-variant);
    color: var(--md-sys-color-on-surface);
    border-radius: var(--md-sys-shape-corner-full);
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border-color: var(--md-sys-color-primary);
}

.sector-badge {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    color: var(--md-sys-color-primary);
    padding: 4px 10px;
    background: rgba(8, 66, 160, 0.35);
    border-radius: var(--md-sys-shape-corner-full);
    border: 1px solid rgba(168, 199, 250, 0.25);
}

/* ==========================================================================
   M3 SEGMENTED FLOATING NAVIGATION BAR (MAP MODES)
   ========================================================================== */
.map-modes-toolbar {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(28, 35, 48, 0.88);
    backdrop-filter: blur(20px);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-full);
    padding: 5px;
    display: flex;
    gap: 4px;
    box-shadow: var(--md-sys-elevation-level3);
    z-index: 50;
}

.mode-btn {
    background: transparent;
    border: none;
    color: var(--md-sys-color-on-surface-variant);
    padding: 8px 15px;
    border-radius: var(--md-sys-shape-corner-full);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 6px;
}

.mode-btn:hover {
    background: rgba(230, 225, 229, 0.08);
    color: var(--md-sys-color-on-surface);
}

.mode-btn.active {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    box-shadow: 0 4px 12px rgba(8, 66, 160, 0.4);
}

/* ==========================================================================
   COMPACT HUD PHYSICAL INSPECTOR PANEL (TIGHT & SMALL UX)
   ========================================================================== */
.compact-inspector {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 220px;
    background: rgba(24, 30, 42, 0.88);
    backdrop-filter: blur(20px);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-large);
    padding: 14px 16px;
    box-shadow: var(--md-sys-elevation-level3);
    z-index: 40;
    pointer-events: none;
}

.compact-inspector h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--md-sys-color-primary);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: 0.3px;
}

.compact-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.data-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.no-border {
    border-bottom: none !important;
    padding-bottom: 0 !important;
}

.biome-row {
    padding-top: 2px;
}

.data-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
}

.data-value {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
}

.badge {
    padding: 2px 8px;
    border-radius: var(--md-sys-shape-corner-full);
    font-size: 10px;
    font-weight: 700;
}

/* ==========================================================================
   PLANET LAB PANEL (EXPRESSIVE SURFACE CARD)
   ========================================================================== */
.inspector-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 330px;
    background: rgba(28, 35, 48, 0.92);
    backdrop-filter: blur(20px);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-extra-large);
    padding: 20px;
    box-shadow: var(--md-sys-elevation-level3);
    z-index: 60;
    pointer-events: auto;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
}

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

.panel-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--md-sys-color-tertiary);
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
}

.preset-section label {
    font-size: 12px;
    color: var(--md-sys-color-on-surface-variant);
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
}

.preset-section select {
    width: 100%;
    background: var(--md-sys-color-surface-container-highest);
    border: 1px solid var(--md-sys-color-outline-variant);
    color: #fff;
    padding: 8px 12px;
    border-radius: 10px;
    font-family: var(--font-sans);
    font-size: 13px;
    outline: none;
}

.panel-divider {
    border: none;
    border-top: 1px solid rgba(255,255,255,0.08);
    margin: 14px 0;
}

.sliders-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.slider-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 6px;
}

.output-title {
    font-size: 12px;
    color: var(--md-sys-color-primary);
    margin-bottom: 10px;
    font-weight: 600;
}

.output-grid {
    background: var(--md-sys-color-surface-dim);
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.05);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.w-full {
    width: 100%;
    justify-content: center;
    margin-top: 14px;
    background: var(--md-sys-color-tertiary) !important;
    color: var(--md-sys-color-on-tertiary) !important;
}

/* Sliders */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 5px;
    background: var(--md-sys-color-surface-container-highest);
    border-radius: var(--md-sys-shape-corner-full);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--md-sys-color-primary);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    transition: transform 0.1s ease;
}

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

/* ==========================================================================
   STATUS OVERLAY (INITIALIZING ENGINE)
   ========================================================================== */
#status-overlay {
    position: absolute;
    inset: 0;
    background: rgba(13, 17, 23, 0.9);
    backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#status-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--md-sys-color-surface-container-highest);
    border-top-color: var(--md-sys-color-primary);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.status-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
}
