/* ==========================================================================
   Project H (합글) - Korean Traditional Aesthetic Design System
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Gowun+Batang:wght@400;700&family=Noto+Serif+KR:wght@400;600;700;900&display=swap');

:root {
    --primary-navy: #0d1b2a;
    --royal-navy: #1b263b;
    --accent-blue: #415a77;
    --gold-bright: #f4d06f;
    --gold-dark: #b8860b;
    --gold-seal: #d4af37;
    --traditional-red: #c0392b;
    --tile-bg: #ffffff;
    --tile-border: #4a4e69;
    --tile-text: #1a1a24;
    --stone-wall: #495057;
    
    --shadow-main: 0 10px 30px rgba(0, 0, 0, 0.5);
    --shadow-tile: 0 4px 10px rgba(0, 0, 0, 0.25);
    --font-traditional: 'Gowun Batang', 'Noto Serif KR', serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: #070d17;
    font-family: var(--font-traditional);
    color: #ffffff;
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#app-container {
    position: relative;
    width: 100%;
    max-width: 480px;
    height: 100vh;
    max-height: 920px;
    background-color: var(--primary-navy);
    background-image: radial-gradient(circle at 50% 30%, #1c2b42 0%, #0d1b2a 100%);
    box-shadow: var(--shadow-main);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Screen Management
   ========================================================================== */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease-in-out, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transform: scale(0.98);
    background-size: cover;
    background-position: center;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    transform: scale(1);
    z-index: 10;
}

/* ==========================================================================
   1. Opening Screen
   ========================================================================== */
#screen-opening {
    background: #080808;
    justify-content: center;
    align-items: center;
    text-align: center;
    cursor: pointer;
}

.opening-text-wrap {
    padding: 30px;
}

.hunmin-title {
    font-size: 28px;
    line-height: 1.8;
    color: #e6c887;
    letter-spacing: 4px;
    font-weight: 700;
    animation: fadePulse 2.8s ease-in-out forwards;
}

.hunmin-sub {
    margin-top: 20px;
    font-size: 15px;
    color: #a09787;
    letter-spacing: 2px;
    opacity: 0.8;
}

@keyframes fadePulse {
    0% { opacity: 0; transform: translateY(15px); }
    40% { opacity: 1; transform: translateY(0); }
    80% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0.9; }
}

/* ==========================================================================
   2. Main Lobby Screen
   ========================================================================== */
#screen-lobby {
    background-image: url('../resource/최존본 메인 결정 복사.png'), 
                      radial-gradient(circle at 50% 20%, #203554 0%, #0d1b2a 100%);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center top;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 60px;
}

.top-right-tools {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 20;
}

.btn-gear {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 22px;
    color: #f4d06f;
    transition: transform 0.2s, background-color 0.2s;
}

.btn-gear:hover {
    transform: rotate(30deg) scale(1.05);
    background: rgba(255, 255, 255, 0.25);
}

.lobby-menu-group {
    width: 80%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 15;
}

.btn-primary-wooden {
    position: relative;
    height: 56px;
    background: linear-gradient(180deg, #6c4f3d 0%, #4a3325 100%);
    border: 2px solid #b8860b;
    border-radius: 12px;
    color: #fceabb;
    font-size: 20px;
    font-weight: 700;
    font-family: var(--font-traditional);
    letter-spacing: 2px;
    cursor: pointer;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.5), inset 0 1px 1px rgba(255, 255, 255, 0.3);
    transition: transform 0.1s, box-shadow 0.1s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-primary-wooden:active {
    transform: translateY(3px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   3. Stage Select Screen
   ========================================================================== */
#screen-stage-select {
    background-image: radial-gradient(circle at 50% 30%, #f4ede2 0%, #e2d3be 100%);
    color: #2b2014;
    padding: 24px 20px;
}

.stage-select-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.stage-select-header h2 {
    font-size: 24px;
    font-weight: 900;
    letter-spacing: 3px;
    color: #3d2b1f;
    border-bottom: 2px solid #3d2b1f;
    padding-bottom: 4px;
}

.stage-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 10px 4px;
    overflow-y: auto;
    flex: 1;
}

.stage-card {
    aspect-ratio: 1 / 1;
    background: #fffdf9;
    border: 2px solid #5a4635;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 10px rgba(90, 70, 53, 0.2);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background-color 0.15s;
    padding: 8px;
}

.stage-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 14px rgba(90, 70, 53, 0.35);
    background: #fffaee;
}

.stage-card:active {
    transform: translateY(1px);
}

.stage-number {
    font-size: 26px;
    font-weight: 900;
    color: #3d2b1f;
    line-height: 1;
}

.stage-card-title {
    margin-top: 6px;
    font-size: 13px;
    color: #7b624c;
    font-weight: 700;
}

/* ==========================================================================
   4. Ingame Screen
   ========================================================================== */
#screen-ingame {
    background-image: url('../resource/인게임 뒷배경 1111.png'), 
                      radial-gradient(circle at 50% 50%, #152238 0%, #0d1b2a 100%);
    background-repeat: repeat;
    background-size: 260px auto;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 14px 16px 20px 16px;
}

/* Header */
.ingame-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    height: 60px;
    z-index: 15;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 10px;
    color: #f4d06f;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(6px);
    transition: transform 0.1s, background-color 0.1s;
}

