* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-pink: #6b6eff;
    --secondary-pink: #389b24;
    --light-pink: #c2e2ff;
    --pale-pink: #fff0f5;
    --purple: #c9b1ff;
    --lavender: #e8d5ff;
    --mint: #98e4c9;
    --peach: #ffcba4;
    --yellow: #fff3b0;
    --coral: #ff7e79;
    --gradient-start: #ffecd2;
    --gradient-end: #fcb69f;
    --shadow-color: rgba(255, 107, 157, 0.3);
    --glow-color: rgba(100, 171, 106, 0.5);
    --error-color: #ff2929;
    --success-color: #51cf66;
    --highlight-color: rgba(236, 255, 221, 0.829);
    --same-number-color: rgba(228, 221, 243, 0.87);
}

body {
    font-family: 'Nunito', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 50%, #fbc2eb 100%);
    overflow-x: hidden;
    position: relative;
    padding: 20px;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 20% 80%, rgba(255, 182, 193, 0.4) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(221, 160, 221, 0.4) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(255, 218, 185, 0.3) 0%, transparent 40%);
    pointer-events: none;
    z-index: 0;
}

.game-container {
    position: relative;
    z-index: 1;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    border-radius: 30px;
    padding: 25px;
    box-shadow:
        0 20px 60px rgba(255, 107, 157, 0.2),
        0 0 0 1px rgba(255, 255, 255, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    max-width: 450px;
    width: 100%;
}

.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.game-header h1 {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-pink), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 15px;
    letter-spacing: 2px;
    animation: titleFloat 3s ease-in-out infinite;
}

@keyframes titleFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

.stats-bar {
    display: flex;
    justify-content: space-evenly;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

/* 標題行（含說明按鈕） */
.title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 22px;
}

/* 說明按鈕 */
.help-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(255, 107, 157, 0.3);
    transition: all 0.3s ease;
    gap: 10px;
}

.help-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(255, 107, 157, 0.4);
}

.help-btn.active {
    background: linear-gradient(135deg, #fecfef 0%, #ff9a9e 100%);
}

/* 說明面板 */
.help-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 240, 245, 0.95));
    border-radius: 15px;
    margin-top: 0;
    box-shadow: 0 4px 15px rgba(255, 107, 157, 0.15);
}

.help-panel.show {
    max-height: 80vh;
    overflow-y: scroll;
    margin-top: 10px;
    padding: 15px;
}

/* Help panel scrollbar styling */
.help-panel.show::-webkit-scrollbar {
    width: 10px;
}

.help-panel.show::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 5px;
}

.help-panel.show::-webkit-scrollbar-thumb {
    background: #ff6b9d;
    border-radius: 5px;
}

.help-panel.show::-webkit-scrollbar-thumb:hover {
    background: #ff4d7d;
}

.help-content h3 {
    margin: 0 0 10px 0;
    color: #ff6b9d;
    font-size: 1rem;
}

.help-section {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 8px;
    line-height: 1.4;
}

.help-section strong {
    color: #ff6b9d;
}

.stat-item {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 240, 245, 0.9));
    padding: 10px 16px;
    border-radius: 15px;
    box-shadow:
        0 4px 15px rgba(255, 107, 157, 0.15),
        inset 0 2px 0 rgba(255, 255, 255, 0.8);
    min-width: 80px;
    transition: transform 0.3s ease;
}

.stat-item:hover {
    transform: translateY(-2px);
}

.stat-label {
    display: block;
    font-size: 0.96rem;
    color: var(--secondary-pink);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.stat-value {
    display: block;
    font-size: 0.96rem;
    font-weight: 800;
    color: var(--primary-pink);
}

.difficulty-select {
    font-family: 'Nunito', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary-pink);
    background: transparent;
    border: none;
    cursor: pointer;
    outline: none;
}

.difficulty-select option {
    font-family: 'Nunito', sans-serif;
    background: white;
    color: var(--primary-pink);
}

.game-board-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 2px;
    background: var(--primary-pink);
    padding: 3px;
    border-radius: 15px;
    box-shadow:
        0 8px 25px rgba(255, 107, 157, 0.25),
        inset 0 0 0 3px var(--primary-pink);
}

.sudoku-cell {
    width: 45px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.4rem;
    font-weight: 700;
    background: white;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    position: relative;
    color: var(--primary-pink);
}

/* 3x3 box borders - Only for standard Sudoku (approximate check by excluding other modes) */
.sudoku-board:not(.mode-pipe):not(.mode-kenken):not(.mode-ohh1):not(.mode-nonogram):not(.mode-minesweeper):not(.mode-nerdle):not(.mode-mastermind):not(.mode-2048) .sudoku-cell:nth-child(3n) {
    border-right: 2px solid var(--primary-pink);
}

.sudoku-board:not(.mode-pipe):not(.mode-kenken):not(.mode-ohh1):not(.mode-nonogram):not(.mode-minesweeper):not(.mode-nerdle):not(.mode-mastermind):not(.mode-2048) .sudoku-cell:nth-child(9n) {
    border-right: none;
}

.sudoku-board:not(.mode-pipe):not(.mode-kenken):not(.mode-ohh1):not(.mode-nonogram):not(.mode-minesweeper):not(.mode-nerdle):not(.mode-mastermind):not(.mode-2048) .sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-board:not(.mode-pipe):not(.mode-kenken):not(.mode-ohh1):not(.mode-nonogram):not(.mode-minesweeper):not(.mode-nerdle):not(.mode-mastermind):not(.mode-2048) .sudoku-cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--primary-pink);
}

