:root {
    --bg: #1a1a2e;
    --card: #16213e;
    --accent: #e94560;
    --primary: #3949ab;
    --text: #fff;
    --cell-bg: #1e2a45;
    --cell-given: #0f3460;
    --cell-border: #2a3f6f;
    --box-border: #7a9cc4;
    --highlight-row: rgba(57, 73, 171, 0.2);
    --highlight-same: rgba(57, 73, 171, 0.35);
    --highlight-sel: rgba(233, 69, 96, 0.35);
    --wrong-color: #e53935;
    --box-complete: #2e7d32;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', sans-serif; user-select: none; }

body {
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
    overflow-x: hidden;
    touch-action: manipulation;
}

.app-container {
    width: 100%;
    max-width: min(800px, 50vh); /*BUNLARIN HEPSI 480DI DEGISTIRDIM AMA LANDSCAPE BOK SU AN*/
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 10px;
    min-height: 100dvh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 10px; }
h1 { font-size: 1.8rem; color: var(--accent); }

.global-hub-btn {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; background: rgba(255,255,255,0.1);
    border-radius: 8px; text-decoration: none; font-size: 1.5rem;
    border: 1px solid rgba(255,255,255,0.2); transition: 0.2s;
}
.global-hub-btn:active { transform: scale(0.9); }

select {
    background: var(--card); color: #fff;
    padding: 6px 10px; border-radius: 6px;
    border: 1px solid var(--accent); font-size: 0.95rem; outline: none;
    touch-action: manipulation;
}

/* Controls */
.controls-bar {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.difficulty-tabs {
    display: flex;
    gap: 6px;
    width: 100%;
}

.diff-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: var(--card);
    color: #aaa;
    font-weight: bold;
    font-size: 0.95rem;
    cursor: pointer;
    transition: 0.2s;
    touch-action: manipulation;
}
.diff-btn.active { background: var(--primary); color: #fff; }
.diff-btn:active { transform: scale(0.97); }

.action-btns {
    display: flex;
    gap: 6px;
    width: 100%;
}

.btn {
    flex: 1;
    padding: 10px 6px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    transition: 0.2s;
    white-space: nowrap;
    touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn.secondary { background: #2c3e6b; }
.btn.secondary.active { background: var(--accent); }
.btn.danger { background: #e53935; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Board */
.board-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    max-height: fit-content;
    padding: 2vh 0 2vh 0;
}

.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: min(100%, 100vmin - 20px, 800px);
    max-width: 800px;
    aspect-ratio: 1;
    border: 3px solid var(--box-border);
    border-radius: 6px;
    overflow: hidden;
    background: var(--cell-border);
    gap: 1px;
}

.sudoku-cell {
    background: var(--cell-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1rem, 4vw, 1.6rem);
    font-weight: bold;
    cursor: pointer;
    position: relative;
    transition: background 0.1s;
    -webkit-tap-highlight-color: transparent;
}

/* Box borders: thicker lines every 3 cells */
.sudoku-cell.box-right  { border-right: 2px solid var(--box-border); }
.sudoku-cell.box-bottom { border-bottom: 2px solid var(--box-border); }

.sudoku-cell.given {
    background: var(--cell-given);
    color: #a8d0f5;
}

.sudoku-cell.selected { background: var(--highlight-sel) !important; }
.sudoku-cell.highlight-row { background: var(--highlight-row); }
.sudoku-cell.highlight-same { background: var(--highlight-same); }

.sudoku-cell.wrong {
    color: var(--wrong-color) !important;
    font-weight: 900;
}

.sudoku-cell.box-complete {
    border: 2px solid var(--box-complete) !important;
}

/* Correctly placed user cell - locked */
.sudoku-cell.correct {
    color: #a8e6b0;
    cursor: default;
}

/* Box complete animation */
@keyframes boxFlash {
    0%   { box-shadow: inset 0 0 0 3px #4caf50; }
    50%  { box-shadow: inset 0 0 0 3px #a5d6a7; background: rgba(76,175,80,0.18); }
    100% { box-shadow: inset 0 0 0 2px var(--box-complete); }
}
.sudoku-cell.box-animate { animation: boxFlash 0.5s ease; }

/* Notes grid inside cell */
.cell-notes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0; left: 0;
    pointer-events: none;
}

.cell-note-num {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(0.5rem, 2vw, 0.8rem);
    font-weight: normal;
    color: rgba(168, 208, 245, 0.55);
    line-height: 1;
}
.cell-note-num.ghost { color: rgba(168, 208, 245, 0.25); font-style: italic; font-family: monospace;}
.cell-note-num.user  { color: rgba(255, 220, 100, 0.75); }

/* Numpad */
.numpad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 480px;
    padding-bottom: 10px;
    flex-shrink: 0;
}

.num-btn {
    aspect-ratio: 1;
    border: none;
    border-radius: 10px;
    background: var(--card);
    color: #fff;
    font-size: clamp(1.2rem, 5vw, 2rem);
    font-weight: bold;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    border: 1px solid rgba(255,255,255,0.08);
    -webkit-tap-highlight-color: transparent;
}
.num-btn:active { background: var(--primary); transform: scale(0.92); }
.num-btn.erase-btn { background: #2c2c3e; color: var(--accent); grid-column: span 1; }
.num-btn.disabled-num { opacity: 0.3; pointer-events: none; }

/* Modals */
.modal {
    display: none;
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.75);
    z-index: 100;
    justify-content: center; align-items: center;
    padding: 1rem;
}
.modal-content {
    background: var(--card);
    padding: 24px;
    border-radius: 14px;
    max-width: 380px;
    width: 100%;
    text-align: center;
}
.modal-content h2 { font-size: 1.6rem; color: var(--accent); margin-bottom: 0.7rem; }
.modal-content p { opacity: 0.85; margin-bottom: 0.5rem; line-height: 1.5; }
.modal-btns { display: flex; gap: 10px; margin-top: 1rem; }
.modal-btns .btn { flex: 1; }

/* Responsive */
@media (max-width: 400px) {
    .action-btns { flex-wrap: wrap; }
    .btn { font-size: 0.8rem; padding: 8px 4px; }
}
