:root {
    --board-bg: #1a1a20;
    --cell-bg: #2a2a35;
    --cell-hover: #3a3a48;
    --accent-gold: #ffd700;
    --accent-red: #ff4444;
    --text-primary: #e0e0e0;
    --highlight-move: rgba(100, 255, 100, 0.4);
}

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

html {
    touch-action: manipulation;
}

body {
    background-color: #000000ec;
    color: var(--text-primary);
    font-family: 'Segoe UI', system-ui, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 40px;
}

.logo {
    width: 80vw;
    max-width: 300px;
}

.subtitle {
    color: #888;
    font-size: 0.9rem;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 600px;
}

@media (min-width: 768px) {
    .game-container {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        max-width: 900px;
    }
}

/* Hand Panel */
.hand {
    background: var(--board-bg);
    border-radius: 12px;
    padding: 15px 20px;
    text-align: center;
    min-width: 120px;
    border: 2px solid #333;
    transition: all 0.3s ease;
}

.hand.active {
    border-color: var(--accent-gold);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.hand h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.hand.white h3 {
    color: #fff;
}

.hand.black h3 {
    color: #666;
}

.hand-count {
    display: flex;
    justify-content: center;
    gap: 4px;
    min-height: 40px;
}

.hand-piece {
    width: 35px;
    height: 35px;
    object-fit: contain;
}

.must-drop {
    font-size: 0.75rem;
    color: var(--accent-red);
    animation: pulse 1s infinite;
    margin-top: 5px;
}

/* Board Section */
.board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    position: relative;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 10px;
    font-size: 0.85rem;
    color: #888;
}

.status-bar span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.turn-indicator {
    font-weight: bold;
}

.turn-indicator.white {
    color: #fff;
}

.turn-indicator.black {
    color: #666;
}

.phase-indicator {
    color: var(--accent-gold);
    font-weight: bold;
    text-transform: uppercase;
}

/* Board */
.board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    background: var(--board-bg);
    padding: 12px;
    border-radius: 16px;
    border: 4px solid #333;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    max-width: calc(100vw - 40px);
}

.cell {
    width: 70px;
    height: 70px;
    background: var(--cell-bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

@media (max-width: 420px) {
    body {
        padding: 10px;
    }

    .cell {
        width: 60px;
        height: 60px;
    }

    .piece {
        width: 50px;
        height: 50px;
    }

    /* スタート画面のレスポンシブ対応 */
    .mode-buttons {
        flex-direction: column;
        gap: 10px;
        width: 100%;
    }

    .mode-btn {
        width: 100%;
        padding: 15px 20px;
        flex-direction: row;
        justify-content: center;
    }

    .mode-icon {
        width: 35px;
        height: 35px;
    }

    .mode-btn span {
        font-size: 0.9rem;
    }

    .difficulty-buttons {
        flex-wrap: wrap;
        justify-content: center;
    }

    .difficulty-btn {
        padding: 8px 16px;
        font-size: 0.85rem;
    }

    .start-game-btn {
        padding: 12px 40px;
        font-size: 1rem;
    }

    .start-screen h1 {
        font-size: 1.8rem;
    }

    /* オンラインロビーのレスポンシブ対応 */
    .lobby-container {
        padding: 20px 15px;
    }

    .lobby-option h3 {
        font-size: 1rem;
    }

    .lobby-btn {
        padding: 10px 16px;
        font-size: 0.85rem;
    }

    .join-form {
        flex-direction: column;
        gap: 8px;
    }

    .join-form input {
        width: 100%;
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .join-form .join-btn {
        width: 100%;
        padding: 10px;
    }

    .room-id-display {
        padding: 10px;
    }

    .room-id-display .room-id {
        font-size: 1.2rem;
        letter-spacing: 3px;
    }

    .waiting-status,
    .searching-status {
        font-size: 0.8rem;
    }
}

.cell:hover {
    background: var(--cell-hover);
}

.cell.selected {
    background: rgba(100, 150, 255, 0.3);
    box-shadow: inset 0 0 0 3px #6496ff;
}

.cell.valid-move::after,
.cell.valid-drop::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

.cell.valid-move::after {
    background: var(--highlight-move);
}

.cell.valid-drop::after {
    background: rgba(255, 100, 100, 0.4);
}

/* Piece */
.piece {
    width: 55px;
    height: 55px;
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
    pointer-events: none;
}

/* Winner Overlay */
.winner-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
}

.winner-overlay.hidden {
    display: none;
}

.winner-text {
    font-size: 2rem;
    font-weight: 900;
    color: #fff;
    text-shadow:
        0 0 10px rgba(0, 0, 0, 0.8),
        0 0 20px rgba(0, 0, 0, 0.6),
        2px 2px 4px rgba(0, 0, 0, 0.9);
    animation: pulse 1s ease infinite;
}

.reset-btn {
    background: #333;
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.reset-btn:hover {
    transform: scale(1.05);
}

.reset-container {
    display: flex;
    justify-content: center;
    margin-top: 50px;
}

/* Footer */
footer {
    margin-top: 30px;
    color: #555;
    font-size: 0.8rem;
}

/* Utilities */
.hidden {
    display: none;
}

/* Animations */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

@keyframes bounce {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(-10px);
    }
}

/* ============================
   Start Screen
   ============================ */

.start-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    gap: 30px;
}

.start-screen.hidden {
    display: none;
}

.start-logo {
    width: 80vw;
    max-width: 350px;
    margin-bottom: 20px;
}

.mode-selection,
.difficulty-selection {
    text-align: center;
}

.mode-selection h2,
.difficulty-selection h2 {
    color: #888;
    font-size: 0.9rem;
    letter-spacing: 3px;
    margin-bottom: 15px;
}

.mode-buttons {
    display: flex;
    gap: 15px;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: var(--board-bg);
    border: 2px solid #333;
    border-radius: 12px;
    padding: 20px 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-primary);
    min-width: 130px;
    max-width: 130px;
}