/* Corner radius */
.sudoku-cell:nth-child(1) {
    border-top-left-radius: 12px;
}

.sudoku-cell:nth-child(9) {
    border-top-right-radius: 12px;
}

.sudoku-cell:nth-child(73) {
    border-bottom-left-radius: 12px;
}

.sudoku-cell:nth-child(81) {
    border-bottom-right-radius: 12px;
}

.sudoku-cell.fixed {
    color: #666;
    font-weight: 800;
}

.sudoku-cell.selected {
    background: var(--light-pink);
    box-shadow: inset 0 0 0 2px var(--primary-pink);
}

.sudoku-cell.highlighted {
    background: var(--highlight-color);
}

.sudoku-cell.same-number {
    background: var(--same-number-color);
}

/* 自動帶入時，相同數字放大顯示 */
.sudoku-cell.auto-fill-enlarged {
    font-size: 1.95rem;
    font-weight: 800;
    transition: font-size 0.2s ease;
}

.sudoku-cell.error {
    color: var(--error-color);
    animation: shake 0.3s ease;
}

.sudoku-cell.error-highlight {
    background: rgba(255, 107, 107, 0.2);
}

/* Killer Sudoku Cage Styles */
.sudoku-cell.killer-mode {
    position: relative;
}

/* 8 種柔和的籠子背景顏色 */
.sudoku-cell.cage-color-0 {
    background: rgba(255, 180, 180, 0.938) !important;
    /* 淺粉紅 */
}

.sudoku-cell.cage-color-1 {
    background: rgb(202, 242, 255) !important;
    /* 淺藍 */
}

.sudoku-cell.cage-color-2 {
    background: rgb(155, 255, 155) !important;
    /* 淺綠 */
}

.sudoku-cell.cage-color-3 {
    background: rgb(255, 255, 156) !important;
    /* 淺黃 */
}

.sudoku-cell.cage-color-4 {
    background: rgb(248, 150, 255) !important;
    /* 淺紫 */
}

.sudoku-cell.cage-color-5 {
    background: rgb(255, 207, 202) !important;
    /* 淺橙 */
}

.sudoku-cell.cage-color-6 {
    background: rgb(160, 244, 255) !important;
    /* 淺青 */
}

.sudoku-cell.cage-color-7 {
    background: rgb(255, 211, 128) !important;
    /* 淺棕 */
}

/* 籠子邊框 - 細小紅色實線 */
.sudoku-cell.cage-border-top {
    border-top: 2px solid #ff4545 !important;
}

.sudoku-cell.cage-border-right {
    border-right: 2px solid #ff3939 !important;
}

.sudoku-cell.cage-border-bottom {
    border-bottom: 2px solid #fc4747 !important;
}

.sudoku-cell.cage-border-left {
    border-left: 2px solid #cc3333 !important;
}

.cage-sum {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 0.6rem;
    font-weight: 800;
    color: #333;
    background: rgba(255, 255, 255, 0.85);
    padding: 1px 3px;
    border-radius: 3px;
    line-height: 1;
    z-index: 10;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.sudoku-cell.killer-mode .cell-value {
    font-size: 1.3rem;
    font-weight: 700;
}

.sudoku-cell.killer-mode .notes {
    margin-top: 8px;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-3px);
    }

    75% {
        transform: translateX(3px);
    }
}

.sudoku-cell.correct {
    animation: pop 0.3s ease;
}

@keyframes pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.sudoku-cell:hover:not(.fixed):not(.selected) {
    background: rgba(255, 240, 245, 0.8);
}

/* Notes styling */
.sudoku-cell .notes {
    display: grid;
    grid-template-columns: repeat(3, auto);
    grid-template-rows: repeat(3, auto);
    gap: 0px;
    width: 100%;
    height: 100%;
    font-size: 0.7rem;
    color: #03c70d;
    font-weight: 700;
    justify-content: center;
    align-content: center;
}

.sudoku-cell .notes span {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 10px;
    height: 10px;
    line-height: 1;
}

/* Number pad */
.number-pad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 20px;
    padding: 0 10px;
}

