@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;600&display=swap');

/* ==================== ROOT VARIABLES ==================== */
:root {
    font-size: 16px;

    /* Colors */
    --color-primary: #18958f;
    --color-primary-light: #62b8b4;
    --color-primary-lighter: #73bcb3;
    --color-primary-hover: #3da89a;
    --color-primary-active: #7fccc3;
    --color-primary-bg: #e8f4f2;

    --color-bg-main: #fffdf9;
    --color-bg-highlight: #fff6e6;
    --color-text-primary: #6b5a47;
    --color-text-secondary: #333;
    --color-text-light: #999;
    --color-text-white: #ffffff;

    --color-border-main: #9d8b7a;
    --color-border-light: #d4c4b0;
    --color-border-gray: #e0e0e0;

    --color-error: #CA4233;
    --color-error-text: #E3A99B;

    --color-gray: #ccc;
    --color-gray-dark: #666;
    --color-gray-bg: #f0f0f0;
}

/* ==================== RESET & BASE ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Segoe UI', sans-serif;
    background: white;
    min-height: 100vh;
}

/* ==================== GAME CONTAINER ==================== */
.game-container {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

/* ==================== TOP MENU ==================== */
.top-menu {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid var(--color-border-gray);
}

.logo-text {
    font-size: 24px;
    font-weight: 600;
    color: var(--color-text-secondary);
}

.mobile-new-game-btn {
    padding: 12px 14px;
    background: var(--color-primary);
    color: var(--color-text-white);
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    font-family: 'Roboto', sans-serif;
}

/* ==================== STATS BAR ==================== */
.mobile-stats-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: baseline;
    padding: 10px 15px 0;
    gap: 15px;
}

.mobile-stats-bar .stat-item {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.mobile-stats-bar .stat-item:nth-child(1) {
    order: 2; /* Difficulty - giữa */
    justify-content: center;
}

.mobile-stats-bar .stat-item:nth-child(2) {
    order: 1; /* Mistakes - trái */
    justify-content: flex-start;
}

.mobile-stats-bar .stat-item:nth-child(3) {
    order: 3; /* Time - phải */
    justify-content: flex-end;
}

.mobile-stats-bar .stat-label {
    font-size: 14px;
    color: var(--color-text-secondary);
    font-weight: 400;
}

.mobile-stats-bar .stat-item:nth-child(1) .stat-label,
.mobile-stats-bar .stat-item:nth-child(3) .stat-label {
    display: none;
}

.mobile-stats-bar .stat-value {
    font-size: 14px;
    color: var(--color-text-secondary);
    font-weight: 400;
}

/* ==================== HIDE DESKTOP ELEMENTS ==================== */
.side-panel .stats-row {
    display: none !important;
}

.stat-item {
    flex: 1;
    text-align: center;
}

.stat-label {
    font-size: 12px;
    color: var(--color-text-light);
    display: block;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 18px;
    color: var(--color-text-secondary);
    font-weight: 400;
}

/* ==================== MAIN GAME ==================== */
.main-game {
    width: 100%;
}

/* ==================== BOARD CONTAINER ==================== */
.board-container {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 10px;
    position: relative;
}

/* ==================== SUDOKU BOARD ==================== */
#sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 0;
    width: 100%;
    max-width: 500px;
    aspect-ratio: 1;
    background: var(--color-bg-main);
    position: relative;
}

#sudoku-board::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 100;
    border: 2px solid var(--color-border-main);
    background-image:
            linear-gradient(to right, transparent calc(33.333% - 1px), var(--color-border-main) calc(33.333% - 1px), var(--color-border-main) calc(33.333% + 1px), transparent calc(33.333% + 1px)),
            linear-gradient(to right, transparent calc(66.666% - 1px), var(--color-border-main) calc(66.666% - 1px), var(--color-border-main) calc(66.666% + 1px), transparent calc(66.666% + 1px)),
            linear-gradient(to bottom, transparent calc(33.333% - 1px), var(--color-border-main) calc(33.333% - 1px), var(--color-border-main) calc(33.333% + 1px), transparent calc(33.333% + 1px)),
            linear-gradient(to bottom, transparent calc(66.666% - 1px), var(--color-border-main) calc(66.666% - 1px), var(--color-border-main) calc(66.666% + 1px), transparent calc(66.666% + 1px));
}

/* ==================== CELLS ==================== */
.cell {
    width: 100%;
    height: 100%;
    border-right: 1px solid var(--color-border-light);
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-main);
    position: relative;
    overflow: hidden;
}

