﻿* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background: #f4f6f9;
    color: #263238;
}

main {
    background: #d8dee4;
}

button {
    font: inherit;
    border: none;
    cursor: pointer;
}

    button:disabled {
        cursor: default;
    }
/* ========================================================= App ========================================================= */

#app {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
/* ========================================================= Toolbar ========================================================= */

.toolbar {
    width: 100%;
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: white;
    border-bottom: 1px solid #e1e5e9;
}

.toolbar-button {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: transparent;
    color: #455a64;
    font-size: 25px;
}

    .toolbar-button:hover {
        background: #f0f2f5;
    }

.settings-button {
    font-size: 25px;
}

/* =========================================================
   Settings
   ========================================================= */

.settings-container {
    position: relative;
}


/* =========================================================
   Settings popup
   ========================================================= */

.settings-popup {
    position: absolute;
    top: 48px;
    left: 0;
    width: 260px;
    padding: 12px;
    background: white;
    border: 1px solid #dce1e6;
    border-radius: 10px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
    z-index: 100;
}

    .settings-popup[hidden] {
        display: none;
    }


/* =========================================================
   Setting row
   ========================================================= */

.setting-row {
    display: flex;
    align-items: center;
    min-height: 40px;
    cursor: pointer;
    user-select: none;
}

    .setting-row + .setting-row {
        margin-top: 4px;
    }

.setting-label {
    margin-left: 9px;
    font-size: 14px;
    color: #455a64;
}


/* =========================================================
   Switch
   ========================================================= */

.setting-row input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch {
    position: relative;
    width: 38px;
    height: 22px;
    flex-shrink: 0;
    border-radius: 11px;
    background: #cbd2d9;
    transition: background 0.15s ease;
}

    .switch::after {
        content: "";
        position: absolute;
        width: 18px;
        height: 18px;
        top: 2px;
        left: 2px;
        border-radius: 50%;
        background: white;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
        transition: transform 0.15s ease;
    }


/* On */

.setting-row input:checked + .switch {
    background: #287fe8;
}

    .setting-row input:checked + .switch::after {
        transform: translateX(16px);
    }


#clueDisplay {
    min-height: 40px;
    padding: 0 32px 0 12px;
    font-size: 16px;
    border: 1px solid #aaa;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    touch-action: manipulation;
}

.info-button {
    background: #287fe8;
    color: white;
    font-family: Georgia, serif;
    font-size: 25px;
    font-weight: bold;
}

    .info-button:hover {
        background: #176ed7;
    }
/* ========================================================= New Puzzle + radius ========================================================= */

.puzzle-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.new-puzzle-button {
    height: 42px;
    padding: 0 16px;
    border-radius: 8px;
    background: #287fe8;
    color: white;
    font-size: 15px;
    font-weight: 600;
}

    .new-puzzle-button:hover {
        background: #176ed7;
    }

.radius-selector {
    display: flex;
    gap: 4px;
}

.radius-button {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #e5e9ee;
    color: #596875;
    font-size: 15px;
    font-weight: 600;
}

    .radius-button:hover {
        background: #d8dee5;
    }

    .radius-button.selected {
        background: #287fe8;
        color: white;
    }
/* ========================================================= Main ========================================================= */

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
}
/* ========================================================= Puzzle ========================================================= */

#puzzleArea {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 12px 0;
}

#puzzleGrid {
    --cell-size: 40px;
    position: relative;
    width: min(100%, 480px);
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
}

    #puzzleGrid.hide-factors .clue-factors {
        display: none;
    }

    #puzzleGrid.hide-candidates .cell-candidates {
        display: none;
    }

/* =========================================================
   Hex cells
   ========================================================= */

.hex-cell {
    position: absolute;
    width: calc(var(--cell-size) * 1.732);
    height: calc(var(--cell-size) * 2);
    left: 50%;
    top: 50%;
    transform: translate( calc(var(--x) * var(--cell-size) - 50%), calc(var(--y) * var(--cell-size) - 50%) );
    clip-path: polygon( 50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25% );
    display: flex;
    align-items: center;
    justify-content: center;
}