.icon-btn:active {
    transform: scale(0.92);
}

.icon-btn:disabled {
    opacity: 0.35;
    pointer-events: none;
}

/* Target Word Container */
.target-word-wrap {
    display: flex;
    gap: 8px;
    background: rgba(0, 0, 0, 0.35);
    padding: 6px 14px;
    border-radius: 14px;
    border: 1px solid rgba(244, 208, 111, 0.4);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.target-char-box {
    width: 38px;
    height: 38px;
    background: #ffffff;
    border: 2px solid #333333;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    font-weight: 900;
    color: #1a1a24;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.target-char-box.completed {
    background: #f4d06f;
    color: #0d1b2a;
    border-color: #ffffff;
    box-shadow: 0 0 14px rgba(244, 208, 111, 0.8);
    transform: scale(1.08);
}

/* Stage Subtitle & Score */
.ingame-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0 6px;
    margin-top: 4px;
}

.stage-title-text {
    font-size: 15px;
    color: #e0a96d;
    font-weight: 700;
    letter-spacing: 1px;
}

.score-badge {
    font-size: 14px;
    color: #cdd6f4;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 10px;
    border-radius: 12px;
}

/* Action Prompt Banner */
.action-prompt-banner {
    min-height: 22px;
    text-align: center;
    font-size: 13px;
    color: #ffde7d;
    font-weight: 700;
    padding: 2px 8px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.action-prompt-banner.active {
    opacity: 1;
}

/* Puzzle Board */
.board-outer-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-height: 440px;
    background: #1b263b;
    background-image: url('../resource/퍼즐뒷배경.png');
    background-size: cover;
    border: 8px solid #5a4635;
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), inset 0 0 20px rgba(0, 0, 0, 0.7);
    padding: 6px;
    margin: 4px auto;
    overflow: hidden;
}

#game-board {
    width: 100%;
    height: 100%;
    display: grid;
    gap: 4px;
    position: relative;
}

/* Grid Cells */
.grid-cell {
    position: relative;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* Movable / Static Tile inside Cell */
.tile-block {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    will-change: transform;
    pointer-events: none;
    z-index: 10;
}

.tile-block.cell-wall {
    background-color: #555555;
    background-image: url('../resource/돌버전2.png');
    background-size: cover;
    background-position: center;
    border-radius: 6px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6), 0 2px 4px rgba(0, 0, 0, 0.4);
}

.tile-block.cell-jangseung {
    background-color: #6d4c41;
    background-image: url('../resource/장승 세우기.png');
    background-size: 80% auto;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 6px;
    box-shadow: 0 0 10px rgba(184, 134, 11, 0.6);
}

.tile-block.cell-char {
    background-color: #ffffff;
    background-image: url('../resource/자음 모음 들어갈 공간 흰배경 없는 버전.png');
    background-size: cover;
    border-radius: 10px;
    box-shadow: var(--shadow-tile);
    pointer-events: all;
    cursor: pointer;
}

.tile-block.cell-char:hover {
    transform: scale(1.03);
}

.tile-block.cell-char.selected-move {
    outline: 3px solid #f4d06f;
    box-shadow: 0 0 15px #f4d06f;
    animation: pulseMove 0.8s infinite alternate;
}

@keyframes pulseMove {
    from { transform: scale(1.02); }
    to { transform: scale(1.09); }
}

.tile-block.cell-char.frozen {
    background-color: #d0ebff;
    border: 2px solid #74c0fc;
    box-shadow: 0 0 12px rgba(116, 192, 252, 0.8);
}

.char-text {
    font-size: clamp(22px, 5vw, 32px);
    font-weight: 900;
    color: var(--tile-text);
    line-height: 1;
}

