/* --- 글로벌 설정 --- */
html, body {
	height: 100%;
	width: 100%;
	margin: 0;
	padding: 0;
	font-family: 'Arial', sans-serif;
	background-color: #1a1a2e; 
	color: #fff;
	overflow: hidden;
	touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

* {
	box-sizing: border-box;
	-webkit-tap-highlight-color: transparent; 
}

/* --- 1. 전체 앱 레이아웃 --- */
.tetris-app-container {
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100%; 
	max-width: 100vw;     
    overflow: hidden;   
	position: relative; 
	transition: transform 0.05s ease-in-out;
}

/* 화면 흔들림 효과 */
.shake-effect {
  animation: screenShake 0.2s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes screenShake {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 3px); }
  50% { transform: translate(3px, -3px); }
  75% { transform: translate(-2px, 2px); }
  100% { transform: translate(0, 0); }
}

.data-display {
	font-size: 0.95em; /* 데이터 숫자 크기 약간 축소 */
	font-weight: bold;
	color: #ffd700;
    line-height: 1.2;
}

/* --- 3. 게임 영역 (Main) --- */
.game-area-container {
	flex-grow: 1; 
	display: flex;
	justify-content: center; 
	align-items: stretch; 
	overflow: hidden; 
	padding: 5px 2px; 
	min-height: 0;
	position: relative; 
}

.board-wrapper {
	height: 100%; 
	aspect-ratio: 1 / 2; 
	max-width: 100%; 
	border: 2px solid #00bcd4;
	background-color: #0d0d1a;
	box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
	border-radius: 4px;
	position: relative; 
	overflow: hidden;
}

#idOne {
	width: 100%;
	height: 100%;
	display: block;
}

/* 게임 오버레이 스타일 */
#game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65); 
    display: flex;
    justify-content: center;   
    align-items: center;       
    color: #fff;
    text-align: center;
    cursor: pointer;
    z-index: 10;
    display: none; 
}

.overlay-content {
    display: flex;
    flex-direction: column;
    justify-content: center;   
    align-items: center;       
    height: 100%;              
}

#game-overlay .start-text {
    font-size: 2.2em; 
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 0 10px #000;
}

#game-overlay .start-subtext {
    font-size: 1.1em; 
    color: #eee;
    margin-top: 10px;
}

/* 오버레이 게임오버 상태 */
.gameover-title {
    font-size: 2.2em;
    font-weight: bold;
    color: #ff4757; 
    text-shadow: 0 0 10px #000;
}
.gameover-score-label {
    font-size: 1em;
    color: #ccc;
    margin-top: 15px;
}
.gameover-score {
    font-size: 2.0em;
    color: #ffd700;
    font-weight: bold;
}

/* 오버레이 일시 정지 상태 */
.paused-title {
    font-size: 2.2em;
    font-weight: bold;
    color: #00bcd4; 
    text-shadow: 0 0 10px #000;
}

/* [롤백] 레벨업 보드 오버레이 스타일 (기존 버전) */
#level-up-overlay {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -30%);
    font-size: 2em;
    font-weight: 900;
    color: #00e676; 
    text-shadow: 0 0 15px rgba(0, 230, 118, 0.8), 2px 2px 0 #000;
    display: none;
    z-index: 8;
    pointer-events: none;
    white-space: nowrap;
    text-align: center;
    width: 100%;
}

/* [NEW] 플로팅 점수 텍스트 스타일 (메이플스토리 스타일) */
.floating-score-text {
    position: absolute;
    left: 50%; /* 가로 중앙 정렬을 위한 기준점 */
    font-family: 'Arial Black', sans-serif;
    font-weight: 900;
    font-size: 2rem;
    color: #ffd700; /* 금색 */
    /* 강력한 외곽선 효과 */
    text-shadow: 
        2px 2px 0 #000, 
       -1px -1px 0 #000,  
        1px -1px 0 #000,
       -1px 1px 0 #000,
        1px 1px 0 #000;
    z-index: 20; /* 블록(canvas)보다 위에 */
    pointer-events: none; /* 클릭 통과 */
    white-space: nowrap;
    animation: popUpAndFade 1.0s ease-out forwards;
}