.mode-btn:hover {
    border-color: #555;
    background: var(--cell-bg);
}

.mode-btn.selected {
    border-color: var(--accent-gold);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.mode-icon {
    width: 50px;
    height: 50px;
    object-fit: contain;
}

.mode-label {
    font-size: 0.6rem;
    font-weight: bold;
    letter-spacing: 1px;
}

.difficulty-buttons {
    display: flex;
    gap: 10px;
}

.diff-btn {
    background: var(--board-bg);
    border: 2px solid #333;
    border-radius: 8px;
    padding: 12px 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: bold;
    letter-spacing: 1px;
}

.diff-btn:hover {
    border-color: #555;
    background: var(--cell-bg);
}

.diff-btn.selected {
    border-color: var(--accent-gold);
    background: rgba(255, 215, 0, 0.1);
}

.diff-btn[data-diff="easy"].selected {
    border-color: #4caf50;
    background: rgba(76, 175, 80, 0.1);
}

.diff-btn[data-diff="hard"].selected {
    border-color: var(--accent-red);
    background: rgba(255, 68, 68, 0.1);
}

.start-btn {
    background: #eee;
    color: #000;
    border: none;
    padding: 18px 60px;
    font-size: 1.2rem;
    font-weight: bold;
    letter-spacing: 2px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 20px;
}

.start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
}

/* Game Screen */
.game-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.game-screen.hidden {
    display: none;
}

/* AI/Player Labels */
.ai-label,
.player-label {
    font-size: 0.7rem;
    color: var(--accent-gold);
}

/* Menu Button */
.reset-container {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 50px;
}

.menu-btn {
    background: #222;
}

/* ============================
   棋譜表示エリア
   ============================ */

.notation-container {
    margin-top: 30px;
    padding: 15px 20px;
    background: var(--board-bg);
    border-radius: 12px;
    border: 2px solid #333;
    max-width: 500px;
    width: 90%;
    text-align: center;
}

.notation-container h3 {
    color: #888;
    font-size: 0.85rem;
    letter-spacing: 2px;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.notation-display {
    background: #1a1a1a;
    border-radius: 8px;
    padding: 12px 15px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.6;
    max-height: 120px;
    overflow-y: auto;
    text-align: left;
    word-wrap: break-word;
    margin-bottom: 12px;
}

.download-btn {
    background: #333;
    color: white;
    border: none;
    padding: 10px 25px;
    font-size: 0.9rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.download-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(74, 144, 217, 0.4);
}

/* ============================
   Replay Section (Start Screen)
   ============================ */

.replay-section {
    margin-top: 30px;
    text-align: center;
}

.replay-section h2 {
    color: #888;
    font-size: 0.9rem;
    letter-spacing: 3px;
    margin-bottom: 15px;
}

.upload-btn {
    display: inline-block;
    background: var(--board-bg);
    border: 2px solid #333;
    border-radius: 8px;
    padding: 12px 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: bold;
}

.upload-btn:hover {
    border-color: #555;
    background: var(--cell-bg);
}

/* ============================
   Replay Screen
   ============================ */

.replay-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.replay-screen.hidden {
    display: none;
}

.replay-info {
    margin-bottom: 20px;
    text-align: center;
}

.replay-meta {
    color: #888;
    font-size: 0.85rem;
    line-height: 1.6;
}

.replay-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 600px;
}

@media (min-width: 768px) {
    .replay-container {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        max-width: 900px;
    }
}

.replay-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
}

.control-btn {
    background: var(--board-bg);
    border: 2px solid #333;
    border-radius: 8px;
    padding: 12px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-primary);
    font-size: 1.2rem;
}

.control-btn:hover {
    border-color: var(--accent-gold);
    background: var(--cell-bg);
}

.move-counter {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: bold;
    min-width: 80px;
    text-align: center;
}

.replay-notation {
    margin-top: 20px;
    width: 90%;
    max-width: 500px;
}

.replay-notation .notation-display {
    max-height: 80px;
}

.current-move {
    background: var(--accent-gold);
    color: #000;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: bold;
}

/* ============================
   Online Section (Start Screen)
   ============================ */

.online-section {
    margin-top: 30px;
    text-align: center;
}

.online-section h2 {
    color: #888;
    font-size: 0.9rem;
    letter-spacing: 3px;
    margin-bottom: 15px;
}

