/* 設定圖示樣式 */
.icon-settings {
    display: inline-block;
    width: 28px;
    height: 28px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23333" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09a1.65 1.65 0 0 0-1-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09a1.65 1.65 0 0 0 1.51-1 1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33h.09A1.65 1.65 0 0 0 11 3.09V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51h.09a1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82v.09c.2.63.87 1 1.51 1H21a2 2 0 0 1 0 4h-.09c-.64 0-1.31.37-1.51 1z"/></svg>') center/contain no-repeat;
    vertical-align: middle;
}

/* 語言選擇器樣式 */
.language-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.lang-btn {
    padding: 6px 12px;
    font-size: 12px;
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    color: #666;
}

.lang-btn:hover {
    background-color: #e8e8e8;
    border-color: #999;
}

.lang-btn.active {
    background-color: #4caf50;
    color: white;
    border-color: #45a049;
    font-weight: bold;
}

body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 6px 8px;
    background-color: #f4f4f9;
    gap: 4px;
    box-sizing: border-box;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}


#error-count.has-error {
    color: #e74c3c;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.pause-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    gap: 24px;
}

.pause-overlay .pause-text {
    font-size: 48px;
    color: white;
}

.pause-overlay .resume-btn {
    padding: 12px 24px;
    font-size: 18px;
    background-color: #4caf50;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
    min-width: 160px;
}

.pause-overlay .resume-btn:hover {
    background-color: #45a049;
}

.pause-overlay .new-game-text {
    font-size: 24px;
    color: white;
    margin-top: 20px;
    font-weight: bold;
}

.pause-overlay .difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    margin-top: 10px;
}

.pause-overlay .difficulty-btn {
    padding: 12px 24px;
    font-size: 18px;
    background-color: #2196F3;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
    min-width: 160px;
}

.pause-overlay .difficulty-btn:hover {
    background-color: #1976D2;
    transform: translateY(-2px);
}

.pause-overlay .difficulty-btn:active {
    transform: translateY(0);
}

.console-toast {
    position: fixed;
    bottom: 16px;
    left: 8px;
    right: 8px;
    display: block;
    padding: 0;
    background: transparent;
    color: #555;
    border: none;
    border-radius: 0;
    box-shadow: none;
    font-size: 13px;
    line-height: 1.4;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    white-space: pre-line;
    text-align: center;
    font-weight: normal;
}

.console-toast.show {
    opacity: 1;
    visibility: visible;
}

.loading-bar {
    width: 200px;
    height: 8px;
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    overflow: hidden;
}

.loading-progress {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #007bff, #00d4ff);
    animation: loading 1.2s ease-in-out infinite;
}

@keyframes loading {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    border: 3px solid #333;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    width: min(100%, 85vw);
    max-width: 360px;
    height: min(100vw, 85vw);
    max-height: 360px;
    touch-action: manipulation;
}

.cell {
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid #ccc;
    font-size: clamp(16px, 3.5vw, 20px);
    font-weight: normal;
    box-sizing: border-box;
    background-color: #fff;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    color: #1976d2;
    overflow: visible;
    min-width: 0;
    min-height: 0;
    position: relative;
}

/* 選中的格子 */
.cell.selected {
    background-color: #fff9e6;
    box-shadow: inset 0 0 4px #ffb74d;
}

/* 粗線分隔 3x3 區塊 */
.cell:nth-child(3n) {
    border-right: 3px solid #333;
}
/* 水平粗線：在第 3 行與第 6 行之後畫粗底線（對應索引 19-27 與 46-54） */
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 3px solid #333;
}
/* 每一行的最後一個單元格，清除右側粗線 */
.cell:nth-child(9n) {
    border-right: 1px solid #ccc; 
}
/* 整個網格的最後一行，清除底部粗線 */
.grid-container div:nth-child(n+73):nth-child(-n+81) {
    border-bottom: 1px solid #ccc;
}

.given {
    background-color: #eee;
    color: #1976d2;
    font-weight: bold;
}

.hint {
    color: #e74c3c !important;
    font-weight: bold;
}

.hint-border {
    border: 3px solid #e74c3c;
    box-shadow: 0 0 10px rgba(231, 76, 60, 0.5);
    background-color: #fff;
}

.hint-related {
    background-color: #fff9e6;
    border: 2px solid #ffc107;
}

/* hint-border 的白色背景優先於 hint-related */
.hint-border.hint-related {
    background-color: #fff;
}

/* 候選數字容器 */
.notes-container {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 0px;
    width: 100%;
    height: 100%;
    padding: 0px;
    box-sizing: border-box;
    overflow: visible;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.notes-container.hidden {
    display: none;
}

/* 候選數字單元格 */
.note-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(12px, 3vw, 14px);
    font-weight: 600;
    color: #757575;
    background-color: transparent;
    border: none;
    border-radius: 2px;
    user-select: none;
    transition: all 0.1s ease;
    line-height: 1;
}

.note-cell.hidden {
    display: none;
}

.note-cell.inactive {
    color: transparent;
}

.note-cell.active-candidate {
    color: #bbb;
}

.note-cell:hover {
    background-color: transparent;
}

.cell.highlight-related {
    background-color: #f0f0f0;
}

.cell.highlight-same {
    background-color: #ffe6b8;
}

.note-cell.highlight-same-candidate {
    background-color: transparent;
    color: #ffa600;
    font-weight: bold;
}

