/* ===== リセットとベーススタイル ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --main-color: #1e40af;
    --secondary-color: #3b82f6;
    --accent-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --dark-bg: #1f2937;
    --light-bg: #f3f4f6;
    --water-color: #3b82f6;
    --water-dark: #1e40af;
    --ship-color: #6b7280;
    --hit-color: #ef4444;
    --miss-color: #d1d5db;
    --sunk-color: #7f1d1d;
    --hover-color: #60a5fa;
    --border-radius: 8px;
    --transition: all 0.3s ease;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #1f2937;
    line-height: 1.6;
}

/* ===== ヘッダー ===== */
header {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    color: white;
    padding: 2rem 1rem;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
}

/* ===== メインコンテナ ===== */
main {
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* ===== ゲームステータス ===== */
.game-status {
    background: white;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2rem;
    align-items: center;
}

.status-panel h2 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
    color: var(--main-color);
}

.game-message {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--secondary-color);
    padding: 0.5rem;
    background: var(--light-bg);
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.turn-indicator {
    font-size: 0.95rem;
    color: #6b7280;
}

.score-panel {
    display: flex;
    gap: 2rem;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.score-item .label {
    font-size: 0.9rem;
    color: #6b7280;
}

.score-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--main-color);
}

/* ===== ゲームボード ===== */
.game-boards {
    background: white;
    border-radius: var(--border-radius);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.board-header {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.btn-view-toggle {
    background: var(--secondary-color);
    color: white;
    padding: 0.75rem 2rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-view-toggle:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.board-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 500px;
}

.board-wrapper {
    width: 100%;
    max-width: 500px;
    position: absolute;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    transform: translateX(0);
}

.board-wrapper.active {
    opacity: 1;
    visibility: visible;
    position: relative;
}

/* ゲーム終了時は両方のボードを並べて表示 */
.board-container:has(.board-wrapper:nth-child(1).active):has(.board-wrapper:nth-child(2).active) {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    min-height: auto;
}

.board-container:has(.board-wrapper:nth-child(1).active):has(.board-wrapper:nth-child(2).active) .board-wrapper {
    position: relative;
}

.board-wrapper h2 {
    text-align: center;
    margin-bottom: 1rem;
    color: var(--main-color);
    font-size: 1.3rem;
}

.board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 2px;
    background: var(--water-dark);
    padding: 4px;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    aspect-ratio: 1;
}

.cell {
    aspect-ratio: 1;
    background: var(--water-color);
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

/* 敵のボードのみホバー効果を適用 */
#enemyBoard .cell:not(.disabled):not(.hit):hover {
    background: var(--hover-color);
    transform: scale(1.1);
    z-index: 10;
}


.cell.ship {
    background: var(--ship-color);
}

.cell.hit {
    background: var(--hit-color);
}

.cell.hit::after {
    content: '💥';
    position: absolute;
    font-size: 1.5rem;
}

.cell.miss {
    background: var(--miss-color);
}

.cell.miss::after {
    content: '-';
    position: absolute;
    font-size: 1.2rem;
    color: white;
}

.cell.near {
    background: var(--warning-color);
}

.cell.near::after {
    content: '△';
    position: absolute;
    font-size: 1.5rem;
}

.cell.sunk {
    background: var(--sunk-color);
}

.cell.disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.cell.disabled:hover {
    transform: none;
}

.cell.preview {
    background: rgba(107, 114, 128, 0.5);
    border: 2px dashed var(--ship-color);
    position: relative;
}

.cell.preview-invalid {
    background: rgba(239, 68, 68, 0.5);
    border: 2px dashed var(--danger-color);
    position: relative;
}

/* カーソル位置に船名を表示 */
.cell[data-ship-instruction]::before {
    content: attr(data-ship-instruction);
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 64, 175, 0.95);
    color: white;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* 最後の手（直前に攻撃されたマス）のアニメーション */
.cell.last-move {
    animation: lastMoveAnimation 0.5s ease;
}

@keyframes lastMoveAnimation {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

.board-info {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.legend-ship,
.legend-hit,
.legend-miss,
.legend-near,
.legend-sunk {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid #ccc;
}

.legend-ship { background: var(--ship-color); }
.legend-hit { background: var(--hit-color); }
.legend-miss { background: var(--miss-color); }
.legend-near { background: var(--warning-color); }
.legend-sunk { background: var(--sunk-color); }

/* ===== 艦隊配置パネル ===== */
.setup-panel {
    background: white;
    border-radius: var(--border-radius);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.setup-panel h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--main-color);
    font-size: 1.5rem;
}

.difficulty-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--light-bg);
    border-radius: var(--border-radius);
}

.difficulty-selector label {
    font-weight: 600;
    color: var(--dark-bg);
    font-size: 1.1rem;
}