.cell input {
    width: 100%;
    height: 100%;
    border: none;
    text-align: center;
    font-size: 2.25rem;
    font-weight: 300;
    font-family: 'Roboto', sans-serif;
    outline: none;
    background: transparent;
    cursor: pointer;
    color: var(--color-text-primary);
    position: relative;
    z-index: 2;
    caret-color: transparent;
    pointer-events: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
}

.cell {
    pointer-events: auto;
}

.cell input:focus {
    outline: none;
}

/* Cell States */
.cell.fixed input {
    color: var(--color-text-primary);
}

.cell.user-input input {
    color: var(--color-primary);
}

.cell.error {
    background: var(--color-bg-main);
}

.cell.error input {
    color: var(--color-error-text) !important;
}

.cell.error.selected {
    background: var(--color-error) !important;
}

.cell.error.selected input {
    color: var(--color-text-white) !important;
}

.cell.highlight-cross {
    background: var(--color-bg-highlight) !important;
}

.cell.same-number {
    background: var(--color-primary-lighter) !important;
}

.cell.same-number input {
    color: var(--color-text-primary) !important;
}

.cell.selected {
    background: var(--color-primary) !important;
    transition: background-color 0.2s ease;
}

.cell.selected input {
    color: var(--color-text-white) !important;
}

/* ==================== CELL NOTES ==================== */
.cell-notes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 2px;
    pointer-events: none;
    z-index: 1;
}

.note-num {
    font-size: 10px;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 400;
}

/* Notes màu trắng khi cell được select */
.cell.selected .note-num {
    color: var(--color-text-white);
}

/* ==================== SIDE PANEL ==================== */
.side-panel {
    width: 100%;
}

/* ==================== ACTION BUTTONS ==================== */
.action-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    padding: 0 10px;
    margin-bottom: -10px;
}

