:root {
    --bg-body: #2c3e50;
    --console-color: #e0e0d0; /* 빛바랜 플라스틱 */
    --console-shadow: #b0b0a0;
    --screen-bg: #9ea792; /* 다마고치 배경색 */
    --screen-shadow: inset 2px 2px 5px rgba(0,0,0,0.2);
    --pixel-on: #2d3329; /* 액정 켜진 색 */
    --pixel-off: #8b968d; /* 액정 꺼진 색 */
    --btn-color: #d63031;
    --btn-shadow: #b71c1c;
}

* { box-sizing: border-box; touch-action: manipulation; }

body {
    background-color: var(--bg-body);
    display: flex;
    justify-content: center;
    align-items: flex-start; /* 모바일 스크롤 고려하여 상단 정렬 */
    min-height: 100vh;
    margin: 0;
    padding: 20px 0;
    font-family: 'Press Start 2P', cursive;
}

.main-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 400px;
}

/* 게임기 본체 */
.game-console {
    background-color: var(--console-color);
    padding: 20px;
    border-radius: 15px 15px 30px 30px;
    box-shadow: 
        -5px -5px 10px rgba(255,255,255,0.2),
        5px 5px 15px rgba(0,0,0,0.4),
        inset 2px 2px 5px rgba(255,255,255,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 360px;
    max-width: 95%; /* 모바일 대응 */
    margin-bottom: 20px;
}

/* 화면 영역 */
.screen-container {
    background-color: #555;
    padding: 15px 20px;
    border-radius: 10px 10px 30px 10px;
    width: 100%;
    margin-bottom: 20px;
}

.screen-glass {
    background-color: var(--screen-bg);
    border: 2px solid #777;
    box-shadow: var(--screen-shadow);
    padding: 10px;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    position: relative;
}

canvas {
    display: block;
    image-rendering: pixelated; /* 픽셀 깨짐 방지 */
}

#tetris {
    border: 2px solid rgba(0,0,0,0.1);
}

/* 우측 정보 패널 */
.info-panel {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    width: 90px;
    margin-left: 10px;
    color: var(--pixel-on);
    text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
}

.info-box {
    text-align: center;
    margin-bottom: 10px;
}

.label {
    font-size: 8px;
    margin-bottom: 5px;
    opacity: 0.8;
}

.value {
    font-size: 10px;
    letter-spacing: 1px;
}

/* Next Canvas - CSS 사이즈 조정하지 않고 HTML width/height 사용 */
#next-piece {
    /* HTML width=80에 맞춰서 보여주되, 화면이 작으면 줄어들 수 있음 */
    max-width: 100%; 
    height: auto;
    margin-top: 5px;
}

/* 모바일 컨트롤러 */
.controls {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 10px 10px 20px 10px;
}

/* 십자키 */
.d-pad {
    position: relative;
    width: 100px;
    height: 100px;
}
.d-btn {
    position: absolute;
    background: #333;
    border: none;
    cursor: pointer;
    box-shadow: 2px 2px 0 #111, inset 1px 1px 2px rgba(255,255,255,0.2);
    -webkit-tap-highlight-color: transparent;
}
.d-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 #111; }

.d-up { top: 0; left: 35px; width: 30px; height: 35px; border-radius: 5px 5px 0 0; }
.d-down { bottom: 0; left: 35px; width: 30px; height: 35px; border-radius: 0 0 5px 5px; }
.d-left { top: 35px; left: 0; width: 35px; height: 30px; border-radius: 5px 0 0 5px; }
.d-right { top: 35px; right: 0; width: 35px; height: 30px; border-radius: 0 5px 5px 0; }
.d-center { top: 35px; left: 35px; width: 30px; height: 30px; background: #333; pointer-events: none;}

/* 액션 버튼 */
.action-btns {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.big-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--btn-color);
    border: none;
    box-shadow: 2px 4px 0 var(--btn-shadow), inset -2px -2px 5px rgba(0,0,0,0.2);
    cursor: pointer;
    font-family: inherit;
    color: white;
    font-size: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
}
.big-btn:active {
    transform: translateY(2px);
    box-shadow: 1px 2px 0 var(--btn-shadow);
}

.btn-label-rotate {
    margin-top: 5px;
    font-size: 8px;
    color: #555;
    text-transform: uppercase;
    transform: rotate(-25deg);
    margin-left: 5px;
}

/* Start/Pause 등 장식 */
.decorations {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}
.pill-btn {
    width: 40px;
    height: 10px;
    background: #666;
    border-radius: 10px;
    transform: rotate(-25deg);
    border: none;
    cursor: pointer;
    box-shadow: 1px 1px 0 #333;
}
.pill-btn:active { transform: rotate(-25deg) translate(1px, 1px); box-shadow: none;}

/* Game Over Overlay */
#game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(158, 167, 146, 0.95);
    padding: 10px;
    border: 2px solid var(--pixel-on);
    text-align: center;
    display: none;
    width: 80%;
}
#game-over p { margin: 5px 0; font-size: 12px; color: var(--pixel-on); }
.blink { animation: blinker 1s linear infinite; }

@keyframes blinker { 50% { opacity: 0; } }

/* 광고 영역 */
.ad-container {
    margin: 10px 0 20px 0;
    text-align: center;
    width: 100%;
}

/* 다른 게임 링크 */
.other-games {
    width: 100%;
    text-align: center;
    margin-top: 10px;
    padding: 0 10px;
}

.games-title {
    color: #ecf0f1;
    font-size: 12px;
    margin-bottom: 15px;
    text-shadow: 2px 2px 0 #2c3e50;
    border-bottom: 2px solid #555;
    display: inline-block;
    padding-bottom: 5px;
}

.game-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.button-link {
    display: inline-block;
    padding: 8px 12px;
    background-color: var(--console-color);
    color: #333;
    text-decoration: none;
    font-size: 10px;
    border: 2px solid #555;
    box-shadow: 3px 3px 0 #222;
    transition: transform 0.1s, box-shadow 0.1s;
    border-radius: 4px;
}

.button-link:active, .button-link:hover {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 #222;
    background-color: #fff;
}

/* --- [Added] Toast Message Style --- */
#toast-message {
    visibility: hidden;
    min-width: 200px; /* 영어는 길이가 짧으므로 폭을 조금 줄였습니다 */
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 4px;
    padding: 12px;
    position: fixed;
    z-index: 1000;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    font-size: 10px;
    font-family: 'Press Start 2P', cursive; /* 게임 폰트 적용 */
    border: 2px solid #eee;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    opacity: 0;
    transition: opacity 0.5s, bottom 0.5s;
}

/* Show State */
#toast-message.show {
    visibility: visible;
    opacity: 1;
    bottom: 50px;
}