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

:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #3a3a3a;
    --bg-hover: #4a4a4a;
    --accent-red: #8b0000;
    --accent-red-light: #a52a2a;
    --accent-red-bright: #c0392b;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --text-muted: #888888;
    --border: #555555;
    --border-light: #666666;
    --canvas-grid: #444444;
    --canvas-bg: #333333;
    --success: #27ae60;
    --warning: #f39c12;
    --error: #e74c3c;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
}

.header {
    text-align: center;
    padding: 12px 0 16px;
    border-bottom: 2px solid var(--accent-red);
    margin-bottom: 20px;
}

.header__title {
    font-size: 24px;
    color: var(--text-primary);
    letter-spacing: 2px;
}

.header__subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.main {
    display: grid;
    grid-template-columns: 280px 1fr 220px;
    gap: 16px;
    align-items: start;
}

.editor {
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.tabs {
    display: flex;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: 10px 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.tab:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.tab--active {
    color: var(--text-primary);
    border-bottom-color: var(--accent-red);
    background: var(--bg-secondary);
}

.panels {
    padding: 14px;
}

.panel {
    display: none;
}

.panel--active {
    display: block;
}

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

.panel__hint {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

.tool-row {
    display: flex;
    gap: 6px;
}

.label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 4px;
}

.label--small {
    font-size: 11px;
    margin-top: 0;
}

.style-selectors {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    border: 1px solid var(--border);
}

.style-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.style-group .label {
    min-width: 50px;
    flex-shrink: 0;
}

.input--compact {
    padding: 5px 8px;
    font-size: 11px;
}

.input {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.input:focus {
    border-color: var(--accent-red-light);
}

.input--textarea {
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
}

.input--select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

.input--small {
    width: auto;
    flex: 1;
    padding: 4px 8px;
    font-size: 12px;
    font-family: monospace;
}

.btn {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

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

.btn--primary {
    background: var(--accent-red);
    border-color: var(--accent-red-light);
}

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

.btn--primary:disabled {
    background: var(--bg-tertiary);
    border-color: var(--border);
}

.btn--small {
    padding: 5px 10px;
    font-size: 11px;
}

.btn--small.btn--active {
    background: var(--accent-red);
    border-color: var(--accent-red-light);
}

.btn--full {
    width: 100%;
}

.status {
    font-size: 12px;
    padding: 6px 8px;
    border-radius: 4px;
    display: none;
}

.status--loading {
    display: block;
    background: rgba(243, 156, 18, 0.15);
    color: var(--warning);
    border: 1px solid rgba(243, 156, 18, 0.3);
}

.status--success {
    display: block;
    background: rgba(39, 174, 96, 0.15);
    color: var(--success);
    border: 1px solid rgba(39, 174, 96, 0.3);
}

.status--error {
    display: block;
    background: rgba(231, 76, 60, 0.15);
    color: var(--error);
    border: 1px solid rgba(231, 76, 60, 0.3);
}

.canvas-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.canvas-wrapper {
    background: var(--bg-secondary);
    border: 2px solid var(--accent-red);
    border-radius: 4px;
    padding: 2px;
    display: inline-block;
}

#texture-canvas {
    display: block;
    cursor: crosshair;
    image-rendering: pixelated;
}

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

.preview-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#preview-canvas {
    width: 48px;
    height: 48px;
    image-rendering: pixelated;
}

.preview-box--tiled {
    overflow: hidden;
}

#preview-tiled {
    width: 96px;
    height: 96px;
    image-rendering: pixelated;
}

.sidebar {
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.palette-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.current-color {
    display: flex;
    align-items: center;
    gap: 8px;
}

.current-color__swatch {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 2px solid var(--border-light);
    background: #5B8731;
    flex-shrink: 0;
}

.palette {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 3px;
}

.palette__color {
    width: 100%;
    aspect-ratio: 1;
    border: 1px solid var(--border);
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.15s;
}

.palette__color:hover {
    transform: scale(1.15);
    border-color: var(--text-primary);
    z-index: 1;
}

.palette__color--active {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--accent-red);
}

.palette__color--transparent {
    background: repeating-conic-gradient(#666 0% 25%, #999 0% 50%) 50%/8px 8px;
}

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

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 6px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
    font-size: 13px;
}

.upload-zone:hover {
    border-color: var(--accent-red-light);
    background: rgba(139, 0, 0, 0.05);
}

.upload-zone--dragover {
    border-color: var(--accent-red);
    background: rgba(139, 0, 0, 0.1);
}

.gradient-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.gradient-pickers {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gradient-picker {
    width: 40px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    background: var(--bg-tertiary);
    padding: 2px;
}

.gradient-arrow {
    color: var(--text-muted);
    font-size: 18px;
}

.gradient-row {
    display: flex;
    gap: 3px;
}

.gradient-row .palette__color {
    flex: 1;
    aspect-ratio: 1;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 4px;
}

.history-grid::-webkit-scrollbar {
    width: 4px;
}

.history-grid::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.history-item {
    position: relative;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.history-item:hover {
    border-color: var(--accent-red-light);
    transform: scale(1.03);
}

.history-item__img {
    width: 100%;
    aspect-ratio: 1;
    image-rendering: pixelated;
    border-radius: 2px;
    background: repeating-conic-gradient(#2a2a2a 0% 25%, #333 0% 50%) 50%/8px 8px;
}

.history-item__label {
    font-size: 9px;
    color: var(--text-muted);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
    line-height: 1.2;
}

.history-item__method {
    font-size: 8px;
    color: var(--accent-red-light);
    text-align: center;
}

.history-item__delete {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border: none;
    border-radius: 2px;
    background: rgba(0, 0, 0, 0.6);
    color: var(--text-muted);
    font-size: 10px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}

.history-item:hover .history-item__delete {
    display: flex;
}

.history-item__delete:hover {
    background: var(--error);
    color: var(--text-primary);
}

.progress-bar {
    display: none;
    flex-direction: column;
    gap: 4px;
}

.progress-bar--active {
    display: flex;
}

.progress-bar__track {
    width: 100%;
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.progress-bar__fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-red), var(--accent-red-bright));
    border-radius: 3px;
    transition: width 0.4s ease;
}

.progress-bar__fill--animated {
    animation: progress-pulse 1.5s ease-in-out infinite;
}

.progress-bar__label {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
}

@keyframes progress-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

@media (max-width: 900px) {
    .main {
        grid-template-columns: 1fr;
    }
    .sidebar {
        order: -1;
    }
    .palette {
        grid-template-columns: repeat(10, 1fr);
    }
}

.gui-calc-result {
    color: #a0a0a0;
    font-size: 0.75rem;
    margin-left: 6px;
    white-space: nowrap;
}

.color-adjust-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.color-adjust-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 8px 0;
}

.color-adjust__original,
.color-adjust__result {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 2px solid var(--border);
}

.slider-group {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.slider-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    width: 58px;
    flex-shrink: 0;
}

.slider-value {
    font-size: 0.7rem;
    color: var(--text-secondary);
    width: 28px;
    text-align: right;
    flex-shrink: 0;
}

.color-slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-secondary);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.color-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-primary);
    border: 2px solid var(--border);
    cursor: pointer;
}

.color-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-primary);
    border: 2px solid var(--border);
    cursor: pointer;
}

.color-slider--hue {
    background: linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000);
}

.color-slider--sat {
    background: linear-gradient(to right, #808080, #ff4444);
}

.color-slider--bri {
    background: linear-gradient(to right, #000000, #ffffff);
}

.color-slider--con {
    background: linear-gradient(to right, #808080, #000000 50%, #ffffff);
}

.btn--tiny {
    padding: 3px 8px;
    font-size: 0.7rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 3px;
    cursor: pointer;
}

.btn--tiny:hover {
    background: var(--accent-red);
}

.canvas-tools {
    display: flex;
    gap: 6px;
    justify-content: center;
}
