@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Press+Start+2P&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-top: #201636;
    --bg-mid: #15102a;
    --bg-bottom: #0a0a12;

    --text: #f6f3ff;
    --muted: rgba(230, 224, 255, 0.78);
    --muted-2: rgba(230, 224, 255, 0.58);

    --line: #5b4b8a;
    --line-strong: #8d79ca;

    --shadow-lg: 10px 10px 0 #05030a;
    --shadow-md: 6px 6px 0 #05030a;

    --radius-xxl: 0;
    --radius-xl: 0;
    --radius-lg: 0;
    --radius-md: 0;

    --container: 1200px;
    --ui-border-gradient: linear-gradient(135deg, #8b5cf6, #38bdf8);
}

html {
    min-height: 100%;
    scroll-behavior: smooth;
    background: radial-gradient(ellipse at top, var(--bg-top) 0%, var(--bg-mid) 48%, var(--bg-bottom) 100%) fixed;
}

body {
    min-height: 100vh;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: transparent;
    position: relative;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding: 20px;
}

button { font: inherit; }
a { color: inherit; text-decoration: none; }

:focus-visible {
    outline: 3px solid rgba(96, 165, 250, 0.32);
    outline-offset: 2px;
}

.scene-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(5, 8, 20, 0.16) 0%, rgba(5, 8, 20, 0.8) 100%);
    opacity: 0.9;
}

.stars {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image:
            radial-gradient(1.5px 1.5px at 25px 35px, rgba(255, 255, 255, 1), rgba(0, 0, 0, 0)),
            radial-gradient(2px 2px at 150px 200px, rgba(210, 190, 255, 0.95), rgba(0, 0, 0, 0)),
            radial-gradient(1px 1px at 50px 160px, rgba(255, 255, 255, 0.95), rgba(0, 0, 0, 0)),
            radial-gradient(1.5px 1.5px at 100px 120px, rgba(255, 255, 255, 1), rgba(0, 0, 0, 0)),
            radial-gradient(1px 1px at 190px 70px, rgba(255, 255, 255, 1), rgba(0, 0, 0, 0)),
            radial-gradient(1.5px 1.5px at 10px 230px, rgba(255, 170, 220, 0.86), rgba(0, 0, 0, 0)),
            radial-gradient(2px 2px at 210px 40px, rgba(255, 220, 140, 0.86), rgba(0, 0, 0, 0)),
            radial-gradient(1.5px 1.5px at 230px 145px, rgba(130, 220, 255, 0.86), rgba(0, 0, 0, 0));
    background-repeat: repeat;
    background-size: 280px 280px;
    opacity: 0.52;
    animation: moveStars 80s linear infinite;
}

@keyframes moveStars {
    from { background-position: 0 0; }
    to { background-position: 500px 1000px; }
}

.grid-overlay {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0.05;
    background-image:
            linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
            linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 84px 84px;
    mask-image: radial-gradient(circle at center, black 14%, transparent 82%);
    -webkit-mask-image: radial-gradient(circle at center, black 14%, transparent 82%);
}

.glow-effect {
    position: fixed;
    width: 620px;
    height: 620px;
    border-radius: 50%;
    filter: blur(110px);
    opacity: 0.14;
    pointer-events: none;
    z-index: 1;
}

.glow-1 {
    top: -220px;
    left: -180px;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.42) 0%, transparent 70%);
    animation: drift 20s ease-in-out infinite;
}

.glow-2 {
    right: -180px;
    bottom: -220px;
    background: radial-gradient(circle, rgba(34, 211, 238, 0.38) 0%, transparent 70%);
    animation: drift 26s ease-in-out infinite reverse;
}

@keyframes drift {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(36px, 28px) scale(1.05); }
}

.container {
    width: min(var(--container), 100%);
    margin: 0 auto;
    position: relative;
    z-index: 10;
}

.site-header { margin-bottom: 18px; }

.header-panel {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
    border: 1px solid rgba(255,255,255,0.12);
    backdrop-filter: blur(22px) saturate(180%);
    -webkit-backdrop-filter: blur(22px) saturate(180%);
    box-shadow: var(--shadow-lg);
    border-radius: 24px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.98), rgba(56, 189, 248, 0.98));
    color: #fff;
    font-weight: 800;
    font-size:1.44rem;
    letter-spacing: 0.14em;
    box-shadow: 0 12px 30px rgba(56, 189, 248, 0.18), 0 8px 22px rgba(139, 92, 246, 0.18);
    flex-shrink: 0;
}

.brand-title {
    font-size: 0.98rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.15;
}

