/* --- Modern Reset --- */
*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --text-primary: #eee;
    --text-secondary: #888;
    --grid-border: #555;
    --bg-main: #111;
    --magnifier-scale: 16;

}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

.header {
    margin-block-start: 30px;
    text-align: center;
}

h1 {
    margin: 0 0 10px 0;
    font-size: 1.5rem;
    font-weight: 400;
}

#version {
    font-size: 0.5em;
    color: var(--text-secondary);
    vertical-align: middle;
}

p {
    margin: 0 0 15px 0;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.toolbar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #222;
    padding: 6px;
    border-radius: 8px;
    border: 1px solid #444;
}

#colorPicker, .eraser-swatch {
    cursor: pointer;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--text-secondary);
    border-radius: 4px;
    transition: outline 0.1s ease-in-out;
}

#colorPicker {
    background: none;
    border: none;
}

.eraser-swatch {
    background-color: #fff;
    background-image: conic-gradient(#ccc 90deg, #fff 90deg 180deg, #ccc 180deg 270deg, #fff 270deg);
    background-size: 12px 12px;
}

.active-tool {
    outline: 2px solid white;
    outline-offset: 2px;
}

.layout-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    justify-content: flex-start;
    align-items: center;
    width: 100%;
    max-width: 800px;
    flex: 1;
    min-height: 0;
    padding: 20px;
}

/* --- Dropzone --- */
.dropzone {
    width: 100%;
    padding: 20px;
    border: 2px dashed var(--grid-border);
    border-radius: 8px;
    background: #1a1a1a;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

.dropzone.dragover {
    border-style: solid;
    border-color: #fff;
    background: #2a2a2a;
}

#dropzone-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    pointer-events: none;
}

/* --- Editor Grid --- */
.grid-container {
    display: grid;
    grid-template-columns: repeat(var(--grid-size), 1fr);
    grid-template-rows: repeat(var(--grid-size), 1fr);
    width: 100%;
    aspect-ratio: 1;

    /* The Grid-Gap Trick */
    gap: 1px;
    background-color: var(--grid-border); /* This draws the inner lines */
    border: 1px solid var(--grid-border); /* Outer edge */

    touch-action: none;
}

.pixel {
    user-select: none;
    /* Move checkerboard to the individual pixel */
    background-image: conic-gradient(#333 90deg, #222 90deg 180deg, #333 180deg 270deg, #222 270deg);
    background-size: 50% 50%; /* 4 squares perfectly fit the cell regardless of size */
}

/* --- Output Panel --- */
#output-panel {
    width: 100%;
    margin-top: 20px;
    background: #1a1a1a;
    border-top: 1px solid var(--grid-border);
    padding: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.log-column {
    background: #111;
    border: 1px solid var(--grid-border);
    border-radius: 4px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    flex-basis: max-content;
    flex-grow: 1;
    max-width: 100%;
}

.log-column h3 {
    margin: 0 0 10px 0;
    font-size: 1rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--grid-border);
    padding-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.log-content {
    margin: 0;
    font-family: monospace;
    font-size: 0.9rem;
    color: #0f0;
    white-space: pre-wrap;
    line-height: 1.4;
    overflow-x: auto;
    flex: 1;
}

/* --- Preview Containers --- */
.preview-container {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    align-items: center;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--grid-border);
    flex-wrap: wrap;
}

.preview-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-right: 5px;
}

.preview-box {
    /* Dynamically sized */
    width: calc(var(--grid-size) * 1px);
    height: calc(var(--grid-size) * 1px);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--grid-border);
    cursor: crosshair;
}

.preview-box img {
    image-rendering: pixelated;
    width: 100%;
    height: 100%;
}

.bg-white { background-color: #ffffff; }
.bg-grey  { background-color: #888888; }
.bg-black { background-color: #000000; }
.bg-red   { background-color: #ff0000; }
.bg-green { background-color: #00ff00; }
.bg-blue  { background-color: #0000ff; }

/* --- Magnifier --- */
.magnifier {
    position: fixed;
    /* Dynamically sized */
    width: calc(var(--grid-size) * 1px * var(--magnifier-scale));
    height: calc(var(--grid-size) * 1px * var(--magnifier-scale));
    pointer-events: none;
    display: none;
    z-index: 9999;
    border: 1px solid var(--text-secondary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
    transform: translateY(-100%);
}

.magnifier img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    display: block;
}

/* --- Save Actions & Usage --- */
.save-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
}

.btn {
    padding: 10px 15px;
    color: var(--text-primary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.1s ease-in-out;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #333;
    border: 1px solid #888;
    font-weight: bold;
}

.btn-primary:hover:not(:disabled) {
    background: #444;
    border-color: #fff;
}

.btn-secondary {
    background: #2a2a2a;
    border: 1px solid var(--grid-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.btn-secondary:hover:not(:disabled) {
    background: #3a3a3a;
}

.btn-secondary span {
    color: var(--text-secondary);
    font-size: 0.85em;
}

.usage-section {
    width: 100%;
    background: #111;
    border: 1px solid var(--grid-border);
    border-radius: 4px;
    padding: 15px;
}

.usage-section h3 {
    margin: 0 0 10px 0;
    font-size: 1rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--grid-border);
    padding-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.usage-section code {
    display: block;
    color: #0f0;
    margin-top: 8px;
    font-family: monospace;
    font-size: 0.9rem;
}