/* 狀態提示 */
#status {
    font-size: 14px;
    color: #555;
}
.main-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 360px;
    position: relative;
}

.controls-panel {
    width: 100%;
    padding: 8px;
    background-color: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-sizing: border-box;
    position: static;
    margin-top: 8px;
}

.header-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    padding-bottom: 6px;
    border-bottom: 1px solid #ddd;
    margin-bottom: 2px;
}

.button-row {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 2px;
}

.icon-btn {
    padding: 6px;
    background-color: transparent;
    border: none;
    cursor: pointer;
    font-size: 20px;
    transition: transform 0.1s ease;
}

.icon-btn:hover {
    transform: scale(1.1);
}

.icon-btn:active {
    transform: scale(0.95);
}

.timer-display {
    font-size: 14px;
    color: #555;
    font-weight: 500;
}

.status-display {
    font-size: 12px;
    color: #888;
    flex: 1;
    text-align: center;
}

.error-display {
    font-size: 12px;
    color: #555;
    white-space: nowrap;
}

.answer-row {
    /* inherits from .button-row */
}

.candidate-row {
    /* inherits from .button-row */
}

.utility-row {
    display: flex;
    align-items: center;
    justify-content: space-around;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.difficulty-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
}

.difficulty-btn {
    background-color: #f5f5f5;
    border: 1px solid #bdbdbd;
    color: #424242;
    font-size: 22px;
    padding: 6px;
    line-height: 1;
}

.difficulty-btn:hover {
    background-color: #e0e0e0;
    border-color: #9e9e9e;
    transform: scale(1.05);
}

.difficulty-btn:active {
    background-color: #bdbdbd;
    transform: scale(0.97);
}

.difficulty-btn.active {
    background-color: #ffe082;
    border-color: #ffb300;
    color: #5d3d00;
    box-shadow: inset 0 0 0 2px #ffa000;
    transform: scale(1.08);
}

.utility-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    flex: 1;
    min-width: 50px;
    transition: all 0.1s ease;
    position: relative;
}

.utility-icon-btn:hover {
    transform: scale(1.1);
}
.utility-icon-btn:active {
    transform: scale(0.95);
}
.utility-icon-btn:disabled,
.utility-icon-btn:disabled:hover {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.utility-icon-btn .icon {
    font-size: 28px;
    line-height: 1;
    position: relative;
}

.utility-icon-btn .badge {
        position: absolute;
        top: -6px;
        right: -6px;
    color: #ff0000;
    font-size: 15px;
    font-weight: bold;
    line-height: 1;
    pointer-events: none;
}

.kbd-btn {
    padding: 8px 4px;
    font-size: 14px;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.1s ease;
    width: 100%;
    box-sizing: border-box;
    touch-action: manipulation;
    min-height: 36px;
}

/* 輸入答案按鈕 - 藍色系 */
.answer-btn {
    background-color: #e3f2fd;
    border: 1px solid #90caf9;
    color: #1976d2;
}

.answer-btn:hover {
    background-color: #bbdefb;
    border-color: #42a5f5;
}

.answer-btn:active {
    background-color: #90caf9;
    transform: scale(0.95);
}

/* 候選數字按鈕 - 灰色系 */
.candidate-btn {
    background-color: #f5f5f5;
    border: 1px solid #bdbdbd;
    color: #616161;
}

.candidate-btn:hover {
    background-color: #e0e0e0;
    border-color: #9e9e9e;
}

.candidate-btn:active {
    background-color: #bdbdbd;
    transform: scale(0.95);
}

.answer-btn:disabled,
.candidate-btn:disabled {
    background-color: #e0e0e0;
    border-color: #bdbdbd;
    color: #9e9e9e;
    cursor: not-allowed;
    opacity: 0.5;
}

.answer-btn:disabled:hover,
.candidate-btn:disabled:hover {
    background-color: #e0e0e0;
    border-color: #bdbdbd;
    transform: none;
}

.answer-btn.active {
    background-color: #90caf9;
    border-color: #1976d2;
    color: #0d47a1;
    font-weight: bold;
}

.candidate-btn.active {
    background-color: #bdbdbd;
    border-color: #757575;
    color: #424242;
    font-weight: bold;
}

/* 手機優化 */
@media (max-width: 600px) {
    body {
        padding: 2px 4px;
        gap: 3px;
    }
    
    .grid-container {
        width: 96vw;
        max-width: 380px;
        height: 96vw;
        max-height: 380px;
    }
    
    .main-layout {
        gap: 6px;
        max-width: 380px;
    }
    
    .controls-panel {
        padding: 6px;
        gap: 4px;
    }
    
.button-row {
    gap: 2px;
}

.kbd-btn {
    padding: 7px 3px;
    font-size: 13px;
    min-height: 34px;
}    #status {
        font-size: 10px;
    }
}

@media (max-width: 400px) {
    body {
        padding: 2px 3px;
    }
    
    .main-layout {
        max-width: 360px;
    }
    
    .grid-container {
        max-width: 360px;
        max-height: 360px;
    }
    
    .kbd-btn {
        padding: 6px 2px;
        font-size: 12px;
        min-height: 32px;
    }
    
    .note-cell {
        font-size: 11px;
        font-weight: 600;
    }
    
    .controls-panel {
        padding: 5px;
    }
}