/* 점수 튀어오르는 애니메이션 키프레임 */
@keyframes popUpAndFade {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    20% {
        transform: translate(-50%, -120%) scale(1.3); /* 살짝 커지며 위로 팝업 */
        opacity: 1;
    }
    50% {
        transform: translate(-50%, -150%) scale(1.0);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -300%) scale(1.0); /* 쭉 올라가며 사라짐 */
        opacity: 0;
    }
}


/* 사이드 UI 컨테이너 */
.side-ui-container {
	display: flex;
	flex-direction: column;
	justify-content: flex-start; 
	padding-left: 5px; 
	flex-shrink: 0;
	gap: 4px; /* 간격 다이어트 */
}

/* 사이드 UI 박스 (공통 스타일 + [NEW] hold) */
.next-brick-in-game, .hold-brick-in-game, .level-info-side, .side-info-box, .side-menu-button, .side-game-controls {
	text-align: center;
	padding: 4px 2px; /* 패딩 다이어트 (5px -> 4px 2px) */
	background-color: #2c2c54;
	border-radius: 4px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* [수정] 캔버스(Next/Hold) 크기 축소 (60px -> 42px) */
.next-brick-in-game canvas, .hold-brick-in-game canvas {
	width: 42px;  /* 크기 축소 */
	height: 42px; /* 크기 축소 */
	border: 1px solid #00bcd4; /* 테두리 두께 축소 */
	background-color: #1a1a2e; 
	border-radius: 3px;
    margin-top: 2px;
}

/* [수정] 캔버스 위 라벨 텍스트 축소 */
.next-brick-in-game p, .hold-brick-in-game p {
    margin-bottom: 0 !important; /* 마진 제거 */
    font-size: 0.75em !important; /* 폰트 사이즈 축소 */
    line-height: 1.2;
    color: #aaa;
}

/* [수정] 레벨, 점수, 시간 텍스트 박스 다이어트 */
.side-info-box p, .level-info-side p {
    margin: 0;
    font-size: 0.75em; /* 라벨 폰트 축소 */
    color: #aaa;
    line-height: 1.2;
}

/* 레벨 + 프로그레스 바 컨테이너 */
.level-info-side {
	display: flex;
	flex-direction: column;
	gap: 5px;
	padding: 8px 5px; 
}

.level-container { 
	position: relative; 
}

/* [개선] 사이드바 레벨업 표시 스타일 (가독성 향상) */
.level-up {
	position: absolute;
    /* 숫자 위로 겹치도록 배치 */
	top: -20px; 
	left: 50%;
	transform: translateX(-50%);
    
    /* 가독성 개선: 빨간색 배지 스타일 */
    background-color: #ff4757;
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    
	font-size: 0.85em;
	font-weight: 900;
	white-space: nowrap;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
	display: none; 
    z-index: 5;
}

/* [수정] 레벨 프로그레스 바 (디자인 개선) */
.level-info-side .progress {
	width: 90%; 
	height: 8px; /* [NEW] 구분선이 잘 보이도록 높이 확대 (4px -> 8px) */
	margin: 3px auto 0px auto; 
	background-color: #44475a;
    position: relative; /* 가상 요소를 위해 추가 */
    overflow: hidden; /* 모서리 둥글게 */
    border-radius: 4px;
}

/* [NEW] 프로그레스 바 10단계 구분선 (가상 요소 사용) */
.level-info-side .progress::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* 10% 간격으로 투명/검정 라인을 반복해서 그려 구분선 효과 생성 */
    background: repeating-linear-gradient(
        to right,
        transparent,
        transparent calc(10% - 1px),
        rgba(0, 0, 0, 0.8) calc(10% - 1px),
        rgba(0, 0, 0, 0.8) 10%
    );
    z-index: 2; /* 게이지 위에 표시 */
    pointer-events: none;
}

.level-info-side p {
	margin: 0;
	font-size: 0.8em; 
}

/* 사이드 메뉴 버튼 */
.side-menu-button {
    padding: 0; 
    background: none; 
    box-shadow: none;
}
.side-menu-button .action-btn {
    width: 100%;
    min-width: 60px; 
    padding: 6px 5px;
    font-size: 1.0em;
    background-color: #454565;
    color: #fff;
    touch-action: manipulation;
}

/* 사이드 정보 박스 */
.side-info-box {
    padding: 8px 5px; 
}
.side-info-box p {
    margin: 0 0 5px 0;
    font-size: 0.85em; 
}