.num-btn {
    padding: 12px;
    font-family: 'Nunito', sans-serif;
    font-size: 1.3rem;
    font-weight: 800;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: linear-gradient(145deg, #ffffff, #fff5f8);
    color: var(--primary-pink);
    box-shadow:
        0 4px 10px rgba(255, 107, 157, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.num-btn:hover {
    transform: translateY(-2px);
    box-shadow:
        0 6px 15px rgba(255, 107, 157, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.num-btn:active {
    transform: scale(0.95);
}

.num-btn.erase-btn {
    background: linear-gradient(145deg, var(--pale-pink), var(--light-pink));
}

.num-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.num-btn.auto-fill-active {
    background: linear-gradient(145deg, #a8edea, #5fd9d1);
    color: #006666;
    box-shadow:
        0 4px 15px rgba(95, 217, 209, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.9),
        0 0 0 3px rgba(95, 217, 209, 0.3);
    transform: scale(1.05);
}

.num-btn.auto-fill-active:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow:
        0 6px 20px rgba(95, 217, 209, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.9),
        0 0 0 3px rgba(95, 217, 209, 0.4);
}

/* Game controls */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    font-family: 'Nunito', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
            transparent,
            rgba(255, 255, 255, 0.3),
            transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn-icon {
    font-size: 1.1rem;
}

.btn-notes {
    background: linear-gradient(135deg, var(--lavender), var(--purple));
    color: white;
    box-shadow: 0 4px 15px rgba(201, 177, 255, 0.4);
}

.btn-notes.active {
    background: linear-gradient(135deg, var(--purple), #a78bfa);
    box-shadow: 0 4px 20px rgba(167, 139, 250, 0.5);
    border: 3px solid #ff3333;
    outline: 2px solid rgba(255, 51, 51, 0.4);
}

.btn-hint {
    background: linear-gradient(135deg, var(--yellow), #ffe066);
    color: #8b7000;
    box-shadow: 0 4px 15px rgba(255, 224, 102, 0.4);
}

.btn-restart {
    background: linear-gradient(135deg, var(--primary-pink), var(--secondary-pink));
    color: white;
    box-shadow: 0 4px 15px rgba(255, 107, 157, 0.4);
}

.btn:hover {
    transform: translateY(-2px);
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

/* Message overlay */
.message-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 0;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
}

.message-overlay.show {
    opacity: 1;
    visibility: visible;
}

.message-content {
    text-align: center;
    animation: messagePopIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 80vh;
    max-width: 90vw;
    overflow-y: scroll;
    padding: 20px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

/* Ensure scrollbar is always visible */
.message-content::-webkit-scrollbar {
    width: 12px;
}

.message-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.message-content::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.message-content::-webkit-scrollbar-thumb:hover {
    background: #555;
}

@keyframes messagePopIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.message-icon {
    font-size: 4rem;
    margin-bottom: 15px;
    animation: iconBounce 1s ease-in-out infinite;
}

@keyframes iconBounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.message-text {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-pink), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
}

.message-subtext {
    font-size: 1rem;
    color: var(--secondary-pink);
    margin-bottom: 20px;
}

.message-btn {
    margin-top: 10px;
}

/* Floating decorations */
.floating-decorations {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.decoration {
    position: absolute;
    font-size: 1.5rem;
    animation: floatUp 8s ease-in-out infinite;
    opacity: 0.5;
}

@keyframes floatUp {
    0% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 0;
    }

    10% {
        opacity: 0.5;
    }

    90% {
        opacity: 0.5;
    }

    100% {
        transform: translateY(-100px) rotate(360deg);
        opacity: 0;
    }
}

/* Responsive Design */
@media (max-width: 480px) {
    .game-container {
        padding: 15px;
        border-radius: 25px;
    }

    .game-header h1 {
        font-size: 1.4rem;
    }

    .stats-bar {
        gap: 8px;
    }

    .stat-item {
        padding: 8px 12px;
        min-width: 70px;
    }

    .stat-value {
        font-size: 1rem;
    }

    .sudoku-cell {
        width: 35px;
        height: 35px;
        font-size: 1.2rem;
    }

    .sudoku-cell .notes {
        font-size: 0.45rem;
    }

    .number-pad {
        gap: 6px;
    }

    .num-btn {
        padding: 10px;
        font-size: 1.1rem;
    }

    .btn {
        padding: 8px 14px;
        font-size: 0.85rem;
    }
}

@media (max-width: 380px) {
    .sudoku-cell {
        width: 31px;
        height: 31px;
        font-size: 1.1rem;
    }

    .game-controls {
        gap: 6px;
    }

    .btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .btn span:not(.btn-icon) {
        display: none;
    }
}

/* Victory animation */
@keyframes victory {

    0%,
    100% {
        transform: scale(1) rotate(0deg);
    }

    25% {
        transform: scale(1.1) rotate(-5deg);
    }

    75% {
        transform: scale(1.1) rotate(5deg);
    }
}

.sudoku-board.victory .sudoku-cell {
    animation: victory 0.5s ease-in-out;
    animation-delay: calc(var(--cell-index) * 20ms);
}

/* Confetti */
.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    animation: confettiFall 3s ease-out forwards;
    z-index: 1000;
    pointer-events: none;
    top: -20px;
}

.confetti-square {
    border-radius: 2px;
}

.confetti-circle {
    border-radius: 50%;
}

.confetti-triangle {
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 10px solid;
    background: transparent !important;
}

@keyframes confettiFall {
    0% {
        transform: translateY(0) rotate(0deg) scale(1);
        opacity: 1;
    }

    50% {
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(720deg) scale(0.5);
        opacity: 0;
    }
}

/* Emoji Explosion */
.emoji-explosion {
    position: fixed;
    z-index: 1001;
    pointer-events: none;
    animation: emojiPop 2s ease-out forwards;
}

@keyframes emojiPop {
    0% {
        transform: scale(0) rotate(0deg);
        opacity: 0;
    }

    20% {
        transform: scale(1.5) rotate(15deg);
        opacity: 1;
    }

    40% {
        transform: scale(1) rotate(-10deg);
    }

    100% {
        transform: scale(0) rotate(360deg) translateY(-100px);
        opacity: 0;
    }
}

/* Firework Sparks */
.firework-spark {
    position: fixed;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    z-index: 1002;
    pointer-events: none;
    animation: sparkExplode 1s ease-out forwards;
    box-shadow: 0 0 6px currentColor, 0 0 12px currentColor;
}

@keyframes sparkExplode {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    100% {
        transform:
            translate(calc(cos(var(--angle)) * var(--distance)),
                calc(sin(var(--angle)) * var(--distance))) scale(0);
        opacity: 0;
    }
}

/* Screen Flash */
.screen-flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0%, rgba(255, 215, 0, 0.5) 50%, transparent 100%);
    z-index: 999;
    pointer-events: none;
    animation: flashBang 0.5s ease-out forwards;
}

@keyframes flashBang {
    0% {
        opacity: 1;
        transform: scale(0.5);
    }

    50% {
        opacity: 0.8;
        transform: scale(1.2);
    }

    100% {
        opacity: 0;
        transform: scale(1);
    }
}

/* ===== 2048 遊戲樣式 ===== */

/* 2048 模式基礎樣式（不設定網格，讓各難度類別控制） */
.sudoku-board.mode-2048 {
    width: auto;
    justify-content: center;
}

/* 2048 模式的格子系統 - 不同難度大小 */
.sudoku-board.mode-2048.grid-2048-4 {
    grid-template-columns: repeat(4, 70px) !important;
    grid-template-rows: repeat(4, 70px) !important;
    gap: 8px;
    padding: 12px;
    width: auto;
    justify-content: center;
}

.sudoku-board.mode-2048.grid-2048-5 {
    grid-template-columns: repeat(5, 60px);
    grid-template-rows: repeat(5, 60px);
    gap: 8px;
    padding: 12px;
    width: auto;
    justify-content: center;
}

.sudoku-board.mode-2048.grid-2048-6 {
    grid-template-columns: repeat(6, 50px);
    grid-template-rows: repeat(6, 50px);
    gap: 6px;
    padding: 10px;
    width: auto;
    justify-content: center;
}

/* 2048 方塊基礎樣式 */
.sudoku-board.mode-2048 .tile-2048 {
    width: 100%;
    height: 100%;
    font-size: 1.8rem;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.15s ease;
}

/* 不同大小的字體調整 */
.sudoku-board.mode-2048.grid-2048-4 .tile-2048 {
    font-size: 1.5rem;
}

.sudoku-board.mode-2048.grid-2048-5 .tile-2048 {
    font-size: 1.4rem;
}

.sudoku-board.mode-2048.grid-2048-6 .tile-2048 {
    font-size: 1.2rem;
}

/* 空方塊 */
.tile-2048:not([class*="tile-2"]):not([class*="tile-4"]):not([class*="tile-8"]):not([class*="tile-1"]):not([class*="tile-5"]):not([class*="tile-6"]) {
    background: rgba(238, 228, 218, 0.5);
}

/* 各數字方塊顏色 */
.tile-2 {
    background: linear-gradient(135deg, #eee4da 0%, #ede0c8 100%);
    color: #776e65;
}

.tile-4 {
    background: linear-gradient(135deg, #ede0c8 0%, #edc850 100%);
    color: #776e65;
}

.tile-8 {
    background: linear-gradient(135deg, #f2b179 0%, #f59563 100%);
    color: #f9f6f2;
}

.tile-16 {
    background: linear-gradient(135deg, #f59563 0%, #f67c5f 100%);
    color: #f9f6f2;
}

.tile-32 {
    background: linear-gradient(135deg, #f67c5f 0%, #f65e3b 100%);
    color: #f9f6f2;
}

.tile-64 {
    background: linear-gradient(135deg, #f65e3b 0%, #ed4020 100%);
    color: #f9f6f2;
}

.tile-128 {
    background: linear-gradient(135deg, #edcf72 0%, #edcc61 100%);
    color: #f9f6f2;
    font-size: 1.8rem;
}

.tile-256 {
    background: linear-gradient(135deg, #edcc61 0%, #edc850 100%);
    color: #f9f6f2;
    font-size: 1.8rem;
}

.tile-512 {
    background: linear-gradient(135deg, #edc850 0%, #edc53f 100%);
    color: #f9f6f2;
    font-size: 1.8rem;
}

.tile-1024 {
    background: linear-gradient(135deg, #edc53f 0%, #edc22e 100%);
    color: #f9f6f2;
    font-size: 1.5rem;
}

.tile-2048 {
    background: linear-gradient(135deg, #edc22e 0%, #ffdf00 100%);
    color: #f9f6f2;
    font-size: 1.5rem;
    box-shadow: 0 0 30px rgba(243, 215, 116, 0.8);
    animation: pulse2048 1.5s ease-in-out infinite;
}

.tile-4096 {
    background: linear-gradient(135deg, #ff69b4 0%, #ff1493 100%);
    color: #f9f6f2;
    font-size: 1.3rem;
}

.tile-8192 {
    background: linear-gradient(135deg, #9370db 0%, #8b00ff 100%);
    color: #f9f6f2;
    font-size: 1.3rem;
}

@keyframes pulse2048 {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

/* ===== Oh h1 遊戲樣式 ===== */

/* Oh h1 模式的格子系統 */
.sudoku-board.mode-ohh1.grid-6 {
    grid-template-columns: repeat(6, 45px);
    grid-template-rows: repeat(6, 45px);
    gap: 6px;
    width: auto;
    justify-content: center;
}

.sudoku-board.mode-ohh1.grid-8 {
    grid-template-columns: repeat(8, 38px);
    grid-template-rows: repeat(8, 38px);
    gap: 5px;
    width: auto;
    justify-content: center;
}

.sudoku-board.mode-ohh1.grid-10 {
    grid-template-columns: repeat(10, 32px);
    grid-template-rows: repeat(10, 32px);
    gap: 4px;
    width: auto;
    justify-content: center;
}

/* Oh h1 格子樣式 - 覆蓋 sudoku-cell 基礎樣式 */
.sudoku-board.mode-ohh1 .ohh1-cell {
    cursor: pointer;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    aspect-ratio: 1 / 1;
    width: auto;
    height: auto;
}

.ohh1-cell:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 顏色樣式 */
.ohh1-empty {
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
}

.ohh1-red {
    background: linear-gradient(135deg, #ff6b9d 0%, #ff4581 100%);
}

.ohh1-blue {
    background: linear-gradient(135deg, #87ceeb 0%, #5fbff9 100%);
}

/* 固定格子（題目預設） */
.ohh1-fixed {
    opacity: 0.8;
    cursor: default;
}

.ohh1-fixed:hover {
    transform: none;
    box-shadow: none;
}

/* ===== Nonogram 遊戲樣式 ===== */

/* Nonogram 模式的格子系統 (需要額外的行列放置提示) */
.sudoku-board.mode-nonogram.grid-5 {
    grid-template-columns: auto repeat(5, 40px);
    grid-template-rows: auto repeat(5, 40px);
    gap: 2px;
    width: auto;
    max-width: 100%;
}

.sudoku-board.mode-nonogram.grid-10 {
    grid-template-columns: auto repeat(10, 28px);
    grid-template-rows: auto repeat(10, 28px);
    gap: 1px;
    width: auto;
    max-width: 100%;
}

.sudoku-board.mode-nonogram.grid-15 {
    grid-template-columns: auto repeat(15, 20px);
    grid-template-rows: auto repeat(15, 20px);
    gap: 1px;
    width: auto;
    max-width: 100%;
}

/* Nonogram 模式下重置數獨的邊框樣式 */
.sudoku-board.mode-nonogram .sudoku-cell {
    border: none;
    border-radius: 0;
}

/* Nonogram 提示樣式 */
.nonogram-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: #666;
    background: #f5f5f5;
    padding: 2px;
}

/* 左上角佔位 */
.nonogram-corner {
    background: transparent;
}

.nonogram-hint-col {
    /* 列提示垂直排列，底部對齊（靠近格子） */
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    gap: 2px;
    padding: 4px;
}

/* Nonogram 格子樣式 - 覆蓋所有 sudoku-cell 基礎樣式 */
.sudoku-board.mode-nonogram .nonogram-cell {
    cursor: pointer;
    border: 1px solid #999;
    border-radius: 0 !important;
    transition: all 0.15s ease;
    aspect-ratio: 1 / 1;
    width: auto;
    height: auto;
}

.sudoku-board.mode-nonogram .nonogram-cell:hover {
    background: #e8e8e8;
}

/* 格子狀態 */
.sudoku-board.mode-nonogram .nonogram-empty {
    background: white !important;
}

.sudoku-board.mode-nonogram .nonogram-filled {
    background: #333 !important;
}

.nonogram-marked {
    background: white;
    color: #999;
    font-size: 1.2rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== Nerdle 遊戲樣式 ===== */

/* Nerdle 模式基礎樣式 */
.sudoku-board.mode-nerdle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding: 20px;
}

/* Nerdle 容器 */
.nerdle-container {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Nerdle 每行 */
.nerdle-row {
    display: flex;
    gap: 5px;
}

/* Nerdle 格子 */
.nerdle-cell {
    width: 40px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 700;
    border: 2px solid #ccc;
    border-radius: 5px;
    background: white;
    color: #333;
}

/* 當前輸入行 */
.nerdle-cell.nerdle-current {
    border-color: #ff6b9d;
}

/* 顏色狀態 */
.nerdle-cell.nerdle-green {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    color: white;
    border-color: #22c55e;
}

.nerdle-cell.nerdle-purple {
    background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
    color: white;
    border-color: #8b5cf6;
}

.nerdle-cell.nerdle-black {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
    color: white;
    border-color: #4b5563;
}

/* Nerdle 鍵盤 */
.nerdle-keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.nerdle-keyboard-row {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Nerdle 按鍵 */
.nerdle-key {
    width: 36px;
    height: 40px;
    border: none;
    border-radius: 6px;
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.nerdle-key:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.nerdle-key:active {
    transform: translateY(0);
}

.nerdle-key-wide {
    width: 70px;
    font-size: 0.9rem;
    background: linear-gradient(135deg, #ff9a9e 0%, #ff6b9d 100%);
    color: white;
}

/* ===== Minesweeper 踩地雷遊戲樣式 ===== */

/* Minesweeper 模式 基礎 樣式 */
.sudoku-board.mode-minesweeper {
    width: auto;
    justify-content: center;
    gap: 0;
    padding: 4px;
    background: #bdbdbd;
    border-radius: 4px;
    border: 3px solid #999;
}

/* 各難度格子大小 */
.sudoku-board.mode-minesweeper.grid-9 {
    grid-template-columns: repeat(9, 34px);
    grid-template-rows: repeat(9, 34px);
}

.sudoku-board.mode-minesweeper.grid-12 {
    grid-template-columns: repeat(12, 28px);
    grid-template-rows: repeat(12, 28px);
}

.sudoku-board.mode-minesweeper.grid-16 {
    grid-template-columns: repeat(16, 23px);
    grid-template-rows: repeat(16, 23px);
}

/* 格子基礎樣式 */
.mine-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    cursor: pointer;
    user-select: none;
    transition: all 0.1s ease;
    position: relative;
    border: none;
    font-family: 'Nunito', sans-serif;
}

/* 未揭開格子 - 3D 凸起 */
.mine-hidden {
    background: linear-gradient(145deg, #e6e6e6 0%, #c8c8c8 100%);
    border-top: 2px solid #f5f5f5;
    border-left: 2px solid #f0f0f0;
    border-right: 2px solid #999;
    border-bottom: 2px solid #999;
    border-radius: 2px;
}

.mine-hidden:hover {
    background: linear-gradient(145deg, #f0f0f0 0%, #d5d5d5 100%);
    transform: scale(1.02);
}

.mine-hidden:active {
    border-top: 2px solid #999;
    border-left: 2px solid #999;
    border-right: 2px solid #f5f5f5;
    border-bottom: 2px solid #f0f0f0;
    background: #c8c8c8;
}

/* 揭開的格子 */
.mine-revealed {
    background: #e8e8e8;
    border: 1px solid #ccc;
    border-radius: 0;
    cursor: default;
    font-size: 0.95rem;
}

.sudoku-board.mode-minesweeper.grid-9 .mine-revealed {
    font-size: 1.1rem;
}

.sudoku-board.mode-minesweeper.grid-12 .mine-revealed {
    font-size: 0.9rem;
}

.sudoku-board.mode-minesweeper.grid-16 .mine-revealed {
    font-size: 0.75rem;
}

/* 旗標格子 */
.mine-flagged {
    background: linear-gradient(145deg, #e6e6e6 0%, #c8c8c8 100%);
    border-top: 2px solid #f5f5f5;
    border-left: 2px solid #f0f0f0;
    border-right: 2px solid #999;
    border-bottom: 2px solid #999;
    border-radius: 2px;
    animation: flagPlant 0.3s ease;
}

.sudoku-board.mode-minesweeper.grid-9 .mine-flagged,
.sudoku-board.mode-minesweeper.grid-9 .mine-hidden {
    font-size: 1.1rem;
}

.sudoku-board.mode-minesweeper.grid-12 .mine-flagged,
.sudoku-board.mode-minesweeper.grid-12 .mine-hidden {
    font-size: 0.85rem;
}

.sudoku-board.mode-minesweeper.grid-16 .mine-flagged,
.sudoku-board.mode-minesweeper.grid-16 .mine-hidden {
    font-size: 0.7rem;
}

@keyframes flagPlant {
    0% {
        transform: scale(0.5) rotate(-15deg);
    }

    60% {
        transform: scale(1.15) rotate(5deg);
    }

    100% {
        transform: scale(1) rotate(0);
    }
}

/* 踩到地雷 - 爆炸效果 */
.mine-exploded {
    background: linear-gradient(135deg, #ff4444 0%, #cc0000 100%) !important;
    border: 1px solid #cc0000;
    animation: mineExplode 0.5s ease;
}

@keyframes mineExplode {
    0% {
        transform: scale(1);
        background: #e8e8e8;
    }

    30% {
        transform: scale(1.3);
        background: #ff6666;
    }

    60% {
        transform: scale(0.9);
    }

    100% {
        transform: scale(1);
    }
}

/* 數字顏色 */
.mine-number-1 {
    color: #2563eb;
}

.mine-number-2 {
    color: #16a34a;
}

.mine-number-3 {
    color: #dc2626;
}

.mine-number-4 {
    color: #7c3aed;
}

.mine-number-5 {
    color: #b91c1c;
}

.mine-number-6 {
    color: #0891b2;
}

.mine-number-7 {
    color: #1e293b;
}

.mine-number-8 {
    color: #6b7280;
}

/* 響應式調整 */
@media (max-width: 480px) {
    .sudoku-board.mode-minesweeper.grid-9 {
        grid-template-columns: repeat(9, 30px);
        grid-template-rows: repeat(9, 30px);
    }

    .sudoku-board.mode-minesweeper.grid-12 {
        grid-template-columns: repeat(12, 24px);
        grid-template-rows: repeat(12, 24px);
    }

    .sudoku-board.mode-minesweeper.grid-16 {
        grid-template-columns: repeat(16, 18px);
        grid-template-rows: repeat(16, 18px);
    }

    .sudoku-board.mode-minesweeper.grid-16 .mine-revealed {
        font-size: 0.6rem;
    }

    .sudoku-board.mode-minesweeper.grid-16 .mine-flagged,
    .sudoku-board.mode-minesweeper.grid-16 .mine-hidden {
        font-size: 0.55rem;
    }
}

/* Minesweeper 模式切換控制項 */
.minesweeper-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin: 1rem 0;
}

.btn-mine-mode {
    flex: 1;
    max-width: 200px;
    padding: 1rem;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    opacity: 0.6;
    background: linear-gradient(135deg, #e8e8e8, #d0d0d0);
    color: #666;
}

.btn-mine-mode.active {
    opacity: 1;
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.6);
    background: linear-gradient(135deg, var(--lavender), var(--purple));
    color: white;
}

.btn-mine-mode .btn-icon {
    font-size: 1.5rem;
}

.btn-mine-mode:hover {
    opacity: 0.8;
}

.btn-mine-mode.active:hover {
    opacity: 1;
    transform: scale(1.08);
}

/* 響應式調整 - 手機版 */
@media (max-width: 480px) {
    .minesweeper-controls {
        gap: 0.5rem;
        margin: 0.75rem 0;
    }

    .btn-mine-mode {
        padding: 0.75rem;
        font-size: 1rem;
    }

    .btn-mine-mode .btn-icon {
        font-size: 1.3rem;
    }
}

/* Mastermind Game Styles */
.mastermind-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1rem;
    max-width: 500px;
    margin: 0 auto;
}

.mastermind-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--secondary-pink);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Guess History */
.mastermind-history {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
}

.mastermind-guess-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Color Pegs */
.mastermind-pegs {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.mastermind-peg {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #999;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2), inset 0 -2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.mastermind-peg.empty {
    background: linear-gradient(135deg, #f0f0f0, #d0d0d0);
    border: 2px dashed #aaa;
}

.mastermind-pegs.current .mastermind-peg {
    width: 50px;
    height: 50px;
}

/* Feedback Pegs */
.mastermind-feedback {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    width: 60px;
    justify-content: center;
}

.mastermind-feedback-peg {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid #666;
}

.mastermind-feedback-peg.black {
    background: #1a1a1a;
}

.mastermind-feedback-peg.white {
    background: #e5e7eb;
}

/* Current Section */
.mastermind-current {
    padding: 1rem;
    background: linear-gradient(135deg, rgba(255, 240, 245, 0.8), rgba(255, 255, 255, 0.8));
    border-radius: 15px;
    box-shadow: 0 4px 10px rgba(255, 107, 157, 0.15);
}

/* Color Palette */
.mastermind-palette {
    padding: 1rem;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 240, 245, 0.9));
    border-radius: 15px;
}

.mastermind-colors {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.mastermind-color-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid #999;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2), inset 0 -2px 4px rgba(0, 0, 0, 0.2);
}

.mastermind-color-btn:hover {
    transform: scale(1.15);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3), inset 0 -2px 4px rgba(0, 0, 0, 0.2);
    border-color: #666;
}

.mastermind-color-btn:active {
    transform: scale(0.95);
}

/* Control Buttons */
.mastermind-controls {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-mastermind {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-family: 'Nunito', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: linear-gradient(135deg, var(--lavender), var(--purple));
    color: white;
    box-shadow: 0 4px 15px rgba(201, 177, 255, 0.4);
}

.btn-mastermind:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(201, 177, 255, 0.5);
}

.btn-mastermind:active {
    transform: translateY(0) scale(0.98);
}

.btn-mastermind.submit {
    background: linear-gradient(135deg, var(--primary-pink), var(--secondary-pink));
    box-shadow: 0 4px 15px rgba(255, 107, 157, 0.4);
}

.btn-mastermind.submit:hover {
    box-shadow: 0 6px 20px rgba(255, 107, 157, 0.5);
}

.mastermind-error {
    color: var(--error-color);
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 0.5rem;
    text-align: center;
    animation: shake 0.3s ease;
}

/* Responsive Design */
@media (max-width: 480px) {
    .mastermind-container {
        gap: 1rem;
        padding: 0.5rem;
    }

    .mastermind-peg {
        width: 32px;
        height: 32px;
    }

    .mastermind-pegs.current .mastermind-peg {
        width: 40px;
        height: 40px;
    }

    .mastermind-color-btn {
        width: 40px;
        height: 40px;
    }

    .btn-mastermind {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }

    .mastermind-colors {
        gap: 0.5rem;
    }
}

/* Pipe / Netwalk Game Styles */
/* Handled via grid cell size instead of container max-width */

.mode-pipe {
    gap: 1px;
    background: #2c3e50;
    padding: 5px;
    display: grid;
    justify-content: center;
    overflow-x: auto;
}

/* Scoped to .mode-pipe to avoid affecting other game modes */
.sudoku-board.mode-pipe.grid-5 {
    grid-template-columns: repeat(5, 60px);
    grid-template-rows: repeat(5, 60px);
}

.sudoku-board.mode-pipe.grid-7 {
    /* Fixed width ensures tight packing without gaps */
    grid-template-columns: repeat(7, 50px);
    grid-template-rows: repeat(7, 50px);
}

.sudoku-board.mode-pipe.grid-9 {
    grid-template-columns: repeat(9, 42px);
    grid-template-rows: repeat(9, 42px);
}



.pipe-cell {
    width: 100%;
    height: 100%;
    background: #34495e;
    border: 0;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
    /* Subtle grid line */
}

/* Override default selected style for pipe cells */
.pipe-cell.selected {
    background: #34495e;
    /* Keep original background */
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4);
    /* Clearer white border for selection */
    z-index: 5;
    /* Ensure border is visible */
}

.pipe-cell:hover:not(.pipe-source) {
    background: #3d566e;
}

/* Pipe lines using pseudo-elements */
.pipe-cell::before,
.pipe-cell::after {
    content: '';
    position: absolute;
    background: #7f8c8d;
    transition: all 0.3s ease;
}

/* Straight pipe - horizontal (rotation 0) */
.pipe-straight.pipe-rotation-0::before {
    width: 100%;
    height: 6px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

/* Straight pipe - vertical (rotation 1) */
.pipe-straight.pipe-rotation-1::before {
    width: 6px;
    height: 100%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

/* Straight pipe - horizontal (rotation 2, same as 0) */
.pipe-straight.pipe-rotation-2::before {
    width: 100%;
    height: 6px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

/* Straight pipe - vertical (rotation 3, same as 1) */
.pipe-straight.pipe-rotation-3::before {
    width: 6px;
    height: 100%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

/* Corner pipe - top-right (rotation 0) */
.pipe-corner.pipe-rotation-0::before {
    width: 50%;
    height: 6px;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
}

.pipe-corner.pipe-rotation-0::after {
    width: 6px;
    height: 50%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

/* Corner pipe - bottom-right (rotation 1) */
.pipe-corner.pipe-rotation-1::before {
    width: 50%;
    height: 6px;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
}

.pipe-corner.pipe-rotation-1::after {
    width: 6px;
    height: 50%;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
}

/* Corner pipe - bottom-left (rotation 2) */
.pipe-corner.pipe-rotation-2::before {
    width: 50%;
    height: 6px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.pipe-corner.pipe-rotation-2::after {
    width: 6px;
    height: 50%;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
}

/* Corner pipe - top-left (rotation 3) */
.pipe-corner.pipe-rotation-3::before {
    width: 50%;
    height: 6px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.pipe-corner.pipe-rotation-3::after {
    width: 6px;
    height: 50%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

/* T-junction pipe - no left (rotation 0) */
.pipe-t.pipe-rotation-0::before {
    width: 6px;
    height: 100%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

.pipe-t.pipe-rotation-0::after {
    width: 50%;
    height: 6px;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
}

/* T-junction pipe - no top (rotation 1) */
.pipe-t.pipe-rotation-1::before {
    width: 100%;
    height: 6px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.pipe-t.pipe-rotation-1::after {
    width: 6px;
    height: 50%;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
}

/* T-junction pipe - no right (rotation 2) */
.pipe-t.pipe-rotation-2::before {
    width: 6px;
    height: 100%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

.pipe-t.pipe-rotation-2::after {
    width: 50%;
    height: 6px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

/* T-junction pipe - no bottom (rotation 3) */
.pipe-t.pipe-rotation-3::before {
    width: 100%;
    height: 6px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.pipe-t.pipe-rotation-3::after {
    width: 6px;
    height: 50%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

/* Cross pipe - all directions */
.pipe-cross::before {
    width: 100%;
    height: 6px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.pipe-cross::after {
    width: 6px;
    height: 100%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

/* Connected pipes glow */
.pipe-cell.pipe-connected::before,
.pipe-cell.pipe-connected::after {
    background: #f39c12;
    box-shadow: 0 0 10px #f39c12, 0 0 20px rgba(243, 156, 18, 0.5);
}

/* Power source */
.pipe-cell.pipe-source {
    background: radial-gradient(circle, #e74c3c, #c0392b);
    cursor: default;
}

.pipe-cell.pipe-source::before {
    content: '⚡';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    color: #f1c40f;
    animation: pulse 1.5s infinite;
    z-index: 10;
}

.pipe-cell.pipe-source::after {
    background: #f39c12;
    box-shadow: 0 0 15px #f39c12, 0 0 30px rgba(243, 156, 18, 0.7);
}

@keyframes pulse {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 0.8;
    }
}

/* Light Bulb Styles */
.pipe-bulb {
    background: #2c3e50;
}

/* Bulb connection point (base) */
.pipe-bulb::before {
    content: '';
    position: absolute;
    width: 30%;
    height: 6px;
    background: #7f8c8d;
    transition: all 0.3s ease;
}

/* Bulb rotation 0 - connection at top */
.pipe-bulb.pipe-rotation-0::before {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

/* Bulb rotation 1 - connection at right */
.pipe-bulb.pipe-rotation-1::before {
    right: 0;
    top: 50%;
    width: 6px;
    height: 30%;
    transform: translateY(-50%);
}

/* Bulb rotation 2 - connection at bottom */
.pipe-bulb.pipe-rotation-2::before {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

/* Bulb rotation 3 - connection at left */
.pipe-bulb.pipe-rotation-3::before {
    left: 0;
    top: 50%;
    width: 6px;
    height: 30%;
    transform: translateY(-50%);
}

/* Bulb icon (unlit) */
.pipe-bulb::after {
    content: '💡';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.4rem;
    filter: grayscale(100%) brightness(0.5);
    transition: all 0.3s ease;
}

/* Connected bulb glows */
.pipe-bulb.pipe-connected::before {
    background: #f39c12;
    box-shadow: 0 0 10px #f39c12;
}

.pipe-bulb.pipe-connected::after {
    filter: grayscale(0%) brightness(1.2);
    text-shadow: 0 0 15px #ffd700, 0 0 25px #ffd700;
}


/* Grid size overrides for different game modes */
.sudoku-board.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

.sudoku-board.grid-5 {
    grid-template-columns: repeat(5, 1fr);
}

.sudoku-board.grid-6 {
    grid-template-columns: repeat(6, 1fr);
}

/* KenKen Game Styles */
.mode-kenken {
    padding: 10px;
    gap: 0;
    /* Grid template columns will be set by JS via grid-N class */
}

/* Base KenKen Cell */
.kenken-cell {
    background-color: white;
    border: 1px dotted #ccc;
    /* Light border between cells in same cage */
    position: relative;
    font-size: 1.5rem;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
}

/* Cage Borders - Thick borders */
.kenken-cell.cage-border-top {
    border-top: 3px solid #333;
}

.kenken-cell.cage-border-bottom {
    border-bottom: 3px solid #333;
}

.kenken-cell.cage-border-left {
    border-left: 3px solid #333;
}

.kenken-cell.cage-border-right {
    border-right: 3px solid #333;
}

/* Operation Label */
.kenken-operation {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    color: #000;
    line-height: 1;
    z-index: 2;
    pointer-events: none;
}

/* Cell Value */
.cell-value {
    z-index: 1;
    font-weight: 600;
}

/* Notes */
.cell-notes {
    font-size: 0.6rem;
    color: #666;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    align-items: center;
    justify-items: center;
    padding: 2px;
}

/* States */
.kenken-cell.selected {
    background-color: var(--primary-pink);
    color: white;
}

.kenken-cell.highlighted {
    background-color: var(--highlight-blue);
}

.kenken-cell.error {
    color: var(--error-color);
    background-color: #fee2e2;
}

.kenken-cell:hover:not(.selected) {
    background-color: #f8fafc;
}