/* PixelLand - Pixel Boyama / Yansıma / Şekil Tamamlama */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f0f1a;
    --panel-bg: #1a1a2e;
    --panel-border: #2a2a40;
    --text: #e0e0e0;
    --muted: #8892b0;
    --accent: #9b59b6;
    --accent-hover: #8e44ad;
    --success: #27ae60;
    --warning: #f59e0b;
    --danger: #e74c3c;
    --pool-bg: #1e1e30;
}

html, body {
    width: 100%;
    height: 100%;
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
}

.hidden { display: none !important; }

/* ============ HEADER ============ */
#game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
    z-index: 50;
}

#header-left { display: flex; align-items: baseline; gap: 16px; }
#header-left h1 { font-size: 1.4rem; color: #ffd700; letter-spacing: 1px; }
#level-info { font-size: 0.9rem; color: var(--muted); }

#header-controls { display: flex; gap: 8px; }

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}
.btn:hover { transform: translateY(-1px); opacity: 0.9; }
.btn:active { transform: translateY(0); }
.btn-run { background: var(--success); }
.btn-run:hover { background: #2ecc71; }
.btn-reset { background: #7f8c8d; }
.btn-reset:hover { background: #95a5a6; }
.btn-hint { background: var(--warning); }
.btn-hint:hover { background: #d97706; }
.btn-icon { background: #2c3e7a; padding: 8px 12px; }
.btn-icon:hover { background: #3a4f9e; }

/* ============ MODE SELECT (Tür seçimi) ============ */
#mode-select-screen {
    position: absolute;
    inset: 0;
    top: 49px;
    z-index: 90;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    padding: 30px 20px;
}

#mode-select-content { text-align: center; max-width: 900px; width: 100%; }
#mode-select-content h2 { font-size: 1.8rem; margin-bottom: 28px; color: #a0d8ef; }

.mode-cards {
    display: flex;
    gap: 24px;
    justify-content: center;
    flex-wrap: wrap;
}

.mode-card {
    background: var(--pool-bg);
    border: 2px solid var(--panel-border);
    border-radius: 14px;
    padding: 32px 28px;
    width: 240px;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, background 0.15s;
}
.mode-card:hover {
    transform: translateY(-5px);
    border-color: var(--accent);
    background: #252540;
}
.mode-card .mode-icon { font-size: 3.2rem; margin-bottom: 14px; }
.mode-card h3 { font-size: 1.25rem; margin-bottom: 8px; color: var(--text); }
.mode-card p { font-size: 0.85rem; color: var(--muted); line-height: 1.4; }

/* ============ LEVEL SELECT ============ */
#level-select-screen {
    position: absolute;
    inset: 0;
    top: 49px;
    z-index: 80;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    overflow-y: auto;
    padding: 40px 20px;
}

#level-select-header { display: flex; align-items: center; gap: 16px; }
#level-select-header h2 { font-size: 1.8rem; font-weight: 700; color: #a0d8ef; }
#level-select-header .back-btn { font-size: 1.1rem; }

#level-select-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 5), 1fr);
    gap: 14px;
    width: 100%;
    max-width: 720px;
}

.level-slot {
    aspect-ratio: 1;
    background: var(--pool-bg);
    border: 2px solid var(--panel-border);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, background 0.15s;
    padding: 4px;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.level-slot:hover {
    transform: translateY(-3px);
    border-color: var(--accent);
    background: #252540;
}
.level-slot .slot-number { font-size: 1.3rem; font-weight: 700; color: #a0d8ef; }
.level-slot .slot-name { font-size: 0.75rem; color: #8888a8; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.level-slot .slot-thumb { width: 70%; aspect-ratio: 1; margin-bottom: 4px; image-rendering: pixelated; border-radius: 4px; }
.level-slot.empty { visibility: hidden; pointer-events: none; }
.level-slot.locked { opacity: 0.4; cursor: not-allowed; border-color: var(--panel-bg); background: #141420; }
.level-slot.locked:hover { transform: none; border-color: var(--panel-bg); background: #141420; }
.level-slot.completed { border-color: #3a7a3a; background: #1a2e1a; }
.level-slot.completed:hover { border-color: #5aaa5a; background: #224422; }
.level-slot .slot-stars { font-size: 0.7rem; margin-top: 2px; line-height: 1; }

#level-select-dots { display: flex; gap: 10px; align-items: center; justify-content: center; }
.level-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: #2a2a40; cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}
.level-dot:hover { background: #5a5a8e; }
.level-dot.active { background: var(--accent); transform: scale(1.3); }

/* ============ GAME MAIN LAYOUT ============ */
#game-main {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

#side-panel {
    width: 240px;
    min-width: 200px;
    flex-shrink: 0;
    background: var(--panel-bg);
    border-right: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#side-panel-header {
    padding: 10px 14px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--muted);
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#side-panel-body {
    flex: 4;
    min-height: 0;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Hatalı hücreler - sol panelin alt ~%20'si */
#wrong-panel {
    flex: 1;
    min-height: 64px;
    border-top: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#wrong-panel-header {
    padding: 7px 14px;
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--danger);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
#wrong-panel-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 2px 10px 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    align-content: flex-start;
}

/* Görev koordinat kodları - her kod kendi hedef renginde, yan yana akar */
.task-codes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 6px 4px;
}
.task-code {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.5px;
    cursor: default;
    font-variant-numeric: tabular-nums;
}
.task-code.new-group { margin-left: 10px; }
.task-code.done { opacity: 0.3; text-decoration: line-through; }

.side-note {
    color: var(--muted);
    font-size: 0.85rem;
    line-height: 1.55;
    padding: 8px 4px;
}

/* Komut chip'leri (şekil modu) - minimalist */
.cmd-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 7px;
    border-radius: 5px;
    background: var(--pool-bg);
    border: 1px solid transparent;
    font-size: 0.8rem;
    flex-shrink: 0;
}
.cmd-item .cmd-icon { font-size: 0.95rem; text-align: center; line-height: 1; }
.cmd-item .cmd-count { font-weight: 700; font-size: 0.78rem; color: #ffd700; }
.cmd-item .cmd-color { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(255,255,255,0.3); }
/* Şekil modunda sol panel 2,5 kat genişler, komutlar yan yana akar */
#game-main.mode-shape #side-panel { width: 600px; min-width: 520px; }

.cmd-flow {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 2px;
    align-content: flex-start;
}
.cmd-flow .cmd-item { flex-shrink: 0; }

.cmd-item.current { border-color: var(--accent); background: #252545; box-shadow: 0 0 8px rgba(155, 89, 182, 0.4); }
.cmd-item.done { opacity: 0.35; }
.cmd-item.done::after { content: '✓'; color: var(--success); margin-left: auto; font-weight: 700; }

/* ============ CENTER / GRID ============ */
#center-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

#grid-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px;
    overflow: auto;
    min-height: 0;
}

#status-bar {
    min-height: 24px;
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
#status-text.error { color: var(--danger); font-weight: 600; }

#side-panel-counter .counter-errors { color: var(--danger); font-weight: 700; }

#pixel-grid-wrap {
    flex: 1;
    min-height: 0;
    min-width: 0;
    width: 100%;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

#pixel-grid-outer {
    display: inline-grid;
    gap: 0;
    touch-action: none;
    user-select: none;
    background: #14142a;
    padding: 0;
}

.axis-label {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    overflow: hidden;
}
.axis-corner { background: transparent; }

.px-cell {
    border: 1px solid #23233a;
    background: #191932;
    cursor: pointer;
    position: relative;
}
.px-cell:hover { outline: 1px solid var(--accent); z-index: 2; }
.px-cell.given { cursor: default; }
.px-cell.given:hover { outline: none; }
.px-cell.axis-cell { background: #20204a; cursor: default; }
.px-cell.axis-cell:hover { outline: none; }
.px-cell.flash-error { animation: cellError 0.35s; }
.px-cell.flash-ok { animation: cellOk 0.3s; }

@keyframes cellError {
    0%, 100% { box-shadow: inset 0 0 0 2px transparent; }
    50% { box-shadow: inset 0 0 0 3px var(--danger); background: #5a1f1f; }
}
@keyframes cellOk {
    0% { transform: scale(0.7); }
    60% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

/* Şekil modu kalemi */
.px-cell.pen::after {
    content: '';
    position: absolute;
    inset: 12%;
    border: 2px solid #ffd700;
    border-radius: 3px;
    box-shadow: 0 0 6px rgba(255, 215, 0, 0.8);
    pointer-events: none;
}
.px-cell.pen::before {
    content: '✏️';
    position: absolute;
    top: -55%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1em;
    z-index: 3;
    pointer-events: none;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6));
}
.px-cell.start-marker { box-shadow: inset 0 0 0 2px #ffd700; }

/* Yansıma ekseni çizgisi */
.px-cell.mirror-edge-v { border-right: 2px dashed #6a6aa0; }
.px-cell.mirror-edge-h { border-bottom: 2px dashed #6a6aa0; }

/* ============ RIGHT PANEL (palet + şekil kontrolleri) ============ */
#right-panel {
    width: 200px;
    min-width: 176px;
    flex-shrink: 0;
    background: var(--panel-bg);
    border-left: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    padding: 16px 10px;
    overflow-y: auto;
}

#palette-bar { width: 100%; }

#game-palette { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.game-swatch {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: transform 0.12s, border-color 0.12s;
    padding: 0;
}
.game-swatch:hover { transform: scale(1.12); }
.game-swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent), 0 0 10px rgba(155,89,182,0.6); }

.game-swatch.eraser-swatch {
    background: var(--pool-bg);
    border-style: dashed;
    border-color: #55557a;
    font-size: 1.1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.game-swatch.eraser-swatch.active { border-color: var(--danger); border-style: solid; }

/* ============ SHAPE CONTROLS (3x3 tuş takımı, ortada boya) ============ */
#shape-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}

#arrow-pad {
    display: grid;
    grid-template-columns: repeat(3, 54px);
    grid-template-rows: repeat(3, 54px);
    gap: 6px;
}

.arrow-btn {
    background: #2c3e7a;
    border: 2px solid var(--panel-border);
    border-radius: 8px;
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
    transition: background 0.12s, transform 0.12s;
}
.arrow-btn:hover { background: #3a4f9e; }
.arrow-btn:active { transform: scale(0.93); }
.arrow-btn.shake { animation: btnShake 0.3s; }

.arrow-btn.paint-btn { background: #2c3e7a; padding: 0; }
.arrow-btn.paint-btn:hover { filter: brightness(1.15); }
.arrow-btn.paint-btn .paint-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 68%;
    height: 68%;
    margin: auto;
    background: #ffffff;
    border-radius: 50%;
    font-size: 1.05rem;
    line-height: 1;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.2), 0 1px 3px rgba(0,0,0,0.3);
}

@keyframes btnShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ============ MODALS ============ */
#description-overlay, #complete-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    padding: 30px;
    max-width: 440px;
    width: 90%;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.modal h2 { color: #ffd700; }
.modal p { color: var(--muted); }

#description-modal-body {
    color: var(--text);
    font-size: 1rem;
    line-height: 1.55;
    text-align: left;
    max-height: 50vh;
    overflow-y: auto;
    white-space: pre-line;
}

#complete-stars { font-size: 2.2rem; letter-spacing: 6px; }
#complete-preview canvas { image-rendering: pixelated; border-radius: 8px; border: 1px solid var(--panel-border); max-width: 100%; }

/* ============ HINT OVERLAY ============ */
#hint-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 190;
    pointer-events: none;
}
#hint-grid-outer {
    display: inline-grid;
    gap: 0;
    background: #14142a;
    border: 3px solid #ffd700;
    border-radius: 6px;
    overflow: hidden;
}
.hint-cell { border: none; }

/* ============ COLOR ALERT + GUIDE (şekil modu uyarıları) ============ */
#color-alert-overlay, #guide-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 25, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 150;
}

/* Uyarı açıkken sadece hedef bileşen blur'un üstünde kalır */
#palette-bar.palette-spotlight {
    position: relative;
    z-index: 160;
    border-radius: 10px;
    box-shadow: 0 0 0 3px var(--accent), 0 0 22px rgba(155, 89, 182, 0.75);
}
#shape-controls.guide-spotlight { position: relative; z-index: 160; }

.color-alert-tip {
    position: fixed;
    right: 218px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--panel-bg);
    border: 2px solid var(--accent);
    border-radius: 12px;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.55);
    animation: tipPop 0.25s ease;
}
.color-alert-tip::after {
    content: '';
    position: absolute;
    right: -14px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 9px solid transparent;
    border-bottom: 9px solid transparent;
    border-left: 13px solid var(--accent);
}
.color-alert-tip.tip-below { animation: tipPopBelow 0.25s ease; }
.color-alert-tip.tip-below::after {
    right: auto;
    left: 50%;
    top: auto;
    bottom: -14px;
    transform: translateX(-50%);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 13px solid var(--accent);
    border-bottom: none;
}
.color-alert-title { font-weight: 700; color: #ffd700; font-size: 0.95rem; }
.color-alert-chip {
    width: 44px;
    height: 44px;
    border-radius: 9px;
    border: 2px solid #fff;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.35);
}
.color-alert-text { font-size: 0.8rem; color: var(--text); text-align: center; max-width: 190px; }
.color-alert-text.muted { color: var(--muted); font-size: 0.75rem; }

@keyframes tipPop {
    from { transform: translateY(-50%) scale(0.8); opacity: 0; }
    to   { transform: translateY(-50%) scale(1);   opacity: 1; }
}
@keyframes tipPopBelow {
    from { transform: translateX(-50%) scale(0.8); opacity: 0; }
    to   { transform: translateX(-50%) scale(1);   opacity: 1; }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 860px) {
    #side-panel {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        min-width: 0;
        height: 34%;
        border-right: none;
        border-top: 1px solid var(--panel-border);
        z-index: 60;
    }
    #side-panel-body { flex-direction: row; flex-wrap: wrap; align-content: flex-start; }
    .cmd-item { flex: 0 0 auto; }
    #game-main.mode-shape #side-panel { width: 100%; min-width: 0; }

    /* Sağ panel mobilde alt şerit olur (sol panelin üstünde) */
    #right-panel {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 34%;
        width: 100%;
        min-width: 0;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 16px;
        padding: 8px 10px;
        border-left: none;
        border-top: 1px solid var(--panel-border);
        z-index: 55;
        overflow-x: auto;
        overflow-y: hidden;
        max-height: 36%;
    }
    #game-palette { flex-wrap: nowrap; }
    .game-swatch { width: 32px; height: 32px; }
    #arrow-pad {
        grid-template-columns: repeat(3, 44px);
        grid-template-rows: repeat(3, 44px);
    }
    .arrow-btn { font-size: 1.15rem; }
    .arrow-btn.paint-btn { font-size: 1.25rem; }

    #header-left h1 { font-size: 1.1rem; }
    .mode-card { width: 100%; max-width: 320px; padding: 22px; }
}
