/* ============================================================
   Sequence War: Last Stand — 스타일시트
   외부 CDN 없이 동작한다. 숫자/영문 전용 Orbitron은 로컬 폰트,
   한글은 시스템 폰트를 그대로 쓴다.
   ============================================================ */

@font-face {
    font-family: 'Orbitron';
    font-style: normal;
    font-weight: 400 900;
    font-display: swap;
    src: url('orbitron.woff2') format('woff2');
}

:root {
    --amber: #f59e0b;
    --amber-soft: rgba(245, 158, 11, 0.36);
    --lime: #84cc16;
    --red: #ef4444;
    --gold: #facc15;
    --text-dim: #9ca3af;
    --panel-dark: rgba(12, 10, 9, 0.78);
    --font-kr: 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    --font-num: 'Orbitron', 'Segoe UI', sans-serif;
}

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

html,
body {
    width: 100%;
    height: 100%;
    min-height: 100svh;
    overflow: hidden;
}

body {
    font-family: var(--font-kr);
    color: #fff;
    background:
        radial-gradient(circle at 50% 18%, rgba(245, 158, 11, 0.16), transparent 28%),
        radial-gradient(circle at 18% 82%, rgba(132, 204, 22, 0.13), transparent 24%),
        linear-gradient(135deg, #050505 0%, #17110a 42%, #070605 100%);
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 6px;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
    background-size: 42px 42px;
    mask-image: radial-gradient(circle at center, black, transparent 78%);
    -webkit-mask-image: radial-gradient(circle at center, black, transparent 78%);
}

.font-num {
    font-family: var(--font-num);
}

/* JS에서 토글하는 공용 상태 클래스 */
.hidden {
    display: none !important;
}

.opacity-0 {
    opacity: 0 !important;
    pointer-events: none !important;
}

button {
    font-family: inherit;
    color: inherit;
    border: none;
    background: none;
    cursor: pointer;
}

button:active {
    transform: scale(0.97);
}

/* ---------- 게임 컨테이너 ---------- */

#game-container {
    position: relative;
    width: 100%;
    max-width: 448px;
    height: min(91svh, 720px);
    max-height: calc(100dvh - 16px);
    background: #141210;
    border: 2px solid var(--amber);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 26px rgba(245, 158, 11, 0.44), 0 18px 70px rgba(0, 0, 0, 0.75);
}

#game-container::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background:
        radial-gradient(circle at 50% 0%, rgba(245, 158, 11, 0.12), transparent 36%),
        linear-gradient(90deg, rgba(0, 0, 0, 0.28), transparent 22%, transparent 78%, rgba(0, 0, 0, 0.28));
    mix-blend-mode: screen;
    opacity: 0.65;
}

@media (max-width: 640px) {
    body {
        padding: 5px;
    }

    /* 세로로 긴 화면에서도 상단에 붙지 않고 화면을 거의 채우도록 */
    #game-container {
        width: min(100%, 430px);
        height: min(93svh, 900px);
        max-height: calc(100dvh - 12px);
        border-radius: 12px;
    }

    #hud {
        padding: 10px;
    }
}

#gameCanvas {
    width: 100%;
    flex-grow: 1;
    display: block;
    touch-action: none;
}

/* ---------- 상단 HUD ---------- */

#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10;
    background: linear-gradient(to bottom, #0c0b09, transparent);
    pointer-events: none;
    transition: opacity 0.3s;
}

#hud-sequence-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.hud-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.hud-label {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 700;
    letter-spacing: 0.06em;
}

.hud-rule,
.hud-gold {
    display: flex;
    flex-direction: column;
}

.hud-gold {
    align-items: flex-end;
}

#seq-rule {
    font-size: 13px;
    color: var(--amber);
    font-weight: 800;
}

#gold-display {
    font-family: var(--font-num);
    font-size: 14px;
    font-weight: 700;
    color: var(--gold);
}

.seq-box {
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(120, 53, 15, 0.85);
    padding: 10px 12px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    pointer-events: auto;
}

#seq-history {
    font-family: var(--font-num);
    font-size: 24px;
    font-weight: 900;
    color: #fcd34d;
    line-height: 1.2;
    margin-top: 2px;
}

@media (min-width: 641px) {
    #seq-history {
        font-size: 28px;
    }
}

.progress-track {
    width: 100%;
    background: rgba(28, 25, 23, 0.6);
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
    border: 1px solid rgba(120, 53, 15, 0.3);
}