/* 사이드바 하단 게임 제어 */
.side-game-controls {
    display: flex;
    flex-direction: row; 
    gap: 3px; 
    padding: 2px; 
}
.side-game-controls .action-btn {
    flex: 1; 
    min-width: 0; 
    padding: 6px 2px; 
    font-size: 0.8em; 
    touch-action: manipulation;
}

/* 콤보 애니메이션 */
#combo-display {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%) scale(1); 
	font-size: 2.5em;
	font-weight: 900;
	color: #ffcc00; 
	text-shadow: 0 0 10px rgba(255, 165, 0, 0.9), 0 0 20px rgba(255, 105, 0, 0.7);
	opacity: 0;
	pointer-events: none; 
	transition: all 0.1s ease-out; 
    z-index: 25;
}

/* --- 4. 하단 컨트롤 패드 (Footer) --- */
.control-pad-container {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    width: auto; /* 고정 너비 제거 후 내용물에 맞춤 */
    min-width: 260px;
    
    background: rgba(0,0,0,0.85);
    border-radius: 12px 12px 0 0;
    overflow: hidden;
    transition: transform 0.3s ease, background-color 0.3s ease; 
    z-index: 1000;
	padding-bottom: env(safe-area-inset-bottom); /* 아이폰 하단 바 대응 */
	
    --overlay-opacity: 0.6; 
    --btn-opacity: 1.0;
    --btn-size: 48px; /* [NEW] 버튼 크기 변수 (기본값) */
    --gap-size: 10px;  /* [NEW] 버튼 간 간격 변수 */
    
    /* 시스템 폰트 영향 최소화 */
    text-size-adjust: none;
    -webkit-text-size-adjust: none;
    
    /* [수정] 상단 경계선 추가로 구분감 부여 */
    border-top: 1px solid rgba(255,255,255,0.1);
}

.control-pad-container.closed {
    /* [수정] 완전히 화면 밖으로 숨김 */
    transform: translateX(-50%) translateY(100%); 
}
.control-pad-container.hidden {
	display: none !important;
}

.control-pad-content {
    /* [수정] 패딩 미세 조정 */
    padding: 5px 10px 5px 10px; /* 좌우 패딩 추가 */
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* [NEW] D-Pad Grid Layout for ㅗ shape */
.d-pad-grid {
    display: grid;
    grid-template-columns: repeat(3, auto); /* 3 columns */
    gap: var(--gap-size);
    justify-content: center;
    align-items: center;
    margin-bottom: 5px;
}

/* Specific Grid Placements to ensure ㅗ shape */
#ctrl-hold { 
    grid-column: 1; grid-row: 1; 
    /* [NEW] Round & Smaller Hold Button */
    width: calc(var(--btn-size) * 0.75);
    height: calc(var(--btn-size) * 0.75);
    border-radius: 50%;
    margin: auto; /* Center in cell */
    display: flex;
    justify-content: center;
    align-items: center;
}
#ctrl-up    { grid-column: 2; grid-row: 1; }
#ctrl-left  { grid-column: 1; grid-row: 2; }
#ctrl-down  { grid-column: 2; grid-row: 2; }
#ctrl-right { grid-column: 3; grid-row: 2; }


.controls-row {
    display: flex;
    justify-content: center;
    gap: var(--gap-size); /* [NEW] 변수 사용 */
    margin: 5px 0;
}

