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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 8px;
    color: #333;
}

.container {
    width: 100%;
    max-width: none;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 30px;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5em;
    color: #667eea;
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    color: #666;
    font-size: 1.1em;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 24px 32px;
    margin-bottom: 30px;
    padding: 24px 28px;
    background: #f8f9fa;
    border-radius: 8px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 280px;
}

.control-group label {
    font-weight: 600;
    color: #555;
    white-space: nowrap;
}

/* Grids row: icon-only buttons, no overflow */
.control-group-grids {
    flex-wrap: wrap;
    min-width: 0;
    flex: 0 1 auto;
}

.control-group-grids .btn-icon {
    width: 2.25rem;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1em;
    line-height: 1;
}

.control-group input[type="number"] {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    width: 120px;
    transition: border-color 0.3s;
}

.control-group input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
}

.control-group span {
    font-weight: 600;
    color: #667eea;
    min-width: 60px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

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

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.4);
}

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

.canvas-container {
    position: relative;
    width: 100%;
    height: 650px;
    margin-bottom: 30px;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

#minimap-canvas {
    display: block;
    cursor: grab;
    width: 100%;
    height: 650px;
    object-fit: contain;
}

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

.loading-overlay {
    position: absolute;
    right: 20px;
    bottom: 20px;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    flex-direction: column;
    align-items: flex-end;
    padding: 15px 20px;
    color: white;
    border-radius: 8px;
    z-index: 10;
    pointer-events: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: loading-overlay-pulse 2.5s ease-in-out infinite;
}

@keyframes loading-overlay-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.92; }
}

.loading-overlay p {
    margin-top: 10px;
    font-size: 1em;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.generation-progress {
    margin-top: 10px;
    width: 250px;
    max-width: 100%;
}

.progress-bar {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 5px;
}

.progress-fill {
    height: 100%;
    background: #667eea;
    border-radius: 6px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 0.8em;
    margin-top: 5px;
    color: rgba(255, 255, 255, 0.9);
    text-align: right;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    align-self: flex-end;
}

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

.info {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.info p {
    margin-bottom: 10px;
    font-weight: 600;
    color: #555;
}

.info ul {
    list-style-position: inside;
    color: #666;
}

.info li {
    margin-bottom: 5px;
}

.tile-tooltip {
    position: absolute;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    display: none;
    white-space: nowrap;
}

.tile-tooltip.tooltip-structured {
    white-space: normal;
}

.tile-tooltip.show {
    display: block;
}

.tile-tooltip .tooltip-header {
    white-space: nowrap;
    display: block;
    margin-bottom: 4px;
}

.tile-tooltip .tooltip-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 16px;
    font-size: 11px;
    margin-top: 4px;
    white-space: nowrap;
}

.tile-tooltip .tooltip-fields .tooltip-field {
    line-height: 1.35;
}

.tile-tooltip .tooltip-npcs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 4px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    font-size: 11px;
    white-space: nowrap;
}

.tile-tooltip .tooltip-npcs .tooltip-npc-line {
    line-height: 1.35;
}

.tile-tooltip .tooltip-threat {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    font-size: 11px;
}

.tile-info-panel {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
    margin-bottom: 20px;
}

.tile-info-panel h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #555;
    font-size: 1.2em;
}

.tile-info-panel #tile-info-content {
    color: #666;
    font-size: 0.95em;
}

.tile-info-panel .info-row {
    margin-bottom: 8px;
    padding: 4px 0;
    border-bottom: 1px solid #e0e0e0;
}

.tile-info-panel .info-row:last-child {
    border-bottom: none;
}

.tile-info-panel .info-label {
    font-weight: 600;
    color: #555;
    display: inline-block;
    min-width: 120px;
}

.tile-info-panel .info-value {
    color: #333;
}

.params-section {
    margin-bottom: 30px;
    background: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
}

.collapse-toggle {
    width: 100%;
    padding: 15px 20px;
    background: #667eea;
    color: white;
    border: none;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.3s;
}

.collapse-toggle:hover {
    background: #5568d3;
}

.collapse-icon {
    font-size: 0.8em;
    transition: transform 0.3s;
}

.params-content {
    padding: 20px;
    display: none;
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

.noise-maps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
    width: 100%;
    box-sizing: border-box;
}

.noise-map-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.noise-map-item canvas {
    max-width: 100%;
    width: 400px;
    height: 400px;
    display: block;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.noise-map-label {
    font-size: 0.9em;
    font-weight: 600;
    color: #333;
}

.map-size-group {
    margin-bottom: 20px;
    max-width: 500px;
    width: 100%;
    box-sizing: border-box;
}

.params-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
    width: 100%;
    box-sizing: border-box;
}

.param-group {
    background: white;
    padding: 15px;
    border-radius: 6px;
    border: 2px solid #e0e0e0;
    overflow: hidden;
    min-width: 0;
}

.param-group h3 {
    margin-bottom: 15px;
    color: #667eea;
    font-size: 1.1em;
    border-bottom: 2px solid #667eea;
    padding-bottom: 8px;
}

.param-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
    min-width: 0;
    width: 100%;
}

.param-row label {
    flex: 0 0 90px;
    font-size: 0.9em;
    color: #555;
    font-weight: 500;
    min-width: 0;
}

.param-row input[type="number"] {
    flex: 1;
    min-width: 0;
    max-width: 150px;
    padding: 6px 10px;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-size: 0.9em;
    transition: border-color 0.3s;
    width: 100%;
    box-sizing: border-box;
}

.param-row input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
}

.curve-editor-wrap {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.curve-editor-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.curve-editor-controls label {
    flex: 0 0 auto;
}

.param-info {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e0e0e0;
}

.param-info small {
    color: #666;
    font-size: 0.85em;
}

.falloff-layers-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.falloff-toggle {
    width: 100%;
    padding: 8px 12px;
    background: #e8e8e8;
    color: #555;
    border: none;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 4px;
    margin-bottom: 10px;
    transition: background 0.3s;
}

.falloff-toggle:hover {
    background: #d0d0d0;
}

.falloff-content {
    padding: 10px;
    background: #f8f8f8;
    border-radius: 4px;
    margin-bottom: 10px;
}

.falloff-layer {
    background: white;
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
}

.falloff-layer h4 {
    margin-bottom: 10px;
    color: #667eea;
    font-size: 0.95em;
}

.falloff-layer .param-row {
    margin-bottom: 8px;
}

.falloff-layer input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.add-falloff-layer {
    margin-top: 10px;
    width: 100%;
}

.params-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    padding-top: 15px;
    border-top: 2px solid #e0e0e0;
}

@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    header h1 {
        font-size: 2em;
    }

    .controls {
        flex-direction: column;
    }

    .control-group {
        width: 100%;
    }

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

    .params-grid {
        grid-template-columns: 1fr;
    }

    .params-actions {
        flex-direction: column;
    }

    .params-actions .btn {
        width: 100%;
    }
}