/* Sudoku Grid */
.sudoku-grid {
    display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr);
    height: 70dvh; width: 70dvh; max-width: 95vw; max-height: 95vw;
    background: var(--grid-border-color, var(--text-color)); border: 2px solid var(--grid-border-color, var(--text-color));
    box-shadow: 0 0 30px var(--cell-highlight), 0 10px 30px rgba(0,0,0,0.25);
    touch-action: none;
    transition: border-color 0.3s, box-shadow 0.3s;
}
.sudoku-grid.pencil-mode-active {
    border-color: var(--primary);
    box-shadow: 0 0 40px var(--primary), 0 10px 30px rgba(0,0,0,0.25);
}
.grid-cell { background: var(--cell-bg); border: 0.5px solid rgba(128,128,128,0.2); display: flex; align-items: center; justify-content: center; position: relative; cursor: pointer; user-select: none; -webkit-user-select: none; transition: background 0.1s; }
.grid-cell:nth-child(3n) { border-right-width: 2px; border-right-color: var(--grid-border-color, var(--text-color)); }
.grid-cell:nth-child(n+19):nth-child(-n+27),
.grid-cell:nth-child(n+46):nth-child(-n+54) { border-bottom-width: 2px; border-bottom-color: var(--grid-border-color, var(--text-color)); }
.grid-cell:nth-child(9n) { border-right-width: 0px; }
.cell-value { font-size: min(6vw, 5.5dvh); font-weight: 600; }
.preloaded-cell .cell-value { color: var(--cell-preloaded-color); }
.user-cell .cell-value { color: var(--cell-user-color); }

/* Cell States */
.active-cell { background: var(--cell-active); }
.highlight-cell { background: var(--cell-highlight); }
.invalid-cell { background: var(--cell-invalid); animation: shake 0.3s; }
.hint-highlight { background: rgba(0, 255, 0, 0.2); }
.hint-target { background: rgba(0, 255, 0, 0.8); }
.hint-elimination { background: rgba(231, 76, 60, 0.4); }
.mini-sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 11.111%);
    grid-template-rows: repeat(9, 11.111%);
    width: 100%;
    height: auto;
    max-width: 100%;
    aspect-ratio: 1;
    background: var(--grid-border-color, var(--text-color));
    border: 2px solid var(--grid-border-color, var(--text-color));
    margin: 0 auto;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    container-type: inline-size;
}
.mini-grid-cell {
    background: var(--cell-bg);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; color: var(--text-color);
    border: 0.5px solid rgba(128,128,128,0.2);
    position: relative;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
}
.mini-grid-cell.border-right { border-right: 2px solid var(--grid-border-color, var(--text-color)); }
.mini-grid-cell.border-bottom { border-bottom: 2px solid var(--grid-border-color, var(--text-color)); }
.mini-scratch-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
}
.mini-scratch-pad-digit {
    font-size: 0.4em;
    font-size: 3cqi;
    color: var(--text-color);
    opacity: 0.7;
    display: flex;
    justify-content: center;
    align-items: center;
}
.hint-target .mini-scratch-pad-digit,
.hint-target .scratch-pad-digit {
    opacity: 1;
    font-weight: 800;
}

@keyframes anim-eliminate-digit {
    0%, 15% { opacity: 0.7; transform: scale(1); color: var(--text-color); }
    30%, 45% { opacity: 1; transform: scale(2); color: var(--cell-invalid); }
    60%, 100% { opacity: 0; transform: scale(0); }
}
.anim-eliminate { animation: anim-eliminate-digit 4s ease-in-out infinite; }

@keyframes anim-fade-out-late {
    0%, 45% { opacity: 0.7; }
    60%, 100% { opacity: 0; }
}
.anim-fade-out-late { animation: anim-fade-out-late 4s ease-in-out infinite; }

@keyframes anim-resolve-value {
    0%, 50% { opacity: 0; transform: scale(0.5); }
    65%, 85% { opacity: 1; transform: scale(1.3); color: var(--primary); }
    100% { opacity: 1; transform: scale(1); color: var(--text-color); }
}
.anim-resolve-value {
    position: absolute; font-size: 1.1em; font-size: 8cqi; font-weight: 600;
    animation: anim-resolve-value 4s ease-in-out infinite;
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 100%; top: 0; left: 0;
}

@keyframes mini-target-pulse { 0%, 100% { background: var(--cell-bg); } 15%, 30% { background: rgba(0, 255, 0, 0.8); } }
.mini-grid-cell.hint-target { animation: mini-target-pulse 4s ease-in-out infinite; }

.blink { animation: blinker 1s linear infinite; }
@keyframes blinker { 50% { opacity: 0; } }
@keyframes shake { 0%, 100% {transform: translateX(0);} 25% {transform: translateX(-3px);} 75% {transform: translateX(3px);} }
@keyframes pulse-text { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.4); color: var(--primary); } }
.pulse-text span {
    animation: pulse-text 1.5s ease-in-out infinite;
    display: inline-block;
}
.unproven-cell .cell-value { color: #e67e22; }
.dark-mode .unproven-cell .cell-value { color: #f1c40f; }
.vibrant .unproven-cell .cell-value { color: #f1c40f; }

/* Scratchpad */
.scratch-pad { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); pointer-events: none; }
.scratch-pad-digit { font-size: min(2vw, 1.5dvh); color: var(--text-color); opacity: 0.7; display: flex; justify-content: center; align-items: center; visibility: hidden; }

/* Number Pad */
.numpad { display: grid; grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(2, 1fr); gap: 1dvh; width: 70dvh; max-width: 95vw; height: 20dvh; }
.numpad button { background: var(--card-bg); backdrop-filter: blur(10px); border: 1px solid var(--border-color); border-radius: 12px; font-size: 6dvh; color: var(--text-color); padding: 0; font-weight: 600; box-shadow: 0 4px 6px rgba(0,0,0,0.05); display: flex; align-items: center; justify-content: center; }
.numpad button:disabled { opacity: 0.3; cursor: not-allowed; }
.numpad .control-btn { font-size: 6dvh; display: flex; align-items: center; justify-content: center; gap: 5px; }
.pencil-active { background: var(--primary) !important; color: #fff !important; box-shadow: 0 0 15px var(--primary); border-color: var(--primary-hover) !important; }
.pencil-active svg { filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.6)); }
.hint-active { box-shadow: 0 0 15px #f1c40f; border-color: #f1c40f !important; }
.hint-active svg { filter: drop-shadow(0 0 5px rgba(241, 196, 15, 0.8)); }

/* Responsive adjustments */
@media (orientation: landscape) {
    .sudoku-grid { max-width: 70dvh; }
    .numpad { width: 30dvh; max-width: none; height: 70dvh; grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(6, 1fr); grid-auto-flow: column; align-self: center; }
    .numpad button, .numpad .control-btn { font-size: 7dvh; }
}