:root {
    --bg-color: #242322;
    --panel-color: #303030;
    --panel-border: #4a4a4a;
    --accent-color: #ff9f1c;
    --accent-hover: #ffb84d;
    --text-main: #e2e1e0;
    --text-muted: #999;
    --btn-primary-bg: #ff9f1c;
    --btn-primary-text: #1a1a1a;
    --btn-secondary-bg: #404040;
    --btn-secondary-border: #5a5a5a;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --slot-bg: #2a2928;
    --slot-border: #1a1918;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-family);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background-image: radial-gradient(circle at center, #2a2928 0%, #1f1e1d 100%);
}

.factorio-window {
    background-color: var(--bg-color);
    border: 2px solid #555;
    border-radius: 4px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
}

.window-header {
    background: linear-gradient(to bottom, #4a4a4a, #2a2a2a);
    padding: 12px 16px;
    border-bottom: 2px solid #111;
    border-radius: 2px 2px 0 0;
}

.window-header h1 {
    font-size: 1.2rem;
    font-weight: bold;
    color: #ffcc66;
    text-shadow: 1px 1px 2px #000;
    letter-spacing: 0.5px;
}

.window-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel {
    background-color: var(--panel-color);
    border: 2px solid var(--panel-border);
    border-radius: 4px;
    padding: 16px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.panel h2 {
    font-size: 1rem;
    color: #ffcc66;
    margin-bottom: 12px;
    border-bottom: 1px solid #444;
    padding-bottom: 4px;
}

label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: #ccc;
}

textarea {
    width: 100%;
    background-color: #1a1a1a;
    border: 2px solid #111;
    color: var(--text-main);
    padding: 10px;
    font-family: monospace;
    font-size: 0.9rem;
    resize: vertical;
    border-radius: 2px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

textarea:focus {
    outline: none;
    border-color: var(--accent-color);
}

.control-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 16px;
}

.control-group label {
    margin-bottom: 0;
    min-width: 100px;
}

.radio-group {
    display: flex;
    gap: 16px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: normal;
    cursor: pointer;
    min-width: auto;
}

.factorio-select {
    background-color: #1a1a1a;
    color: var(--text-main);
    border: 2px solid #444;
    padding: 4px 8px;
    border-radius: 2px;
    font-family: var(--font-family);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
    cursor: pointer;
}

/* Tooltip System */
.tooltip-container {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.tooltip-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    background-color: #666;
    color: #fff;
    border-radius: 50%;
    text-align: center;
    line-height: 16px;
    font-size: 11px;
    font-weight: bold;
    cursor: help;
    margin-left: 6px;
}

.tooltip-icon:hover {
    background-color: var(--accent-color);
}

.tooltip-text {
    visibility: hidden;
    width: max-content;
    max-width: 200px;
    background-color: #1a1a1a;
    color: #fff;
    text-align: center;
    border: 1px solid #ffcc66;
    padding: 6px 10px;
    border-radius: 4px;
    position: absolute;
    z-index: 10;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.2s;
    font-size: 0.8rem;
    font-weight: normal;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    line-height: 1.4;
}

.tooltip-container:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Stats and Inventory Layout */
.stats-layout {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.inventory-grid {
    display: flex;
    gap: 8px;
    background-color: #1a1a1a;
    padding: 8px;
    border: 2px solid #111;
    border-radius: 4px;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
}

.item-slot {
    width: 48px;
    height: 48px;
    background-color: var(--slot-bg);
    border: 2px solid var(--slot-border);
    border-radius: 4px;
    position: relative;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.item-slot:hover {
    background-color: #3a3938;
}

.item-slot img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.item-count {
    position: absolute;
    bottom: -2px;
    right: 2px;
    font-size: 12px;
    font-weight: bold;
    color: #fff;
    text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
}

.power-stats {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background-color: #1a1a1a;
    padding: 10px 16px;
    border-radius: 4px;
    border: 2px solid #111;
    min-width: 200px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.stat-row .stat-label {
    color: var(--text-muted);
}

.stat-row .stat-value {
    font-weight: bold;
    color: #ffcc66;
}

/* Canvas */
.canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #1a1a1a;
    padding: 16px;
    border: 2px solid #111;
    border-radius: 4px;
    overflow: auto;
    max-height: 400px;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
}

canvas {
    image-rendering: pixelated;
    max-width: 100%;
    /* Prevent shrinking weirdly */
    flex-shrink: 0;
}

/* Export Buttons */
.section-export {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

button {
    font-family: var(--font-family);
    font-weight: bold;
    font-size: 0.95rem;
    padding: 10px 16px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.1s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background-color: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    border: 2px solid #b36e10;
    box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), 0 2px 4px rgba(0,0,0,0.5);
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

.btn-primary:active {
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.4);
    transform: translateY(1px);
}

.btn-secondary {
    background-color: var(--btn-secondary-bg);
    color: var(--text-main);
    border: 2px solid var(--btn-secondary-border);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.1), 0 2px 4px rgba(0,0,0,0.5);
}

.btn-secondary:hover:not(:disabled) {
    background-color: #4d4d4d;
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.feedback-text {
    color: #4caf50;
    font-weight: bold;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.3s;
    text-align: center;
}

.feedback-text.show {
    opacity: 1;
}