.ice-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background-image: url('../resource/얼음아이템.png');
    background-size: contain;
    background-repeat: no-repeat;
}

/* Animations */
.tile-pop {
    animation: tilePopAnim 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes tilePopAnim {
    0% { transform: scale(0.7); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.tile-disappear {
    animation: tileDisappearAnim 0.25s ease-out forwards;
}

@keyframes tileDisappearAnim {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.8; box-shadow: 0 0 20px #f4d06f; }
    100% { transform: scale(0); opacity: 0; }
}

/* Board blocked bump shake */
.board-bump-shake {
    animation: bumpShake 0.15s ease-in-out;
}

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

/* Bottom Items Bar */
.ingame-bottom-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 22px;
    padding: 10px 0;
    z-index: 15;
}

.item-btn {
    position: relative;
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.12);
    border: 2px solid rgba(244, 208, 111, 0.5);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s, border-color 0.2s, background-color 0.2s;
}

.item-btn:hover {
    transform: translateY(-2px);
    border-color: #f4d06f;
}

.item-btn:active {
    transform: translateY(2px);
}

.item-btn.active {
    border-color: #ff6b6b;
    box-shadow: 0 0 15px rgba(255, 107, 107, 0.8);
    background: rgba(255, 107, 107, 0.2);
}

.item-btn.used {
    filter: grayscale(1);
    opacity: 0.35;
    pointer-events: none;
    border-color: #888888;
}

.item-icon {
    width: 34px;
    height: 34px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

#item-lock .item-icon {
    background-image: url('../resource/장승아이콘.png');
}

#item-freeze .item-icon {
    background-image: url('../resource/얼음아이템.png');
}

#item-move .item-icon {
    background-image: url('../resource/잡기 아이콘2 명암 진한버전.png');
}

.item-label {
    font-size: 10px;
    color: #e0d0b0;
    margin-top: 2px;
    font-weight: 700;
}

/* ==========================================================================
   5. Modals and Popups
   ========================================================================== */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Clear Success Card */
.clear-popup-card {
    position: relative;
    width: 86%;
    max-width: 360px;
    background: #fffbf0;
    border: 3px solid #8c6d48;
    border-radius: 24px;
    padding: 30px 20px 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
    color: #3d2b1f;
    animation: popupBounce 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popupBounce {
    0% { transform: scale(0.6); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.medal-emblem-wrap {
    width: 110px;
    height: 110px;
    background: radial-gradient(circle, #ffeaa7 0%, #d4af37 70%, #9e782f 100%);
    border: 4px solid #fff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 6px 20px rgba(212, 175, 55, 0.6);
    margin-bottom: 12px;
}

.medal-title {
    font-size: 26px;
    font-weight: 900;
    color: #4a2810;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

.clear-stars {
    font-size: 32px;
    color: #f39c12;
    margin-bottom: 10px;
    letter-spacing: 4px;
}

.clear-stats {
    font-size: 15px;
    color: #634b35;
    margin-bottom: 20px;
    font-weight: 700;
}

.clear-popup-buttons {
    display: flex;
    gap: 12px;
    width: 100%;
}

.btn-popup {
    flex: 1;
    height: 46px;
    border-radius: 12px;
    font-family: var(--font-traditional);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: transform 0.1s;
}

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

.btn-popup.secondary {
    background: #e5d7c3;
    color: #4a3728;
}

.btn-popup.primary {
    background: #b8860b;
    color: #fff;
    box-shadow: 0 4px 12px rgba(184, 134, 11, 0.4);
}

/* Settings Modal */
.settings-card {
    width: 80%;
    max-width: 320px;
    background: #1b263b;
    border: 2px solid rgba(244, 208, 111, 0.4);
    border-radius: 20px;
    padding: 24px 20px;
    color: #fff;
    text-align: center;
}

.settings-card h3 {
    font-size: 20px;
    color: #f4d06f;
    margin-bottom: 20px;
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    padding: 0 8px;
}

.btn-toggle {
    padding: 6px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    color: #fff;
    font-family: var(--font-traditional);
    cursor: pointer;
}

.btn-toggle.active {
    background: #f4d06f;
    color: #0d1b2a;
    font-weight: 700;
}

/* ==========================================================================
   Particles / Confetti
   ========================================================================== */
#particles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 60;
}

.confetti-glyph {
    position: absolute;
    font-size: 20px;
    font-weight: 900;
    animation: floatDown 1.8s ease-in forwards;
}

@keyframes floatDown {
    0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(600px) rotate(360deg); opacity: 0; }
}
