/* 
* DokuSudoku CSS
* Organized and structured styles for Sudoku game
*/

/* ============================================
   BASE STYLES
   ============================================ */
body {
    font-family: 'Arial', sans-serif;
    background-color: #f4f4f9;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    margin: 0;
    min-height: 100vh;
    position: relative;
    padding-bottom: 60px; /* Space for copyright */
}

h1 {
    color: #4a5568;
    margin-bottom: 20px;
    font-size: 2.5em;
    font-weight: 600;
}

button {
    padding: 10px 5px;
    background-color: #718096;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
    width: 80px;
}

button:hover {
    background-color: #4d727f;
}

label {
    color: #4a5568;
    font-weight: 500;
}

input[type="checkbox"] {
    margin-right: 5px;
}

textarea {
    width: 150px;
    height: 170px;
    padding: 6px;
    border: 1px solid #a0aec0;
    border-radius: 6px;
    background-color: #edf2f7;
    resize: none;
    font-family: 'Arial', sans-serif;
    font-size: 16px;
}

/* ============================================
   HEADER STYLES
   ============================================ */
.header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

#timer,
#score {
    color: #4a5568;
    font-size: 1.2em;
    margin: 10px 0;
}

/* ============================================
   SUDOKU GRID STYLES
   ============================================ */
.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, minmax(30px, 50px));
    max-width: 100%;
    margin: 0 auto;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    gap: 2px;
    background-color: #000;
    padding: 6px;
    padding-right: 12px;
    border: 1px solid #333;
    overflow: visible !important;
}

/* Shift cells to visually separate 3x3 subgrids */
.sudoku-grid > .cell:nth-child(9n+4),
.sudoku-grid > .cell:nth-child(9n+5),
.sudoku-grid > .cell:nth-child(9n+6) {
    margin-left: 3px;
}

.sudoku-grid > .cell:nth-child(9n+7),
.sudoku-grid > .cell:nth-child(9n+8),
.sudoku-grid > .cell:nth-child(9n+9) {
    margin-left: 6px;
}

/* Apply special borders to visually separate regions */
.sudoku-grid > .cell:nth-child(3n) {
    border-right-color: black;
}

.sudoku-grid > .cell:nth-child(3n+1) {
    border-left-color: black;
}

.sudoku-grid > .cell[data-row="2"] {
    border-bottom-color: black;
}

.sudoku-grid > .cell[data-row="3"] {
    border-top-color: black;
}

.sudoku-grid > .cell[data-row="5"] {
    border-bottom-color: black;
}

.sudoku-grid > .cell[data-row="6"] {
    border-top-color: black;
}

/* Horizontal borders for 3x3 sections */
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 3px solid #000;
}

/* ============================================
   CELL STYLES
   ============================================ */
.cell {
    width: 50px;
    height: 50px;
    background-color: #edf2f7;
    text-align: center;
    line-height: 50px;
    cursor: pointer;
    position: relative;
    opacity: 1;
    transition: background-color 0.3s ease;
}

.cell:hover {
    background-color: #fefcd2;
}

.cell-value {
    display: block;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 3;
    font-size: 20px;
    color: #2d3748;
    pointer-events: none;
}

.invalid-cell {
    background-color: #feb2b2;
}

.seed-cell .cell-value {
    color: black;
}

.user-cell .cell-value {
    color: blue;
}

/* ============================================
   NUMBER PICKER STYLES
   ============================================ */