.action-btn {
	padding: 10px 20px; 
	font-size: 1em; 
	font-weight: bold;
	cursor: pointer;
	border: none;
	border-radius: 6px;
	transition: background-color 0.2s;
} 
.start-btn { background-color: #43a047; color: #fff; }
.stop-btn { background-color: #e84118; color: #fff; }

.control-pad-container .btn {
    /* [NEW] 변수 기반 크기 및 폰트 사이즈 조절 */
	width: var(--btn-size);
	height: var(--btn-size);
	font-size: calc(var(--btn-size) * 0.45) !important; 
    
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    
    touch-action: none;
    user-select: none;
}

/* 물리적 버튼 눌림 효과 */
.control-pad-container .btn:active, .control-pad-container .btn.active {
    background-color: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

#ctrl-space {
    /* [NEW] 동적 너비 계산: 버튼 3개 너비 + 갭 2개 */
	width: calc((var(--btn-size) * 3) + (var(--gap-size) * 2)); 
    height: calc(var(--btn-size) * 0.75); 
}

/* [수정] FAB 위치 고정 및 z-index 상향 */
.fab-toggle-btn {
    position: fixed;
    bottom: 10px !important; /* JS 간섭 무시하고 위치 고정 */
    right: 10px !important;
    width: 46px; /* 크기 약간 축소 */
    height: 46px;
    border-radius: 50%;
    background-color: rgba(67, 160, 71, 0.9);
    border: 2px solid rgba(255,255,255,0.3);
    color: white;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 2000; /* 컨트롤 패드(999)보다 높게 설정하여 위에 뜸 */
    transition: background-color 0.3s, transform 0.1s; /* 위치 이동 애니메이션 제거 */
}

.fab-toggle-btn:active {
    transform: scale(0.95);
}

.fab-toggle-btn.open-state {
    background-color: rgba(232, 65, 24, 0.9);
    /* transform 제거됨 */
}

/* 작은 화면 대응 - 변수가 적용되므로 여기서는 제외하거나 덮어쓰지 않도록 주의 */
/* 변수 시스템으로 전환했으므로 미디어 쿼리 내의 고정 픽셀값은 제거 또는 변수 조정만 수행 */
@media (max-height: 700px) {
    /* 변수 사용으로 인해 고정 사이즈 지정 제거, 필요시 패딩만 조정 */
    .control-pad-content {
        padding: 5px 10px;
    }
    .fab-toggle-btn {
        width: 44px;
        height: 44px;
        font-size: 20px;
        bottom: 15px;
        right: 15px;
    }
	
	.side-ui-container {
        gap: 2px;
    }
    .next-brick-in-game canvas, .hold-brick-in-game canvas {
        width: 38px;
        height: 38px;
    }
    .side-menu-button .action-btn {
        padding: 4px;
    }
}

/* 오버레이 모드 스타일 */
.control-pad-container.overlay-mode {
    background-color: rgba(52, 73, 94, var(--overlay-opacity)); 
    bottom: 10%; 
    width: 90%; 
    max-width: 380px; 
    border-radius: 10px; 
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5); 
    transform: translateX(-50%) translateY(100vh); 
}
.control-pad-container.overlay-mode.open {
    transform: translateX(-50%) translateY(0); 
    bottom: 10%; 
}

.control-pad-container.overlay-mode .control-pad-content {
    padding: 10px;
}
.control-pad-container.overlay-mode .btn {
	width: 60px; /* 오버레이 모드는 별도 고정 사이즈 유지하거나 변수로 통합 가능 */
	height: 60px;
	font-size: 24px !important; 
}

.control-pad-container.overlay-mode #ctrl-space {
    width: 100%;
    height: 100%;
    float: right; 
    clear: right;
}

/* --- 5. 슬라이드 메뉴 (Offcanvas) --- */
.offcanvas {
	background-color: #1a1a2e;
	color: #fff;
	max-width: 320px;
	z-index: 2001;
}

/* [NEW] 오프캔버스 바디 스크롤 제어 */
.offcanvas-body {
    /* 패딩 제거 (내부 요소가 패딩 처리) */
    padding: 0 !important; 
    /* Flex column으로 상/하단 분리 */
    display: flex;
    flex-direction: column;
    /* 바디 자체 스크롤 방지 */
    overflow: hidden; 
}

/* [NEW] 스크롤 가능한 설정 목록 영역 */
.settings-scroll-area {
    flex-grow: 1; /* 남은 공간 모두 차지 */
    overflow-y: auto; /* 내용 넘칠 때만 스크롤 */
    overflow-x: hidden;
}

/* [NEW] 하단 고정 영역 */
.settings-fixed-bottom {
    flex-shrink: 0; /* 크기 축소 방지 */
    background-color: #1a1a2e; /* 배경색 유지 */
    border-top: 1px solid #444; /* 상단 구분선 */
    z-index: 10;
}


.settings-toggle-btn-offcanvas {
	width: 60px; 
	height: 60px;
	font-size: 1.5em;
	border: none;
	border-radius: 12px; 
	padding: 0;
	transition: background-color 0.2s;
	background-color: #43a047; 
	color: #fff;
	flex-shrink: 0;
}
.settings-toggle-btn-offcanvas.off {
	background-color: #6c757d; 
}