/* =========================================================
   Puzzle cells
   ========================================================= */

.puzzle-cell {
    background: #8d9aa8;
    position: absolute;
}

    .puzzle-cell::after {
        content: "";
        position: absolute;
        top: 1px;
        left: 1px;
        width: calc(100% - 2px);
        height: calc(100% - 2px);
        background: #ffffff;
        clip-path: polygon( 50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25% );
        z-index: 0;
    }

    .puzzle-cell.selected {
        background: #287fe8;
    }

        .puzzle-cell.selected::after {
            top: 3px;
            left: 3px;
            width: calc(100% - 6px);
            height: calc(100% - 6px);
        }

    .puzzle-cell.solved .cell-value {
        animation: solvedPulse 2.0s ease forwards;
    }


@keyframes solvedPulse {
    0% {
        transform: scale(1);
    }

    20% {
        transform: scale(1.8);
    }

    40% {
        transform: scale(1);
    }

    60% {
        transform: scale(1.8);
    }

    80% {
        transform: scale(1);
    }

    100% {
        transform: scale(1.5);
    }
}

/* =========================================================
   Clue cells
   ========================================================= */

.clue-cell {
    background: #dfe5eb;
    flex-direction: column;
    text-align: center;
}

/* =========================================================
   Clue text
   ========================================================= */

.clue-value {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.1;
    color: #111111;
}

.clue-factors {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 1px;
    margin-top: 4px;
    font-size: 10px;
    font-weight: 400;
    line-height: 1;
    color: #6f7b87;
    white-space: nowrap;
    transform: scaleX(0.9);
}
    .clue-factors strong {
        font-size: 12px;
        font-weight: 700;
    }

/* =========================================================
   Puzzle cell content
   ========================================================= */

.cell-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    color: #111111;
}


.cell-candidates {
    font-size: 14px;
    font-weight: 400;
    line-height: 1;
    color: #6f7b87;
    white-space: nowrap;
    transform: scaleX(0.9);
}

.cell-value,
.cell-candidates {
    position: relative;
    z-index: 1;
}

.clue-cell::after {
    content: "";
    position: absolute;
    height: 4px;
    width: var(--cell-size);
    background-color: #777;
    transform-origin: center;
}

/* q-axis */
.clue-q::after {
    left: 50%;
    top: 87.5%;
    transform: translate(-12.5%, -50%) rotate(150deg);
}

/* r-axis */
.clue-r::after {
    left: 1px;
    top: 50%;
    transform: translateX(-50%) rotate(-90deg);
}

/* s-axis */
.clue-s::after {
    left: 50%;
    top: 12.5%;
    transform: translate(-12.5%, -50%) rotate(30deg);
}

/* =========================================================
   Candidate visibility
   ========================================================= */

#puzzleGrid.hide-candidates .cell-candidates {
    display: none;
}

/* ========================================================= Factor buttons ========================================================= */

#factorButtons {
    width: 100%;
    max-width: 500px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 8px 0;
}

.factor-button {
    height: 52px;
    border-radius: 10px;
    background: #f0f5fc;
    color: #455a64;
    font-size: 20px;
    font-weight: 600;
}

    .factor-button:hover {
        background: #ffffff;
    }

    .factor-button:disabled {
        background: #dfe4eb;
        color: #b7bec6;
    }
/* ========================================================= Desktop ========================================================= */

@media (min-width: 700px) {
    body {
        padding: 20px;
    }

    #app {
        max-width: 1100px;
        min-height: calc(100vh - 40px);
        margin: 0 auto;
        background: white;
        border-radius: 12px;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
        overflow: hidden;
    }

    .toolbar {
        height: 64px;
        padding: 10px 20px;
    }

    main {
        padding: 20px;
    }

    #puzzleGrid {
        max-width: 650px;
    }

    #factorButtons {
        max-width: 650px;
    }
}
