/* リセットとベース設定 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f0f2f5;
    color: #333;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* スクリーン切り替え */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    overflow: auto;
}

.screen.active {
    display: block;
}

/* 生成画面 */
#generatorScreen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
}

.title {
    text-align: center;
    color: white;
    font-size: 2.5rem;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.generator-card {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin-bottom: 30px;
}

.generator-card h2 {
    color: #667eea;
    margin-bottom: 25px;
    text-align: center;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 16px;
    transition: all 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.hint-text {
    display: block;
    margin-top: 5px;
    font-size: 0.85rem;
    color: #999;
}

.button-group {
    display: flex;
    gap: 15px;
    margin-top: 30px;
}

.btn {
    flex: 1;
    padding: 15px 20px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.btn-success {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(72, 187, 120, 0.3);
}

.btn-icon {
    font-size: 1.2rem;
}

.message-area {
    margin-top: 20px;
    padding: 15px;
    border-radius: 10px;
    text-align: center;
    font-weight: 500;
    display: none;
}

.message-area.show {
    display: block;
}

.message-area.success {
    background-color: #c6f6d5;
    color: #276749;
}

.message-area.error {
    background-color: #fed7d7;
    color: #9b2c2c;
}

.message-area.info {
    background-color: #bee3f8;
    color: #2c5282;
}

/* プレビューエリア */
.preview-area {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin-bottom: 30px;
    text-align: center;
}

.preview-area h3 {
    color: #667eea;
    margin-bottom: 20px;
}

.preview-svg {
    max-width: 100%;
    max-height: 400px;
    height: auto;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
}

/* レコードセクション */
.records-section {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin-bottom: 30px;
}

.records-section h2 {
    color: #667eea;
    margin-bottom: 20px;
    text-align: center;
}

.records-list {
    max-height: 300px;
    overflow-y: auto;
}

.no-records {
    text-align: center;
    color: #999;
    padding: 20px;
}

.record-item {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 12px 15px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.record-info {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
}

.record-hints {
    font-weight: 600;
    color: #667eea;
}

.record-date {
    font-size: 0.85rem;
    color: #666;
}

.record-time {
    font-size: 1.1rem;
    font-weight: bold;
    color: #48bb78;
    min-width: 60px;
    text-align: right;
}

/* フッター */
.footer {
    text-align: center;
    padding: 20px;
    color: white;
    opacity: 0.8;
}

/* プレイ画面 */
#playScreen {
    background: #1a1a2e;
    flex-direction: column;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

#playScreen.active {
    display: flex;
}

/* プレイヘッダー */
.play-header {
    height: 10%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    background: rgba(0,0,0,0.3);
}

.timer {
    font-size: min(8vw, 2rem);
    font-weight: bold;
    color: #48bb78;
    font-family: 'Courier New', monospace;
    text-shadow: 0 0 10px rgba(72, 187, 120, 0.5);
}

.quit-btn {
    background: #e53e3e;
    color: white;
    border: none;
    padding: min(2.5vw, 10px) min(5vw, 20px);
    border-radius: 8px;
    font-weight: 600;
    font-size: min(4vw, 1rem);
    cursor: pointer;
    transition: all 0.3s;
}

.quit-btn:hover {
    background: #c53030;
    transform: scale(1.05);
}

/* ゲームボード */
.game-board-container {
    height: 60%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

.game-board {
    width: 100%;
    max-width: min(90vw, 54vh);
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 0;
    background: #333;
    border: 3px solid #48bb78;
    border-radius: 8px;
    overflow: hidden;
}

.cell {
    background: #2d2d3d;
    border: 1px solid #444;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

/* ハイライトスタイル */
.cell.highlight-row {
    background: rgba(102, 126, 234, 0.15);
}

.cell.highlight-col {
    background: rgba(102, 126, 234, 0.15);
}

.cell.highlight-block {
    background: rgba(72, 187, 120, 0.15);
}

.cell.selected {
    background: #4a4a5e !important;
    border-color: #48bb78;
    box-shadow: inset 0 0 0 2px #48bb78;
    z-index: 1;
}

/* 3x3ブロックの境界線 */
.cell:nth-child(3n) {
    border-right: 2px solid #666;
}

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

.cell.selected {
    background: #4a4a5e !important;
    border-color: #48bb78;
    box-shadow: inset 0 0 0 2px #48bb78;
    z-index: 1;
}

.cell.fixed {
    background: #1a1a2e;
}

.cell-value {
    font-size: min(5vw, 1.8rem);
    font-weight: bold;
    color: white;
}

.cell.fixed .cell-value {
    color: #bbb;
}

.cell.user-input .cell-value {
    color: #48bb78;
}

/* 候補数字グリッド */
.candidates {
    position: absolute;
    top: 5%;
    left: 5%;
    right: 5%;
    bottom: 5%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 0;
}

.candidate {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(1.5vw, 0.7rem);
    color: #667eea;
    font-weight: 600;
}

/* コントロールパネル */
.control-panel {
    height: 30%;
    background: rgba(0,0,0,0.5);
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.number-buttons {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 8px;
    margin: 0 auto;
    width: 100%;
    max-width: 500px;
}

.num-btn {
    aspect-ratio: 1;
    background: #2d2d3d;
    color: white;
    border: 2px solid #444;
    border-radius: 8px;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.num-btn:hover {
    background: #3d3d4d;
    transform: scale(1.05);
}

.num-btn.active {
    background: #667eea;
    border-color: #667eea;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.5);
}

.action-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 0 auto;
    width: 100%;
    max-width: 500px;
}

.action-btn {
    background: #3d3d4d;
    color: white;
    border: 2px solid #555;
    border-radius: 8px;
    padding: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.action-btn:hover {
    background: #4d4d5d;
    transform: scale(1.05);
}

.action-btn.active {
    background: #e53e3e;
    border-color: #e53e3e;
    box-shadow: 0 0 15px rgba(229, 62, 62, 0.5);
}

.action-btn .icon {
    font-size: 1.2rem;
}

/* モーダル */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 1000;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-content h2 {
    color: #667eea;
    margin-bottom: 20px;
}

.modal-content p {
    color: #666;
    margin-bottom: 30px;
    line-height: 1.6;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .title {
        font-size: 2rem;
    }
    
    .generator-card {
        padding: 20px;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .num-btn {
        font-size: 1.2rem;
    }
    
    .action-btn {
        font-size: 0.85rem;
        padding: 10px;
    }
}