.brand-sub {
    margin-top: 3px;
    font-size: 0.76rem;
    color: rgba(226, 232, 240, 0.58);
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.header-right{
    display:flex;
    align-items:center;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-title h1 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.header-title p {
    margin-top: 4px;
    font-size: 0.78rem;
    color: rgba(226, 232, 240, 0.62);
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.lang-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.lang-btn {
    min-width: 62px;
    height: 38px;
    border-radius: 12px;
    background: transparent;
    color: rgba(255, 255, 255, 0.74);
    font-size: 0.88rem;
    font-weight: 800;
    border: none;
    cursor: pointer;
    transition: all 0.28s ease;
}

.lang-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.lang-btn.is-active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.22), rgba(56, 189, 248, 0.22));
    color: #ffffff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.main-content {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    align-items: flex-start;
}

.toolbar,
.canvas-area {
    background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.03));
    border: 1px solid rgba(255,255,255,0.12);
    backdrop-filter: blur(22px) saturate(180%);
    -webkit-backdrop-filter: blur(22px) saturate(180%);
    box-shadow: var(--shadow-md);
    border-radius: 28px;
}

.toolbar {
    padding: 18px;
    width: 300px;
    flex-shrink: 0;
}

.tool-section { margin-bottom: 18px; }

.tool-section h3 {
    font-size: 0.82rem;
    color: rgba(186, 230, 253, 0.86);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding-bottom: 8px;
}

.size-control {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.size-control label {
    min-width: 54px;
    color: rgba(226, 232, 240, 0.72);
    font-size: 0.9rem;
}

.size-control input[type="number"] {
    width: 76px;
    padding: 9px 10px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    background: rgba(255,255,255,0.05);
    color: #fff;
    text-align: center;
}

.size-control input[type="number"]:focus {
    outline: none;
    border-color: rgba(96, 165, 250, 0.5);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18);
}

.size-control span {
    color: rgba(226, 232, 240, 0.52);
    font-size: 0.9rem;
}

.btn {
    padding: 10px 14px;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    font-size: 0.92rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    transition: transform 0.28s ease, background 0.28s ease, box-shadow 0.28s ease, border-color 0.28s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
    background: linear-gradient(135deg, rgba(139,92,246,.96), rgba(56,189,248,.96));
    color: #fff;
    border: 1px solid rgba(255,255,255,0.12);
    box-shadow: 0 16px 36px rgba(56,189,248,.18), 0 12px 30px rgba(139,92,246,.16);
}
.btn-primary:hover { transform: translateY(-2px); }

.btn-secondary {
    background: rgba(255,255,255,0.055);
    border: 1px solid rgba(255,255,255,0.12);
    color: #fff;
}
.btn-secondary:hover { transform: translateY(-2px); background: rgba(255,255,255,0.08); }

.btn-success {
    background: rgba(34, 197, 94, 0.16);
    color: #b7f7cf;
    border: 1px solid rgba(34, 197, 94, 0.28);
}
.btn-success:hover { background: rgba(34, 197, 94, 0.26); transform: translateY(-2px); }

.btn-danger {
    background: rgba(239, 68, 68, 0.16);
    color: #fecaca;
    border: 1px solid rgba(239, 68, 68, 0.28);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.26); transform: translateY(-2px); }

.tools-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.tool-btn {
    aspect-ratio: 1;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 16px;
    background: rgba(255,255,255,0.05);
    color: #fff;
    cursor: pointer;
    font-size: 1.1rem;
    transition: transform 0.28s ease, background 0.28s ease, border-color 0.28s ease;
}

.tool-btn:hover {
    transform: translateY(-2px);
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.2);
}

.tool-btn.active {
    border-color: rgba(96, 165, 250, 0.55);
    background: linear-gradient(135deg, rgba(139,92,246,.22), rgba(56,189,248,.22));
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
}

.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.color-picker-wrapper input[type="color"] {
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    background: none;
}

.color-preview {
    flex: 1;
    height: 52px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.14);
    background: #000;
}

.palette {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
}

.palette-color {
    aspect-ratio: 1;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.palette-color:hover { transform: scale(1.12); }

.palette-color.selected {
    border-color: rgba(255,255,255,0.9);
    box-shadow: 0 0 0 3px rgba(96,165,250,0.18), 0 0 18px rgba(96,165,250,0.12);
}

.history-buttons { display: flex; gap: 10px; }
.history-buttons .btn { flex: 1; }

.action-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.action-buttons .btn { width: 100%; }

.toggle-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    color: rgba(226, 232, 240, 0.74);
}

.brush-size-control {
    margin-top: 10px;
}

.brush-size-control input[type="range"] {
    width: 110px;
    accent-color: #818cf8;
}

.brush-size-control #brushSizeValue {
    min-width: 56px;
    text-align: right;
}

.toggle { position: relative; width: 50px; height: 26px; }
.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background-color: rgba(255,255,255,0.08);
    transition: 0.4s;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.12);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 2px;
    background-color: rgba(226, 232, 240, 0.74);
    transition: 0.4s;
    border-radius: 50%;
}

.toggle input:checked + .toggle-slider {
    background: linear-gradient(135deg, rgba(139,92,246,.9), rgba(56,189,248,.9));
    border-color: transparent;
}

