* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #1a1a1a;
    min-height: 100vh;
    max-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

.container {
    background: #2a2a2a;
    border-radius: 0;
    padding: 15px;
    box-shadow: none;
    max-width: 600px;
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: none;
}

header {
    text-align: center;
    margin-bottom: 10px;
    flex-shrink: 0;
}

header h1 {
    color: #ffffff;
    font-size: 1.5em;
    margin-bottom: 2px;
    font-weight: 300;
    letter-spacing: 1px;
}

.subtitle {
    color: #aaa;
    font-size: 0.7em;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.game-controls {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 10px; /* Space between the two control groups */
    flex-shrink: 0;
}

.game-control-group {
    display: flex;
    flex-direction: column;
    gap: 8px; /* Space between elements within a group */
    align-items: center; /* Center items horizontally within their group */
    flex-shrink: 0;
    /* Adjust width to ensure they take roughly half the space */
    flex: 1 1 auto;
    min-width: calc(50% - 10px);
}

.btn {
    padding: 6px 12px;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    background: #333;
    color: #ffffff;
}

.btn:hover {
    background: #444;
    border-color: #555;
}

.btn-primary {
    background: #1a1a1a;
    color: #ffffff;
    border: 1px solid #444;
}

.btn-primary:hover {
    background: #2a2a2a;
    border-color: #555;
}

.btn-secondary {
    background: #333;
    color: #ffffff;
    border: 1px solid #444;
}

.btn-secondary:hover {
    background: #444;
    border-color: #555;
}

.btn-danger {
    background: #333;
    color: #ffffff;
    border: 1px solid #444;
}

.btn-danger:hover {
    background: #444;
    border-color: #555;
}

.difficulty-selector {
    text-align: center;
    flex-shrink: 0;
    width: 100%; /* Ensure it takes full width within its group */
}

.difficulty-selector label {
    margin-right: 8px;
    font-weight: 500;
    color: #ccc;
    font-size: 11px;
}

.difficulty-selector select {
    padding: 4px 8px;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    background: #333;
    color: #ffffff;
}

.difficulty-selector select:hover {
    border-color: #555;
    background: #444;
}

.difficulty-selector select:focus {
    outline: none;
    border-color: #666;
}

.mode-selector {
    display: flex;
    align-items: center;
    justify-content: flex-end; /* Align mode button and indicator to the right */
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
    width: 100%; /* Take full width within its group */
}

.btn-mode {
    background: #333;
    color: #ffffff;
    padding: 6px 12px;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.btn-mode:hover {
    background: #444;
    border-color: #555;
}

.btn-mode.active {
    background: #1a1a1a;
    border-color: #555;
}

.mode-indicator {
    font-weight: 400;
    color: #aaa;
    font-size: 11px;
}

#modeStatus {
    color: #ffaa00;
    font-weight: 600;
}

.game-board-container {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
    flex: 1;
    min-height: 0;
    align-items: center;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 1px;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 0;
    padding: 1px;
    max-width: 100%;
    width: 100%;
    max-height: 100%;
    aspect-ratio: 1;
}

.cell {
    background: #333;
    border: 1px solid #555;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1em;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    position: relative;
    color: #ffffff;
}

.cell .cell-value {
    position: absolute;
    font-size: 1em;
    font-weight: 400;
    z-index: 2;
    color: #ffffff;
}

.cell .notes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    padding: 2px;
    gap: 1px;
}

.cell .note-number {
    font-size: 0.4em;
    font-weight: 300;
    color: #888;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.cell .note-number.visible {
    opacity: 1;
}

.cell:hover {
    background: #3a3a3a;
}

.cell.selected {
    background: #444;
    border: 1px solid #777;
}

/* 選択されたセルでも3x3ブロックの境界線を優先 */
.cell.selected:nth-child(3n):not(:nth-child(9n)) {
    border-right: 3px solid #888;
}

.cell.selected:nth-child(n+19):nth-child(-n+27),
.cell.selected:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 3px solid #888;
}

.cell.prefilled {
    background: #1a1a1a;
    color: #ffffff;
    font-weight: 500;
    cursor: default;
}

.cell.prefilled:hover {
    background: #1a1a1a;
}

.cell.error {
    background: #3a2a2a;
    color: #ffffff;
    border: 1px solid #777;
}

.cell.correct {
    background: #2a3a2a;
    color: #ffffff;
}

/* 3x3ブロックの境界線を太く（3列目と6列目の右側） */
.cell:nth-child(3n):not(:nth-child(9n)) {
    border-right: 3px solid #777;
}

/* 3x3ブロックの境界線を太く（3行目と6行目の下側） */
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 3px solid #777;
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
    margin-bottom: 8px;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    flex-shrink: 0;
}

.number-btn {
    padding: 12px 8px;
    border: 1px solid #444;
    border-radius: 4px;
    background: #333;
    font-size: 1em;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #ffffff;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.number-btn:hover {
    background: #444;
    color: #ffffff;
    border-color: #555;
}

.number-btn:active {
    background: #1a1a1a;
}

.number-btn[data-number="0"] {
    background: #333;
    color: #ffffff;
    border-color: #444;
}

.number-btn[data-number="0"]:hover {
    background: #444;
    border-color: #555;
}

.message {
    text-align: center;
    min-height: 20px;
    margin-bottom: 6px;
    font-weight: 400;
    font-size: 0.75em;
    flex-shrink: 0;
}

.message.success {
    color: #ccc;
}

.message.error {
    color: #aaa;
}

.message.info {
    color: #ccc;
}


.timer {
    text-align: right;
    font-size: 0.75em;
    font-weight: 400;
    color: #aaa;
    padding: 4px;
    background: #333;
    border-radius: 4px;
    border: 1px solid #444;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    width: 100%; /* Take full width within its group */
}

@media (max-width: 600px) {
    body {
        padding: 0;
    }

    .container {
        padding: 8px;
        height: 100vh;
        max-height: 100vh;
    }

    header {
        margin-bottom: 6px;
    }

    header h1 {
        font-size: 1.2em;
    }

    .subtitle {
        font-size: 0.6em;
    }

    .game-controls {
        gap: 6px;
        margin-bottom: 6px;
    }

    .game-control-group {
        gap: 6px; /* Adjusted gap for smaller screens */
        min-width: calc(50% - 6px); /* Adjusted for smaller screens */
    }

    .btn {
        padding: 5px 8px;
        font-size: 10px;
    }

    .difficulty-selector {
        /* margin-bottom removed, handled by group gap */
    }

    .difficulty-selector label {
        font-size: 10px;
    }

    .difficulty-selector select {
        padding: 3px 6px;
        font-size: 10px;
    }

    .mode-selector {
        gap: 6px;
        /* margin-bottom removed, handled by group gap */
    }

    .btn-mode {
        padding: 5px 8px;
        font-size: 10px;
    }

    .mode-indicator {
        font-size: 10px;
    }

    .game-board-container {
        margin-bottom: 6px; /* Already 6px, keep or adjust as needed */
    }

    .cell {
        font-size: 0.85em;
    }

    .cell .cell-value {
        font-size: 0.85em;
    }

    .cell .note-number {
        font-size: 0.35em;
    }

    .number-pad {
        gap: 4px;
        margin-bottom: 6px;
    }

    .number-btn {
        padding: 10px 4px;
        font-size: 0.9em;
        min-height: 40px;
    }

    .message {
        min-height: 16px;
        margin-bottom: 4px;
        font-size: 0.7em;
    }

    .timer {
        font-size: 0.7em;
        padding: 3px;
    }
}