.offcanvas-body .form-check-label {
    color: #fff;
    font-size: 1.0em;
    font-weight: bold;
    margin: 0;
    padding: 0;
    text-align: left;
}
.offcanvas-body .form-switch {
    padding-left: 0 !important; 
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.offcanvas-body .form-switch .form-check-input {
    cursor: pointer;
    width: 3.2em; 
    height: 1.6em;
    flex-shrink: 0;
    margin-left: 10px;
}

/* Range Input Style Override */
.form-range {
    height: 1.5rem;
    padding: 0;
    width: 100%;
    background-color: transparent;
    -webkit-appearance: none;
    appearance: none;
}
.form-range::-webkit-slider-thumb {
    background-color: #00bcd4;
}
.form-range::-webkit-slider-runnable-track {
    background-color: #444;
}

.settings-desc {
    display: block; 
    color: #aaa; 
    font-size: 0.8em; 
    margin-top: 2px;
    font-weight: normal;
}


/* 게임 오버 모달 */
.modal-content {
	background-color: #2c2c54;
	color: #fff;
	border: 2px solid #ff4757;
	border-radius: 12px;
}
.modal-header {
	border-bottom: 1px solid #444;
	padding: 1rem 1rem 0.5rem 1rem;
	position: relative;
}
.modal-title-center {
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	font-weight: bold;
	color: #ffd700;
}
.modal-header .btn-close {
	filter: invert(1);
	margin: -0.5rem -0.5rem -0.5rem auto; 
}

#final-score-display {
	font-size: 2em;
	color: #ffd700;
	font-weight: bold;
	margin-top: 10px;
}

#best-score-message {
    font-size: 1.1em;
    font-weight: bold;
}


/* 6. 오버레이 키보드 스타일 (Grid 구조 적용) */
.overlay-keyboard-container {
    position: absolute;
    bottom: 10px;
    left: 50%; 
    right: auto;
    transform: translateX(-50%); 
    
    display: flex;
    justify-content: center; 
    align-items: flex-end;
    
    z-index: 5; 
    opacity: 0.3; 
    pointer-events: none; 
    transition: opacity 0.3s;
}

.overlay-keyboard-container.hidden {
    display: none;
}

/* [NEW] 오버레이 Grid 시스템 (하단 키보드와 동일한 'ㅗ' 구조) */
.overlay-d-pad-grid {
    display: grid;
    grid-template-columns: repeat(3, auto);
    gap: 8px; /* 오버레이에 맞는 간격 */
    justify-content: center;
    align-items: center;
    pointer-events: auto; /* Grid 영역만 클릭 가능 */
}

/* 오버레이 버튼 Grid 배치 */
#overlay-hold { 
    grid-column: 1; grid-row: 1; 
    justify-self: center; /* 셀 가운데 정렬 */
}
#overlay-up    { grid-column: 2; grid-row: 1; }
#overlay-left  { grid-column: 1; grid-row: 2; }
#overlay-down  { grid-column: 2; grid-row: 2; }
#overlay-right { grid-column: 3; grid-row: 2; }

.overlay-btn {
    background: rgba(80, 80, 100, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: #fff;
    border-radius: 12px;
    font-size: 1.6em;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 0;
    
    touch-action: none; 
    -webkit-user-select: none; 
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.1s, transform 0.1s;
}

.overlay-btn:active, .overlay-btn.active {
    background: rgba(120, 120, 150, 0.8);
    transform: scale(0.95); 
    border-color: #ffd700;
}

.keyboard-actions {
    display: flex;
    flex-direction: column; 
    gap: 8px;
    align-items: center; 
}

.overlay-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    pointer-events: auto;
}

.overlay-btn-small {
    width: 60px;
    height: 60px;
}

/* 오버레이 홀드 버튼용 원형 스타일 */
.overlay-btn-round {
    width: 50px; /* 하단 키보드 비율에 맞춰 약간 작게 조정 */
    height: 50px;
    border-radius: 50%;
}

.overlay-btn-space {
    width: 196px; 
    height: 60px;
    font-size: 1.2em;
}

.overlay-btn-space span {
    display: block;
    width: 60%;
    height: 5px;
    background: #fff;
    border-radius: 2px;
}