/* GitHub-style UI/UX */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f6f8fa;
    --color-bg-tertiary: #0d1117;
    --color-border: #d0d7de;
    --color-text-primary: #24292f;
    --color-text-secondary: #656d76;
    --color-accent: #0969da;
    --color-accent-hover: #0860ca;
    --border-radius: 6px;
    --spacing-unit: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    line-height: 1.5;
    padding: var(--spacing-unit);
    margin: 0;
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.header {
    text-align: center;
    margin-bottom: calc(var(--spacing-unit) * 2);
}

.title {
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: var(--spacing-unit);
}

.game-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-unit);
    max-width: 100vw;
    overflow-x: hidden;
}

.game-panel {
    display: flex;
    justify-content: center;
    gap: var(--spacing-unit);
    flex-wrap: wrap;
    align-items: flex-start; /* 上端を揃える */
}

.left-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-unit);
    align-items: center;
    justify-content: space-between; /* Holdは上、操作説明は下に配置 */
    height: 800px; /* ゲームボードの高さ（800px）に合わせる */
}

.panel-section {
    background-color: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-unit);
}

.hold-section,
.next-section {
    min-width: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#next-canvas,
#hold-canvas {
    background-color: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
}

.panel-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-unit);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.preview-area {
    background-color: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) / 2);
    display: flex;
    justify-content: center;
    align-items: center;
}

.board-section {
    padding: var(--spacing-unit);
}

.controls-section {
    min-width: 200px;
    padding: var(--spacing-unit);
}

.controls-list {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) / 2);
}

.control-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-unit);
    padding: calc(var(--spacing-unit) / 2);
    background-color: var(--color-bg-secondary);
    border-radius: var(--border-radius);
}

.control-key {
    background-color: var(--color-bg-tertiary);
    color: #ffffff;
    padding: calc(var(--spacing-unit) / 4) calc(var(--spacing-unit) / 2);
    border-radius: 4px;
    font-family: "SF Mono", "Monaco", "Inconsolata", "Roboto Mono", monospace;
    font-size: 0.875rem;
    font-weight: 600;
    min-width: 60px;
    text-align: center;
    white-space: nowrap;
}

.control-key span {
    display: inline-block;
    font-size: 1em;
}

.control-desc {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

#game-canvas {
    background-color: #2d3136; /* 明るい背景色を直接指定 */
    border: 2px solid #8b949e; /* より明るい境界線 */
    border-radius: var(--border-radius);
    display: block;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

#hold-canvas,
#next-canvas {
    background-color: var(--color-bg-tertiary);
    display: block;
}

.info-panel {
    background-color: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-unit);
    display: flex;
    justify-content: center;
    gap: calc(var(--spacing-unit) * 2);
    flex-wrap: wrap;
}

.info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: calc(var(--spacing-unit) / 4);
}

.info-label {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    font-weight: 500;
}

.info-value {
    font-family: "SF Mono", "Monaco", "Inconsolata", "Roboto Mono", monospace;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.controls-panel {
    background-color: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-unit);
    text-align: center;
}

.controls-info {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    line-height: 1.8;
}

.controls-info strong {
    color: var(--color-text-primary);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

/* タイトル画面 */
.title-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0d1117 0%, #1c2128 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.5s ease-in;
}

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

.title-content {
    text-align: center;
    color: #ffffff;
}

.title-main {
    font-size: 5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    text-shadow: 0 0 20px rgba(9, 105, 218, 0.5);
    animation: pulse 2s ease-in-out infinite;
}

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

.title-subtitle {
    font-size: 1.5rem;
    color: #8b949e;
    margin-bottom: 3rem;
}

.start-btn {
    background-color: var(--color-accent);
    color: #ffffff;
    border: none;
    border-radius: var(--border-radius);
    padding: 1rem 3rem;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(9, 105, 218, 0.3);
    margin-bottom: 2rem;
}

.start-btn:hover {
    background-color: var(--color-accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(9, 105, 218, 0.4);
}

.start-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(9, 105, 218, 0.3);
}

.title-info {
    color: #656d76;
    font-size: 0.875rem;
}

.modal-content {
    background-color: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 2);
    text-align: center;
    min-width: 300px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: var(--spacing-unit);
    color: var(--color-text-primary);
}

.modal-content p {
    margin-bottom: calc(var(--spacing-unit) * 1.5);
    color: var(--color-text-secondary);
}

.btn {
    background-color: var(--color-accent);
    color: white;
    border: 1px solid var(--color-accent);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) / 2) var(--spacing-unit);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.btn:hover {
    background-color: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
}

.btn:active {
    transform: translateY(1px);
}

/* タイトル画面 */
.title-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0d1117 0%, #1c2128 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.5s ease-in;
}

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

.title-content {
    text-align: center;
    color: #ffffff;
}

.title-main {
    font-size: 5rem;
    font-weight: 700;
    margin-bottom: 2rem;
    text-shadow: 0 0 20px rgba(9, 105, 218, 0.5);
    animation: pulse 2s ease-in-out infinite;
}

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

.title-subtitle {
    font-size: 1.5rem;
    color: #8b949e;
    animation: blink 1.5s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* ゲーム画面 */
.game-screen {
    width: 100%;
    min-height: 100vh;
}

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

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

/* ゲームオーバーオーバーレイ */
#game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    pointer-events: none;
}

.game-over-content {
    text-align: center;
}

.game-over-text {
    font-size: 80px;
    font-weight: bold;
    background: linear-gradient(135deg, #f44336 0%, #ff9800 50%, #f44336 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin-bottom: 20px;
}

.final-score,
.final-level,
.final-lines {
    font-size: 30px;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin: 10px 0;
}

.retry-message {
    font-size: 40px;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin-top: 20px;
}

@keyframes tetrisPulse {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.8;
    }
}

@keyframes lineClearPulse {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

@keyframes comboPulse {
    0% {
        transform: translate(-50%, -50%) scale(0.7);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.15);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

@keyframes levelUpPulse {
    0% {
        transform: translate(-50%, -50%) scale(0.3);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.3);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.7;
    }
}

@keyframes levelUpFlash {
    0% {
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

@keyframes rotationFeedback {
    0% {
        transform: translate(-50%, -50%) scale(0.5) rotate(0deg);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2) rotate(180deg);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1) rotate(360deg);
        opacity: 0;
    }
}

@keyframes countdownPulse {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0.5;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

@keyframes gameStartFlash {
    0% {
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

@keyframes gameOverPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.05);
        opacity: 0.9;
    }
}

@keyframes particleFade {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--end-x, 0), var(--end-y, 0)) scale(0);
        opacity: 0;
    }
}

.score-value {
    transition: transform 0.3s ease, color 0.3s ease;
}

@media (max-width: 768px) {
    .game-panel {
        flex-direction: column;
        align-items: center;
    }
    
    .title {
        font-size: 2rem;
    }
    
    .title-main {
        font-size: 3rem;
    }
    
    #game-canvas {
        width: 100%;
        max-width: 400px;
        height: auto;
    }
}

/* タイトル画面のCanvas */
#title-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.title-screen {
    overflow: hidden;
}

.title-content {
    position: relative;
    z-index: 2;
}