#progress-bar {
    background: linear-gradient(to right, #d97706, var(--lime));
    height: 100%;
    width: 0%;
    transition: width 0.3s;
}

/* 보스 HP 패널 */

#hud-boss-section {
    width: min(72%, 310px);
    margin-left: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: linear-gradient(135deg, rgba(17, 24, 39, 0.88), rgba(69, 10, 10, 0.82));
    border: 1px solid rgba(248, 113, 113, 0.82);
    padding: 12px;
    border-radius: 12px;
    pointer-events: auto;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.boss-hud-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.boss-hud-alert {
    color: var(--red);
    font-weight: 900;
    font-size: 12px;
    letter-spacing: 0.12em;
    animation: pulse 1.4s ease-in-out infinite;
}

#boss-hp-text {
    font-family: var(--font-num);
    font-size: 12px;
    font-weight: 900;
    color: #fff;
}

.boss-hp-track {
    width: 100%;
    background: rgba(59, 7, 100, 0.6);
    border-radius: 999px;
    height: 12px;
    overflow: hidden;
    border: 1px solid rgba(127, 29, 29, 0.5);
}

#boss-hp-bar-fill {
    background: linear-gradient(to right, #dc2626, #ec4899);
    height: 100%;
    width: 100%;
    transition: width 75ms;
}

/* ---------- 메뉴 / 결과 공용 오버레이 ---------- */

#menu-screen,
#result-screen {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 24px;
    background:
        radial-gradient(circle at 50% 16%, rgba(245, 158, 11, 0.22), transparent 28%),
        radial-gradient(circle at 50% 96%, rgba(15, 23, 42, 0.95), transparent 46%),
        linear-gradient(180deg, rgba(12, 10, 8, 0.96), rgba(28, 19, 10, 0.94) 54%, rgba(3, 7, 18, 0.98));
    transition: opacity 0.3s;
}

#menu-screen {
    justify-content: space-between;
}

#result-screen {
    justify-content: center;
}

#menu-screen::before,
#result-screen::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(90deg, transparent 0 18%, rgba(245, 158, 11, 0.12) 18.5%, transparent 19%, transparent 81%, rgba(245, 158, 11, 0.12) 81.5%, transparent 82%),
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.04) 0 2px, transparent 2px 34px),
        radial-gradient(circle at 20% 28%, rgba(132, 204, 22, 0.14), transparent 22%),
        radial-gradient(circle at 82% 72%, rgba(239, 68, 68, 0.13), transparent 24%);
    opacity: 0.76;
}

#menu-screen > *,
#result-screen > * {
    position: relative;
    z-index: 1;
}

#result-screen.result-victory {
    background:
        radial-gradient(circle at 50% 22%, rgba(132, 204, 22, 0.28), transparent 30%),
        linear-gradient(180deg, rgba(4, 20, 13, 0.96), rgba(28, 25, 23, 0.95) 58%, rgba(5, 7, 5, 0.99));
}

#result-screen.result-defeat {
    background:
        radial-gradient(circle at 50% 22%, rgba(239, 68, 68, 0.34), transparent 32%),
        linear-gradient(180deg, rgba(24, 5, 5, 0.98), rgba(28, 19, 10, 0.95) 58%, rgba(5, 5, 5, 0.99));
}

/* ---------- 메뉴 화면 ---------- */

.menu-header {
    margin-top: 12px;
}

.menu-badge {
    display: inline-block;
    padding: 4px 12px;
    font-size: 10px;
    font-weight: 700;
    color: var(--amber);
    border: 1px solid var(--amber);
    border-radius: 999px;
    letter-spacing: 0.14em;
    animation: pulse 2s ease-in-out infinite;
}

.menu-title {
    font-family: var(--font-num);
    font-size: 32px;
    font-weight: 900;
    margin-top: 12px;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, #f59e0b, #84cc16, #06b6d4);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.menu-subtitle {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 4px;
}

.stats-panel {
    display: flex;
    justify-content: center;
    gap: 18px;
    font-size: 11px;
    color: var(--text-dim);
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(120, 53, 15, 0.35);
    border-radius: 10px;
    padding: 7px 14px;
    margin-top: 10px;
}

.stats-panel .stat b {
    color: #fcd34d;
    font-family: var(--font-num);
    font-weight: 700;
    margin-left: 4px;
}

/* 업그레이드 패널 */