.number-picker {
    display: none;
    position: absolute;
    background-color: #ffffff;
    border: 1px solid #a0aec0;
    padding: 5px;
    z-index: 20;
    grid-template-columns: repeat(3, 40px);
    gap: 2px;
    width: 125px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.number-picker span {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
    z-index: 9999 !important;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.number-picker span:hover {
    background-color: #cbd5e0;
}

.number-picker .valid {
    color: #2d3748;
}

.number-picker .invalid {
    color: #ff6666;
}

.number-picker-validated {
    display: none;
    position: absolute;
    padding: 2px;
    pointer-events: auto;
    grid-template-columns: repeat(3, 12px);
    row-gap: 2px;
    column-gap: 3px;
    width: 36px;
    top: 1px;
    left: 2px;
}

.number-picker-validated span {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 12px;
    height: 12px;
    font-size: 8px;
    background-color: transparent;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
}

.number-picker-validated span:hover {
    background-color: #cbd5e0;
}

.number-picker-validated .valid {
    color: #2d3748;
    background-color: #d3d3d3;
}

.number-picker-validated .invalid {
    color: #ff6666;
}

/* When picker is shown, make sure it's visible */
.show-picker .number-picker,
.show-picker .number-picker-validated {
    z-index: 1000 !important;
}

/* ============================================
   CONTROLS STYLES
   ============================================ */
.controls-top {
    margin: 20px 0;
    display: flex;
    gap: 10px;
    align-items: center;
}

.controls-bottom {
    margin: 20px 0;
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.controls-input-area {
    flex: 1;
}

.controls-button-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.controls-button-stack button {
    width: 120px;
}

/* ============================================
   GAME BOX STYLES
   ============================================ */
.new-game-box {
    margin: 7px 0;
    padding: 8px;
    background-color: #edf2f7;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.new-game-box h2 {
    color: #4a5568;
    margin: 0 0 10px 0;
    font-size: 1.5em;
    font-weight: 500;
}

.new-game-box .buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ============================================
   TOGGLE BUTTON STYLES
   ============================================ */
.toggle-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.toggle-description {
    font-size: 12px;
    color: #4a5568;
    margin-top: 5px;
    text-align: center;
}

.toggle-button {
    display: flex;
    align-items: center;
    width: 150px;
    height: 30px;
    background-color: #718096;
    border-radius: 15px;
    cursor: pointer;
    position: relative;
    transition: background-color 0.2s;
}

.toggle-button .toggle-text {
    color: white;
    font-weight: 500;
    margin-left: 40px;
    transition: margin-left 0.2s;
}

.toggle-button .toggle-switch {
    width: 30px;
    height: 30px;
    background-color: white;
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 0;
    transition: left 0.2s;
}

.toggle-button.active {
    background-color: #4a5568;
}

.toggle-button.active .toggle-text {
    margin-left: 40px;
}

.toggle-button.active .toggle-switch {
    left: 120px;
}

/* ============================================
   GAME MODE SELECTOR STYLES (Radio Buttons)
   ============================================ */
.game-mode-selectors { /* Container for the radio options */
    display: flex;
    justify-content: center;
    gap: 20px; /* Space between radio options */
    margin-top: 15px; /* Space below the <hr> */
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
}

.radio-option { /* Container for one radio button + label */
    display: flex;
    align-items: center;
    gap: 5px; /* Space between radio button and label */
}

.radio-option label {
    cursor: pointer;
    display: flex;
    flex-direction: column; /* Icon above text */
    align-items: center;
    color: #4a5568;
    font-weight: 500;
}

.radio-option label i {
    margin-bottom: 3px;
    font-size: 1.2em;
}

/* Optional: Style the label when its radio button is checked */
.radio-option input[type="radio"]:checked + label {
    color: #2d3748;
    font-weight: bold;
}

/* Hide the actual radio button (optional, if you want fully custom appearance) */
/* 
.radio-option input[type="radio"] {
    display: none; 
}
*/

/* ============================================
   GAME MODE SLIDER STYLES
   ============================================ */
.game-mode-sliders {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin: 15px 0;
}

.slider-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 40px;
}

.slider {
    position: relative;
    width: 40px;
    height: 80px;
    cursor: pointer;
    margin-bottom: 8px;
}

.slider-track {
    width: 4px;
    height: 80px;
    background-color: #4a5568;
    border-radius: 2px;
    position: absolute;
    left: 18px;
    top: 0;
}

.slider-knob {
    width: 16px;
    height: 16px;
    background-color: #718096;
    border: 2px solid #4a5568;
    border-radius: 50%;
    position: absolute;
    left: 12px;
    top: 0;
    transition: top 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

.slider.active .slider-knob {
    top: 64px;
    background-color: #4a5568;
}

.slider-label {
    margin-top: 5px;
    font-size: 14px;
    color: #4a5568;
    text-align: center;
    font-weight: 500;
}

.slider.active .slider-label {
    color: #2d3748;
    font-weight: bold;
}

/* ============================================
   MEMORY GAME STYLES
   ============================================ */
.hidden-cell {
    position: relative;
    perspective: 1000px;
}

.cell-flipper {
    transition: transform 0.6s;
    transform-style: preserve-3d;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

.cell.flipped .cell-flipper {
    transform: rotateY(180deg);
}

.cell-front, .cell-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    top: 0;
    left: 0;
}

.cell-front {
    background-color: #718096;
    color: white;
}

.cell-back {
    background-color: #edf2f7;
}

/* Memory Mode */
.cell.hidden-cell .cell-front {
    z-index: 2;
}

.cell.hidden-cell .cell-back {
    z-index: 1;
    transform: rotateY(180deg);
}

/* Non-memory mode - always show cell back */
.cell:not(.hidden-cell) .cell-front {
    z-index: 0;
}

.cell:not(.hidden-cell) .cell-back {
    z-index: 1;
    transform: rotateY(0deg);
}

/* Handle flipped state in memory mode */
.cell.hidden-cell.flipped .cell-front {
    z-index: 1;
}

.cell.hidden-cell.flipped .cell-back {
    z-index: 2; 
}

#flip-count {
    margin-left: 15px;
    color: #4a5568;
    font-weight: bold;
}

/* ============================================
   KIOKUDOKU (MEMORY GAME) STYLES
   ============================================ */
.kiokudoku-mode .cell {
    position: relative;
}

.logo-container {
    position: relative;
    display: inline-block;
}

.king-of-hill {
    position: absolute;
    top: 30%;
    left: 50%;
    width: 80%; /* Set to exactly 80% of the logo width */
    transform: translate(-50%, -50%); /* Center both horizontally and vertically */
    text-align: center;
    font-size: clamp(18px, 10vw, 72px); /* Min: 18px, preferred: 8% of viewport width, max: 72px */
    font-weight: bold;
    color: #ffffff;
    text-shadow: 3px 3px 6px rgba(20, 18, 18, 0.7);
    z-index: 10;
    pointer-events: none; /* Allow clicks to pass through to logo */
}

/* Add additional class for JavaScript dynamic sizing if needed */
.king-of-hill.dynamic-size {
    /* This will be controlled by JavaScript in updateKingOfHill function */
    transition: font-size 0.3s ease;
}

.tile {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: #4682b4;
    transition: opacity 0.3s ease;
    top: 0;
    left: 0;
}

.cell.hidden .tile {
    opacity: 1;
}

.cell.revealed .tile {
    opacity: 0;
    pointer-events: none;
}

.cell.hidden {
    cursor: pointer;
}

.cell.question .number {
    color: #f00;
    font-weight: bold;
}

.number {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

#kiokudoku-status {
    margin-left: 20px;
    font-size: 1.2em;
    color: #4a5568;
}

/* ============================================
   FOOTER STYLES
   ============================================ */
footer {
    position: relative;
    margin-top: 20px;
    width: 100%;
}

.footer-links {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 40px; /* Add space for copyright */
}

.footer-links a {
    display: flex;
    align-items: center;
    justify-content: center;
}

.footer-image {
    height: 100px;
    transition: height 0.3s ease;
}

.footer-image:hover {
    height: 200px;
    transition: height 0.3s ease;
}

.copyright-container {
    position: absolute;
    bottom: -40px;
    left: 0;
    right: 0;
    text-align: center;
    padding: 10px 0;
    background-color: #f4f4f9;
    width: 100%;
}

/* ============================================
   LEADERBOARD STYLES
   ============================================ */
.leaderboard-container {
    max-width: 800px;
    margin: 20px auto;
    padding: 20px;
    background-color: #f9f9f9;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.leaderboard-container h2 {
    font-size: 24px;
    margin-bottom: 15px;
}

#leaderboard {
    width: 100%;
    border-collapse: collapse;
}

#leaderboard th, 
#leaderboard td {
    padding: 10px;
    border-bottom: 1px solid #ddd;
}