.icon-btn {
    width: 60px;
    height: 60px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.icon-btn::before {
    display: none;
}

.icon-btn:active::before {
    background: var(--color-primary-active);
}

.icon-btn .icon {
    font-size: 35px;
    color: var(--color-gray);
    font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
}

.icon-btn .icon-svg {
    width: 35px;
    height: 35px;
    color: var(--color-gray);
}

.icon-btn.active .icon,
.icon-btn.active .icon-svg {
    color: var(--color-primary);
}

.icon-btn.active::before {
    background: transparent !important;
}

/* Pause Button */
.action-buttons .pause-btn {
    width: 60px;
    height: 60px;
    background: transparent;
    border: none;
    color: var(--color-gray);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    outline: none !important;
}

.action-buttons .pause-btn .icon-svg {
    width: 35px;
    height: 35px;
}

.action-buttons .pause-btn::before {
    content: '';
    position: absolute;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: transparent;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: -1;
}

.action-buttons .pause-btn.paused::before {
    border: none !important;
}

.action-buttons .pause-btn:active::before {
    background: var(--color-primary-active);
}

.action-buttons .pause-btn.paused {
    color: var(--color-primary);
}

/* Badges */
.toggle-badge {
    position: absolute;
    top: 5px;
    right: 2px;
    min-width: 32px;
    height: 20px;
    background: var(--color-gray);
    color: var(--color-gray-dark);
    font-size: 10px;
    border-radius: 10px;
    font-weight: 600;
    font-family: 'Roboto', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    box-shadow: 0 0 0 3px white;
}

.toggle-badge.active {
    background: var(--color-primary);
    color: var(--color-text-white);
}

.hint-count {
    position: absolute;
    top: 5px;
    right: 2px;
    width: 24px;
    height: 24px;
    background: var(--color-primary);
    color: var(--color-text-white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 0 0 3px white;
}

.hint-count.empty {
    background: var(--color-gray);
    color: var(--color-gray-dark);
}

/* ==================== NUMBER PAD ==================== */
.number-pad {
    width: 100%;
    padding: 0 10px;
    display: flex;
    justify-content: space-between;
    gap: 0;
}

.num-btn {
    flex: 1;
    height: 60px;
    font-size: 2.25rem;
    font-weight: 300;
    background: transparent;
    color: var(--color-primary);
    border: none;
    cursor: pointer;
    font-family: 'Roboto', sans-serif;
    position: relative;
}

.num-btn::before {
    content: '';
    position: absolute;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: transparent;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: -1;
}

.num-btn:active::before {
    background: var(--color-primary-bg);
}

/* ==================== NEW GAME BUTTON (Hidden) ==================== */
.new-game-btn {
    display: none;
}

/* ==================== MODALS ==================== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: white;
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.modal-content h2 {
    font-size: 32px;
    margin-bottom: 15px;
    color: var(--color-text-secondary);
}

.modal-content p {
    font-size: 18px;
    color: var(--color-gray-dark);
    margin-bottom: 30px;
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.modal-btn {
    padding: 12px 30px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Roboto', sans-serif;
}

.retry-btn {
    background: var(--color-gray-bg);
    color: var(--color-text-secondary);
}

.new-btn {
    background: var(--color-primary);
    color: var(--color-text-white);
}

/* Difficulty Modal */
.difficulty-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 20px;
}

.difficulty-option-btn {
    padding: 15px 20px;
    font-size: 16px;
    font-weight: 600;
    border: 2px solid var(--color-border-gray);
    background: white;
    color: var(--color-text-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Roboto', sans-serif;
}

.difficulty-option-btn:active {
    background: var(--color-primary);
    color: var(--color-text-white);
    border-color: var(--color-primary);
}

.custom-row {
    margin-top: 12px;
    display: flex;
    justify-content: center;
}

.custom-btn {
    width: 100%;
    max-width: 300px;
}

/* ==================== PAUSE OVERLAY ==================== */
.pause-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: 200;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.pause-overlay.show {
    display: flex;
}

.play-btn {
    width: 60px;
    height: 60px;
    border: none;
    background: var(--color-primary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(77, 184, 168, 0.4);
    pointer-events: auto;
}

.play-btn::before {
    display: none;
}

.play-btn .material-symbols-outlined {
    font-size: 48px;
    color: var(--color-text-white);
}

.play-btn .icon-svg {
    width: 60px;
    height: 60px;
    color: var(--color-text-white);
}

/* ==================== MESSAGE ==================== */
.message {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #48bb78;
    min-height: 0;
}

/* ==================== ANIMATIONS ==================== */

/* Ripple Effect */
.cell.completed::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-primary);
    z-index: 1;
    transform-origin: center center;
    -webkit-transform-origin: center center;
    will-change: transform, border-radius, opacity;
    animation: rippleExpand 0.2s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
    -webkit-animation: rippleExpand 0.2s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

.cell.collapsing::before {
    animation: rippleCollapse 0.2s cubic-bezier(0.64, 0, 0.78, 0.39) forwards;
    -webkit-animation: rippleCollapse 0.2s cubic-bezier(0.64, 0, 0.78, 0.39) forwards;
}

@keyframes rippleExpand {
    0% {
        transform: scale(0.50);
        -webkit-transform: scale(0.50);
        border-radius: 45%;
        opacity: 0;
    }
    100% {
        transform: scale(1);
        -webkit-transform: scale(1);
        border-radius: 0%;
        opacity: 1;
    }
}

@-webkit-keyframes rippleExpand {
    0% {
        -webkit-transform: scale(0.50);
        border-radius: 45%;
        opacity: 0;
    }
    100% {
        -webkit-transform: scale(1);
        border-radius: 0%;
        opacity: 1;
    }
}

@keyframes rippleCollapse {
    0% {
        transform: scale(1);
        -webkit-transform: scale(1);
        border-radius: 0%;
        opacity: 1;
    }
    100% {
        transform: scale(0.5);
        -webkit-transform: scale(0.5);
        border-radius: 50%;
        opacity: 0;
    }
}

@-webkit-keyframes rippleCollapse {
    0% {
        -webkit-transform: scale(1);
        border-radius: 0%;
        opacity: 1;
    }
    100% {
        -webkit-transform: scale(0.5);
        border-radius: 50%;
        opacity: 0;
    }
}

/* Text Animations */
.cell.completed.fixed input,
.cell.completed.user-input input {
    animation: textFadeToWhite 0.2s cubic-bezier(0.22, 0.61, 0.36, 1) forwards !important;
    animation-delay: 0.0s !important;
}

@keyframes textFadeToWhite {
    0% {
        /*filter: brightness(1);*/
        color: inherit;
    }
    100% {
        color: white;
    }
}

.cell.collapsing.fixed input,
.cell.collapsing.user-input input {
    animation: textToOriginal 0.2s cubic-bezier(0.64, 0, 0.78, 0.39) forwards !important;
    animation-delay: 0s !important;
}

@keyframes textToOriginal {
    0% {
        color: white;
    }
    100% {
        color: inherit;
    }
}