.shop-panel {
    width: 100%;
    background: linear-gradient(145deg, rgba(12, 10, 9, 0.78), rgba(41, 37, 36, 0.56));
    border: 1px solid var(--amber-soft);
    border-radius: 16px;
    padding: 16px;
    margin: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 18px 40px rgba(0, 0, 0, 0.38);
}

.shop-title {
    font-size: 12px;
    font-weight: 900;
    color: #eab308;
    letter-spacing: 0.06em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#shop-gold {
    color: var(--gold);
    font-family: var(--font-num);
    font-weight: 700;
}

.shop-item {
    width: 100%;
    padding: 10px;
    background: rgba(9, 7, 5, 0.5);
    border: 1px solid rgba(120, 53, 15, 0.3);
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
    text-align: left;
}

.shop-item:hover {
    background: rgba(28, 25, 23, 0.4);
}

.shop-item-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.shop-item-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}

.icon-green {
    background: rgba(34, 197, 94, 0.2);
}

.icon-amber {
    background: rgba(245, 158, 11, 0.2);
}

.icon-yellow {
    background: rgba(234, 179, 8, 0.2);
}

.shop-item-name {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
}

.shop-item-desc {
    display: block;
    font-size: 10px;
    color: var(--text-dim);
}

.shop-item-cost {
    padding: 4px 10px;
    background: rgba(234, 179, 8, 0.2);
    color: var(--gold);
    font-size: 12px;
    font-weight: 700;
    font-family: var(--font-num);
    border-radius: 8px;
    border: 1px solid rgba(234, 179, 8, 0.3);
    white-space: nowrap;
}

/* 버튼 */

.menu-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.btn-primary {
    width: 100%;
    padding: 16px;
    background: linear-gradient(to right, var(--lime), var(--amber));
    color: #000;
    font-weight: 900;
    font-size: 17px;
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.4);
    transition: filter 0.15s;
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.menu-hint {
    font-size: 10px;
    color: #6b7280;
}

.btn-ghost {
    margin-top: 2px;
    padding: 6px;
    font-size: 11px;
    color: #78716c;
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color 0.15s;
}

.btn-ghost:hover {
    color: #d6d3d1;
}

/* ---------- 결과 화면 ---------- */

.result-icon {
    font-size: 56px;
    margin-bottom: 16px;
    line-height: 1;
}

.result-icon.bounce {
    animation: bounce 1s infinite;
}

.result-icon.pulse {
    animation: pulse 1.4s ease-in-out infinite;
}

.result-title {
    font-family: var(--font-num);
    font-size: 38px;
    font-weight: 900;
    margin-bottom: 8px;
    letter-spacing: 0.04em;
}

.result-title.green {
    color: #39ff14;
    text-shadow: 0 0 10px #39ff14, 0 0 20px #39ff14;
}

.result-title.gold {
    color: #fde047;
}

.result-title.red {
    color: var(--red);
}

.result-desc {
    color: var(--text-dim);
    font-size: 13px;
    margin-bottom: 24px;
    max-width: 300px;
}

.result-card {
    background: linear-gradient(145deg, rgba(12, 10, 9, 0.78), rgba(41, 37, 36, 0.56));
    padding: 20px;
    border-radius: 16px;
    border: 1px solid var(--amber-soft);
    max-width: 300px;
    width: 100%;
    margin-bottom: 32px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 18px 40px rgba(0, 0, 0, 0.38);
}

.reward-gold {
    font-family: var(--font-num);
    font-size: 30px;
    font-weight: 800;
    color: var(--gold);
    margin: 4px 0 16px;
}

.result-army-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #d1d5db;
    border-top: 1px solid rgba(120, 53, 15, 0.5);
    padding-top: 12px;
}

#final-army-size {
    font-weight: 700;
    color: var(--amber);
}

.result-actions {
    display: flex;
    gap: 14px;
    width: 100%;
    max-width: 300px;
}

.result-actions .btn-primary {
    flex: 1;
    padding: 12px;
    font-size: 14px;
}

.btn-secondary {
    padding: 12px 20px;
    background: rgba(28, 25, 23, 0.8);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    border-radius: 12px;
    border: 1px solid rgba(245, 158, 11, 0.3);
    transition: background 0.15s;
}

.btn-secondary:hover {
    background: #292524;
}

/* ---------- 배너 ---------- */