.online-buttons {
    display: flex;
    justify-content: center;
}

.online-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: var(--board-bg);
    border: 2px solid #4a90d9;
    border-radius: 12px;
    padding: 20px 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-primary);
    min-width: 130px;
}

.online-btn:hover {
    border-color: #6ab0ff;
    background: var(--cell-bg);
    box-shadow: 0 0 20px rgba(74, 144, 217, 0.3);
}

/* ============================
   Online Lobby Screen
   ============================ */

.online-lobby {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-height: 100vh;
    padding: 20px;
}

.online-lobby.hidden {
    display: none;
}

.lobby-container {
    background: var(--board-bg);
    border-radius: 16px;
    padding: 30px;
    max-width: 500px;
    width: 100%;
    text-align: center;
}

.lobby-container h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
    letter-spacing: 3px;
    margin-bottom: 20px;
}

.connection-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 25px;
    color: #888;
    font-size: 0.85rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #666;
}

.status-dot.online {
    background: #4caf50;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.status-dot.offline {
    background: #666;
}

.status-dot.connecting {
    background: #ffc107;
    animation: pulse 1s infinite;
}

.username-section {
    margin-bottom: 25px;
    text-align: left;
}

.username-section label {
    display: block;
    color: #888;
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.username-section input {
    width: 100%;
    background: #1a1a1a;
    border: 2px solid #333;
    border-radius: 8px;
    padding: 12px 15px;
    color: var(--text-primary);
    font-size: 1rem;
    text-align: center;
}

.username-section input:focus {
    outline: none;
    border-color: var(--accent-gold);
}

.lobby-options {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.lobby-option {
    padding: 20px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
}

.lobby-option h3 {
    color: #888;
    font-size: 0.85rem;
    letter-spacing: 2px;
    margin-bottom: 15px;
    text-transform: uppercase;
}

.lobby-btn {
    background: var(--cell-bg);
    border: 2px solid #333;
    border-radius: 8px;
    padding: 12px 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: bold;
    width: 100%;
}

.lobby-btn:hover {
    border-color: var(--accent-gold);
    background: rgba(255, 215, 0, 0.1);
}

.create-btn:hover {
    border-color: #4caf50;
    background: rgba(76, 175, 80, 0.1);
}

.join-btn:hover {
    border-color: #4a90d9;
    background: rgba(74, 144, 217, 0.1);
}

.random-btn:hover {
    border-color: #ff9800;
    background: rgba(255, 152, 0, 0.1);
}

.lobby-divider {
    color: #555;
    font-size: 0.85rem;
    position: relative;
}

.lobby-divider::before,
.lobby-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: #333;
}

.lobby-divider::before {
    left: 0;
}

.lobby-divider::after {
    right: 0;
}

.room-id-display {
    margin-top: 15px;
    padding: 15px;
    background: #1a1a1a;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.room-id-display code {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent-gold);
    letter-spacing: 3px;
}

.copy-btn {
    background: #333;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.8rem;
}

.copy-btn:hover {
    background: #444;
}

.join-form {
    display: flex;
    gap: 10px;
}

.join-form input {
    flex: 1;
    background: #1a1a1a;
    border: 2px solid #333;
    border-radius: 8px;
    padding: 12px 15px;
    color: var(--text-primary);
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-align: center;
}

.join-form input:focus {
    outline: none;
    border-color: #4a90d9;
}

.join-form .join-btn {
    width: auto;
    padding: 12px 20px;
}

.waiting-status,
.searching-status {
    margin-top: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #888;
    font-size: 0.85rem;
}

.waiting-status.hidden,
.searching-status.hidden {
    display: none;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #333;
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.error-message {
    margin-top: 15px;
    padding: 10px 15px;
    background: rgba(255, 68, 68, 0.1);
    border: 1px solid var(--accent-red);
    border-radius: 8px;
    color: var(--accent-red);
    font-size: 0.85rem;
}

/* ============================
   Online Game Screen
   ============================ */

.online-game-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.online-game-screen.hidden {
    display: none;
}

.online-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
    max-width: 500px;
    margin-bottom: 15px;
    padding: 10px 20px;
    background: var(--board-bg);
    border-radius: 8px;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-label {
    color: #888;
    font-size: 0.8rem;
}

#online-room-id {
    font-size: 1rem;
    font-weight: bold;
    color: var(--accent-gold);
    letter-spacing: 2px;
}

.copy-btn-small {
    background: #333;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.7rem;
}

.copy-btn-small:hover {
    background: #444;
}

.you-label {
    color: #888;
    font-size: 0.85rem;
}

#your-color {
    font-weight: bold;
    font-size: 1rem;
}

.connection-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: #888;
}

.opponent-label,
.you-indicator {
    font-size: 0.7rem;
    color: var(--accent-gold);
}

.turn-indicator-overlay {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 5px 15px;
    background: var(--accent-gold);
    color: #000;
    font-size: 0.75rem;
    font-weight: bold;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.turn-indicator-overlay.visible {
    opacity: 1;
}

.turn-indicator-overlay.waiting {
    background: #666;
    color: #fff;
}