.difficulty-select {
    padding: 0.5rem 1rem;
    border: 2px solid var(--secondary-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    color: var(--dark-bg);
    background: white;
    cursor: pointer;
    transition: var(--transition);
    outline: none;
}

.difficulty-select:hover {
    border-color: var(--main-color);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.difficulty-select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.difficulty-select option {
    padding: 0.5rem;
}

.ships-to-place {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.ship-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--light-bg);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
}

.ship-item:hover {
    background: #e5e7eb;
    transform: translateX(5px);
}

.ship-item.selected {
    border-color: var(--main-color);
    background: #dbeafe;
}

.ship-item.placed {
    opacity: 0.5;
    cursor: not-allowed;
}

.ship-item.placed:hover {
    transform: none;
}

.ship-name {
    min-width: 80px;
    font-weight: 600;
    color: var(--dark-bg);
}

.ship-preview {
    display: flex;
    gap: 2px;
    flex: 1;
}

.ship-preview::before {
    content: '';
    display: block;
}

.ship-preview.size-5::before { width: 150px; height: 25px; background: var(--ship-color); border-radius: 4px; }
.ship-preview.size-4::before { width: 120px; height: 25px; background: var(--ship-color); border-radius: 4px; }
.ship-preview.size-3::before { width: 90px; height: 25px; background: var(--ship-color); border-radius: 4px; }
.ship-preview.size-2::before { width: 60px; height: 25px; background: var(--ship-color); border-radius: 4px; }

.setup-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ===== コントロールパネル ===== */
.control-panel {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

/* ===== ボタン ===== */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translateY(0);
}

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

.btn-primary:hover {
    background: #1e3a8a;
}

.btn-primary:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #2563eb;
}

/* ===== ゲーム説明セクション ===== */
.game-description {
    background: white;
    border-radius: var(--border-radius);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.game-description h2 {
    color: var(--main-color);
    margin-bottom: 1rem;
    font-size: 1.8rem;
}

.game-description h3 {
    color: var(--secondary-color);
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-size: 1.3rem;
}

.game-description p {
    margin-bottom: 1rem;
    color: #4b5563;
}

.game-description ul,
.game-description ol {
    margin-left: 2rem;
    margin-bottom: 1rem;
    color: #4b5563;
}

.game-description li {
    margin-bottom: 0.5rem;
}

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

.modal.show {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    color: var(--main-color);
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #6b7280;
    transition: var(--transition);
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: var(--danger-color);
    transform: rotate(90deg);
}

.modal-body {
    padding: 1.5rem;
}

.modal-body h3 {
    color: var(--secondary-color);
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.modal-body ul {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.modal-body li {
    margin-bottom: 0.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.result-message {
    text-align: center;
    font-size: 1.5rem;
    font-weight: bold;
    padding: 2rem;
}

.result-message.victory {
    color: var(--accent-color);
}

.result-message.defeat {
    color: var(--danger-color);
}

.white-link{
    color:white;
}

/* ===== フッター ===== */
footer {
    background: var(--dark-bg);
    color: white;
    text-align: center;
    padding: 2rem 1rem;
    margin-top: 3rem;
}

footer p {
    margin-bottom: 0.5rem;
    opacity: 0.8;
}

/* ===== レスポンシブデザイン ===== */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .game-status {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .score-panel {
        justify-content: center;
    }
    
    .difficulty-selector {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .board-container:has(.board-wrapper:nth-child(1).active):has(.board-wrapper:nth-child(2).active) {
        grid-template-columns: 1fr;
    }
    
    .board {
        gap: 1px;
        padding: 2px;
    }
    
    .cell {
        font-size: 0.6rem;
    }
    
    .cell.hit::after,
    .cell.miss::after {
        font-size: 1rem;
    }
    
    .setup-panel,
    .game-boards {
        padding: 1rem;
    }
    
    .game-description {
        padding: 1rem;
    }
    
    .game-description h2 {
        font-size: 1.5rem;
    }
    
    .game-description h3 {
        font-size: 1.2rem;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }
    
    .board-wrapper {
        max-width: 100%;
    }
    
    .ship-preview.size-5::before { width: 100px; }
    .ship-preview.size-4::before { width: 80px; }
    .ship-preview.size-3::before { width: 60px; }
    .ship-preview.size-2::before { width: 40px; }
    
    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
}

/* ===== アクセシビリティ ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== 配置完了通知 ===== */
.ready-notification {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.ready-notification.show {
    opacity: 1;
}

.ready-notification-content {
    background: white;
    border-radius: 16px;
    padding: 3rem 2rem;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: bounceIn 0.6s ease;
}

@keyframes bounceIn {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.ready-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: rotate 2s ease-in-out infinite;
}

@keyframes rotate {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

.ready-notification-content h2 {
    color: var(--main-color);
    font-size: 2rem;
    margin-bottom: 1rem;
}

.ready-notification-content p {
    color: #4b5563;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.ready-instruction {
    color: var(--accent-color) !important;
    font-weight: bold;
    font-size: 1.2rem !important;
    margin: 1.5rem 0 2rem 0 !important;
}

.btn-start-game-large {
    background: linear-gradient(135deg, var(--accent-color) 0%, #059669 100%);
    color: white;
    padding: 1rem 2.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1.3rem;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

.btn-start-game-large:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.6);
}

.btn-start-game-large:active {
    transform: translateY(-1px);
}

/* ゲーム開始ボタンのパルスアニメーション */
.pulse-animation {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 4px 20px rgba(16, 185, 129, 0.6);
    }
}

/* ===== ユーティリティクラス ===== */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