.banner {
    position: absolute;
    left: 50%;
    z-index: 10;
    transform: translateX(-50%) scale(0);
    transition: transform 0.25s;
    pointer-events: none;
    text-align: center;
    font-family: var(--font-num);
    border-radius: 12px;
}

.banner.scale-100 {
    transform: translateX(-50%) scale(1);
}

#boss-warning-banner {
    top: 25%;
    background: rgba(220, 38, 38, 0.9);
    border: 2px solid #facc15;
    color: #fff;
    padding: 12px 32px;
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.8);
}

.banner-label {
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.14em;
    color: #fde047;
    margin-bottom: 2px;
}

.banner-title {
    font-size: 18px;
    font-weight: 900;
    color: #fff;
}

#gate-countdown-banner {
    top: 34%;
    width: min(92%, 390px);
    background: rgba(0, 0, 0, 0.88);
    border: 2px solid #fbbf24;
    color: #fef3c7;
    padding: 16px 24px;
    box-shadow: 0 0 24px rgba(245, 158, 11, 0.55);
}

#gate-countdown-label {
    color: #bef264;
    margin-bottom: 4px;
}

#gate-countdown-problem {
    font-family: var(--font-kr);
    font-size: 24px;
    font-weight: 900;
    color: #fde68a;
    line-height: 1.25;
}

#gate-countdown-text {
    font-size: 38px;
    font-weight: 900;
    color: #fff;
    margin-top: 4px;
}

/* ---------- 하단 바 ---------- */

#bottom-bar {
    background: #0c0b09;
    border-top: 1px solid rgba(69, 26, 3, 0.8);
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(9, 7, 5, 0.6);
    border: 1px solid rgba(120, 53, 15, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    transition: color 0.15s, background 0.15s;
}

.icon-btn:hover {
    background: #1c1917;
    color: #fff;
}

.status-text {
    font-size: 10px;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-num);
    font-weight: 700;
}

.status-text .sep {
    color: #4b5563;
}

#army-size-text {
    color: var(--amber);
}

#weapon-lvl-display {
    color: #22c55e;
}

#shield-display {
    color: #22d3ee;
}

#combo-display {
    color: #f472b6;
}

/* ---------- 모달 ---------- */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: #16091f;
    border: 2px solid #ec4899;
    border-radius: 16px;
    max-width: 300px;
    width: 100%;
    padding: 20px;
    text-align: center;
    box-shadow: 0 0 20px rgba(255, 0, 127, 0.4);
}

.modal-icon {
    width: 44px;
    height: 44px;
    margin: 0 auto 10px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fde047, #d97706 78%);
    color: #451a03;
    font-family: var(--font-num);
    font-weight: 900;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 14px rgba(250, 204, 21, 0.5);
}

.modal-card h4 {
    font-size: 15px;
    font-weight: 900;
    margin-bottom: 4px;
}

.modal-card p {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 16px;
    line-height: 1.5;
}

.btn-alert {
    padding: 8px 24px;
    background: #db2777;
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    border-radius: 8px;
    transition: background 0.15s;
}

.btn-alert:hover {
    background: #ec4899;
}

/* 진행 초기화 확인 모달 변형 */
.modal-card-warn {
    background: #1c1210;
    border-color: var(--amber);
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.35);
}

.modal-icon-warn {
    background: radial-gradient(circle at 35% 30%, #fca5a5, #b91c1c 78%);
    color: #fff;
    box-shadow: 0 0 14px rgba(239, 68, 68, 0.5);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-danger {
    padding: 10px 16px;
    background: #b91c1c;
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    border-radius: 8px;
    transition: background 0.15s;
}

.btn-danger:hover {
    background: #dc2626;
}

.modal-actions .btn-secondary {
    padding: 10px 16px;
    font-size: 12px;
}

/* ---------- 애니메이션 ---------- */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

@keyframes bounce {
    0%, 100% { transform: translateY(-14%); animation-timing-function: cubic-bezier(0.8, 0, 1, 1); }
    50% { transform: translateY(0); animation-timing-function: cubic-bezier(0, 0, 0.2, 1); }
}

.shake-screen {
    animation: shake 0.2s infinite;
}

@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0) rotate(1deg); }
    30% { transform: translate(0, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    75% { transform: translate(2px, 1px) rotate(-1deg); }
    90% { transform: translate(-1px, -1px) rotate(1deg); }
    100% { transform: translate(1px, 2px) rotate(0deg); }
}