#leaderboard th {
    background-color: #4CAF50;
    color: white;
}

#leaderboard tr:nth-child(even) {
    background-color: #f2f2f2;
}

#leaderboard tr:hover {
    background-color: #ddd;
}

/* ============================================
   REMAINING NUMBERS GRID
   ============================================ */
.remaining-grid {
    display: grid;
    grid-template-columns: repeat(9, 50px);
    grid-template-rows: repeat(1, 50px);
    gap: 2px;
    margin: 10px auto;
    width: fit-content;
}

.remainingcell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-family: Arial, sans-serif;
    border: 1px solid #000;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.remainingcell:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    z-index: 2;
}

.remainingcell.active-number {
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(0,0,0,0.4);
    position: relative;
    z-index: 10;
}

.remainingcell.active-number::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 3px solid #ffffff;
    border-radius: 3px;
    pointer-events: none;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { border-width: 3px; }
    50% { border-width: 5px; }
    100% { border-width: 3px; }
}

.cell-index {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 10px;
    color: #666;
}

.rcell-value {
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background-color: transparent;
}

/* Background colors for remaining number cells */
.remainingcell[data-number="1"] { background-color: #FFC832; } /* Orange */
.remainingcell[data-number="2"] { background-color: #99CCFF; } /* Blue */
.remainingcell[data-number="3"] { background-color: #99FF99; } /* Green */
.remainingcell[data-number="4"] { background-color: #CC99FF; } /* Purple */
.remainingcell[data-number="5"] { background-color: #FFFF80; } /* Yellow */
.remainingcell[data-number="6"] { background-color: #FF99FF; } /* Pink */
.remainingcell[data-number="7"] { background-color: #CECECE; } /* Gray */
.remainingcell[data-number="8"] { background-color: #FF8080; } /* Red */
.remainingcell[data-number="9"] { background-color: #6699FF; } /* Blue-Violet */

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    body {
        background-color: white;
        color: black;
    }

    .controls-top,
    .controls-bottom,
    .new-game-box,
    #timer,
    #score {
        display: none;
    }

    .print-board {
        display: grid;
        grid-template-columns: repeat(9, 50px);
        column-gap: 0px;
        row-gap: 0px;
        background-color: white;
        padding: 5px;
        border-radius: 8px;
        box-shadow: none;
        margin-bottom: 20px;
        width: 70%;
    }

    .print-board .cell {
        background-color: white;
    }

    .print-board .number-picker-validated {
        display: grid;
        grid-template-columns: repeat(3, 12px);
        row-gap: 0px;
        column-gap: 0px;
        width: 36px;
        margin-top: 5px;
        margin-bottom: 5px;
    }

    .print-board .number-picker-validated span {
        width: 12px;
        height: 12px;
        font-size: 8px;
        background-color: transparent;
    }
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */
/* Medium screens (tablets, small desktops) */
@media screen and (max-width: 600px) {
    body {
        padding-bottom: 80px;
    }
    
    /* Sudoku grid */
    .sudoku-grid {
        grid-template-columns: repeat(9, minmax(25px, 35px));
        column-gap: 1px;
        row-gap: 1px;
        padding: 3px;
    }
    /* Shift cells to visually separate 3x3 subgrids */
    .sudoku-grid > .cell:nth-child(9n+4){
        margin-left: 3px;
    }

    .sudoku-grid > .cell:nth-child(9n+7){
        margin-left: 3px;
    }

    .sudoku-grid > .cell:nth-child(9n+5),
    .sudoku-grid > .cell:nth-child(9n+6) {
        margin-left: 0px;
    }
    .sudoku-grid > .cell:nth-child(9n+8),
    .sudoku-grid > .cell:nth-child(9n+9) {
        margin-left: 0px;
    }

    .cell {
        width: auto;
        height: 35px;
        line-height: 35px;
    }

    .cell-value {
        font-size: 16px;
    }

    /* Number picker */
    .number-picker {
        grid-template-columns: repeat(3, 30px);
        width: 95px;
    }

    .number-picker span {
        width: 30px;
        height: 30px;
        font-size: 14px;
    }

    .number-picker-validated {
        grid-template-columns: repeat(3, 9px);
        row-gap: 4px;
        column-gap: 1px;
        padding: 4px;
        width: 24px;
        top: 0;
        left: 0;
    }

    .number-picker-validated span {
        width: 6px;
        height: 6px;
        font-size: 5px;
    }

    /* Controls */
    .controls-top {
        flex-wrap: wrap;
        justify-content: center;
    }

    .controls-bottom {
        flex-direction: column;
        align-items: center;
    }

    .controls-input-area {
        width: 100%;
    }

    .controls-button-stack {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
    }

    .controls-button-stack button {
        width: auto;
    }

    /* UI elements */
    button {
        padding: 5px 5px;
        font-size: 12px;
    }

    button i {
        font-size: 14px;
    }

    textarea {
        width: 120px;
        height: 120px;
    }

    .toggle-button {
        width: 120px;
    }

    .toggle-button.active .toggle-switch {
        left: 90px;
    }

    .toggle-description {
        font-size: 10px;
    }

    /* Game mode sliders */
    .game-mode-sliders {
        gap: 15px;
    }
    
    .slider-container {
        width: 30px;
    }
    
    .slider {
        width: 30px;
        height: 60px;
    }
    
    .slider-track {
        height: 60px;
        left: 13px;
    }

    .slider-knob {
        width: 14px;
        height: 14px;
        left: 8px;
    }
    
    .slider.active .slider-knob {
        top: 46px;
    }
    
    .slider-label {
        font-size: 10px;
    }

    /* Images */
    img[src="dokusudoku.png"] {
        width: 250px !important;
    }

    /* Footer */
    .footer-links {
        flex-wrap: wrap;
        margin-bottom: 60px;
    }

    .footer-image {
        height: 60px;
    }

    .footer-image:hover {
        height: 100px;
    }

    .copyright-container {
        bottom: -60px;
    }
    
    /* Remaining grid */
    .remaining-grid {
        grid-template-columns: repeat(9, 35px);
        grid-template-rows: repeat(1, 35px);
    }
}

/* Small screens (phones) */
@media screen and (max-width: 350px) {
    .sudoku-grid {
        grid-template-columns: repeat(9, minmax(20px, 30px));
        column-gap: 1px;
        row-gap: 1px;
        padding: 3px;
    }
    /* Shift cells to visually separate 3x3 subgrids */
    .sudoku-grid > .cell:nth-child(9n+4){
        margin-left: 3px;
    }

    .sudoku-grid > .cell:nth-child(9n+7){
        margin-left: 3px;
    }

    .sudoku-grid > .cell:nth-child(9n+5),
    .sudoku-grid > .cell:nth-child(9n+6) {
        margin-left: 0px;
    }
    .sudoku-grid > .cell:nth-child(9n+8),
    .sudoku-grid > .cell:nth-child(9n+9) {
        margin-left: 0px;
    }
    .cell {
        height: 30px;
        line-height: 30px;
    }

    .number-picker-validated {
        grid-template-columns: repeat(3, 5px);
        width: 18px;
        top: 0;
        left: 0;
    }

    .number-picker-validated span {
        width: 5px;
        height: 5px;
        font-size: 4px;
        padding: 0;
    }

    /* Game mode sliders */
    .game-mode-sliders {
        gap: 10px;
    }
    .slider-container {
        width: 25px;
    }
    .slider {
        width: 25px;
        height: 50px;
    }
    .slider-track {
        height: 50px;
        left: 10.5px;
    }
    .slider-knob {
        width: 12px;
        height: 12px;
        left: 6.5px;
    }
    .slider.active .slider-knob {
        top: 38px;
    }
    .slider-label {
        font-size: 9px;
    }
}