.toggle input:checked + .toggle-slider:before {
    transform: translateX(24px);
    background-color: #fff;
}

.shortcuts {
    font-size: 0.86rem;
    color: rgba(226, 232, 240, 0.64);
    line-height: 1.7;
}
.shortcuts p { margin: 6px 0; }
.shortcuts kbd {
    background: rgba(255,255,255,0.08);
    padding: 2px 7px;
    border-radius: 6px;
    margin: 0 2px;
    color: rgba(186, 230, 253, 0.92);
    border: 1px solid rgba(255,255,255,0.12);
}

.canvas-area {
    padding: 18px;
    flex: 1;
    min-width: 320px;
    max-width: 100%;
}

.canvas-wrapper {
    width: 100%;
    overflow: auto;
    display: block;
    border-radius: 18px;
    background: rgba(255,255,255,0.03);
    padding: 14px;
}

.canvas-container {
    position: relative;
    width: fit-content;
    margin: 0 auto;
    border: 1px solid rgba(255,255,255,0.14);
    box-shadow: var(--shadow-md);
    border-radius: 0;
    overflow: visible;
    touch-action: none;
}

.canvas-wrapper::-webkit-scrollbar { width: 8px; height: 8px; }
.canvas-wrapper::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); border-radius: 999px; }
.canvas-wrapper::-webkit-scrollbar-thumb { background: rgba(129, 140, 248, 0.45); border-radius: 999px; }
.canvas-wrapper::-webkit-scrollbar-thumb:hover { background: rgba(129, 140, 248, 0.7); }

#pixelCanvas {
    display: block;
}

.canvas-container canvas {
    image-rendering: pixelated;
}

#previewCanvas,
#gridCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.canvas-info {
    margin-top: 14px;
    display: flex;
    gap: 18px;
    color: rgba(226, 232, 240, 0.64);
    font-size: 0.92rem;
}

.zoom-control {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
    color: rgba(226, 232, 240, 0.74);
}

.zoom-control input[type="range"] {
    width: 180px;
    accent-color: #818cf8;
}

@media (max-width: 900px) {
    .main-content { flex-direction: column; }
    .toolbar { width: 100%; }
    .header-panel { flex-direction: column; align-items: flex-start; }
    .header-right { width: 100%; justify-content: space-between; }
}

@media (max-width: 520px) {
    .action-buttons { grid-template-columns: 1fr; }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.scene-bg,
.stars,
.grid-overlay,
.glow-effect {
    display: none;
}

.pixel-flow {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0.2;
    background-image:
            repeating-linear-gradient(90deg, rgba(139, 92, 246, 0.18) 0 8px, transparent 8px 24px),
            repeating-linear-gradient(0deg, rgba(56, 189, 248, 0.12) 0 8px, transparent 8px 24px),
            repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 2px, transparent 2px 10px);
    background-size: 96px 96px, 72px 72px, 36px 36px;
    image-rendering: pixelated;
    animation: pixelFlow 18s linear infinite;
}

@keyframes pixelFlow {
    from {
        background-position: 0 0, 0 0, 0 0;
    }
    to {
        background-position: 360px 180px, -240px 320px, 140px -110px;
    }
}

body {
    background:
            linear-gradient(0deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.18)),
            repeating-linear-gradient(
                    0deg,
                    rgba(255, 255, 255, 0.02) 0,
                    rgba(255, 255, 255, 0.02) 2px,
                    transparent 2px,
                    transparent 4px
            );
}

.brand-title,
.brand-sub,
.header-title h1,
.tool-section h3,
.btn,
.lang-btn,
#zoomLevel,
.canvas-info,
.shortcuts kbd {
    font-family: "Press Start 2P", "Courier New", monospace;
}

.header-panel,
.toolbar,
.canvas-area,
.canvas-wrapper,
.canvas-container,
.lang-container,
.size-control input[type="number"],
.color-preview,
.toggle-slider,
.shortcuts kbd {
    border-radius: 0;
}

.header-panel,
.toolbar,
.canvas-area {
    background: #1a1430;
    border: 3px solid transparent;
    border-image: var(--ui-border-gradient) 1;
    box-shadow: var(--shadow-md);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.btn,
.tool-btn,
.lang-btn {
    border-radius: 0;
    border: 2px solid transparent;
    border-image: var(--ui-border-gradient) 1;
    box-shadow: 3px 3px 0 #0b0814;
    transform: translateY(0);
}

.btn:hover,
.tool-btn:hover,
.lang-btn:hover {
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 #0b0814;
}

.tool-btn.active,
.lang-btn.is-active {
    border-color: #8d79ca;
    background: #35275e;
}

.canvas-wrapper {
    border: 2px solid transparent;
    border-image: var(--ui-border-gradient) 1;
    background: #0e0b19;
}

.canvas-container {
    border: 2px solid transparent;
    border-image: var(--ui-border-gradient) 1;
}

#gridCanvas {
    mix-blend-mode: screen;
}
