/* ==========================================================================
   LIGHTMINE
   "Midnight Mine Blueprint" - deep navy chalkboard, lantern gold, glowing gems
   ========================================================================== */

:root {
    --bg: #0c1526;
    --bg-2: #16233d;
    --panel: rgba(21, 33, 57, .92);
    --panel-line: rgba(232, 228, 216, .12);
    --chalk: #e8e4d8;
    --chalk-dim: rgba(232, 228, 216, .55);
    --gold: #f5b83d;
    --gold-deep: #a86e0e;
    --cyan: #59e3ff;
    --danger: #ff5d5d;

    --gem-red: #e0413c;
    --gem-yellow: #f2b135;
    --gem-blue: #2e6fd8;
    --gem-white: #f2ead8;
    --gem-crystal: rgba(190, 230, 255, .35);
    --gem-dark: #262b38;

    /* 로고/숫자용 라틴 디스플레이 (언어 무관) */
    --font-display: 'Bungee', 'Baloo 2', sans-serif;
    /* 본문/제목: 언어별로 아래 html[lang] 규칙이 덮어씀. 기본(라틴)은 Baloo 2 */
    --font-head: 'Baloo 2', 'Nanum Gothic', 'Noto Sans JP', 'Noto Sans SC', sans-serif;
    --font-body: 'Baloo 2', 'Nanum Gothic', 'Noto Sans JP', 'Noto Sans SC', sans-serif;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* 국가별 대표 폰트 — 한글은 네이버 나눔고딕 */
html[lang="ko"] { --font-head: 'Nanum Gothic', sans-serif; --font-body: 'Nanum Gothic', sans-serif; }
html[lang="ja"] { --font-head: 'Noto Sans JP', sans-serif;  --font-body: 'Noto Sans JP', sans-serif; }
html[lang="zh"] { --font-head: 'Noto Sans SC', sans-serif;  --font-body: 'Noto Sans SC', sans-serif; }

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

/* hidden 속성이 display:flex 등 CSS 지정보다 항상 우선하도록 */
[hidden] { display: none !important; }

html, body { height: 100%; overscroll-behavior: none; }

/* 뷰포트를 고정해 문서 자체의 좌우/상하 스크롤(웹뷰 고무줄 울렁거림)을 차단.
   내부 스크롤이 필요한 곳(상점 그리드, 게임 로그)은 각자 overflow 로 스크롤. */
body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(130% 90% at 50% -10%, #1c2c4d 0%, var(--bg) 55%, #080e1a 100%);
    color: var(--chalk);
    font-family: var(--font-body);
    user-select: none;
    -webkit-user-select: none;
    touch-action: pan-y;
    overflow: hidden;
    overscroll-behavior: none;
}

/* faint drifting dust / ore sparkles */
#stars {
    position: fixed; inset: 0; pointer-events: none; z-index: 0;
    background-image:
        radial-gradient(1.5px 1.5px at 15% 25%, rgba(245, 184, 61, .5), transparent 60%),
        radial-gradient(1px 1px at 70% 15%, rgba(89, 227, 255, .55), transparent 60%),
        radial-gradient(1.2px 1.2px at 85% 65%, rgba(232, 228, 216, .4), transparent 60%),
        radial-gradient(1px 1px at 35% 80%, rgba(245, 184, 61, .35), transparent 60%),
        radial-gradient(1.6px 1.6px at 55% 45%, rgba(89, 227, 255, .3), transparent 60%);
    animation: dust 14s linear infinite alternate;
    opacity: .8;
}
@keyframes dust {
    from { transform: translateY(-6px); }
    to   { transform: translateY(10px); }
}

#app {
    position: relative; z-index: 1;
    height: 100dvh;
    display: flex; flex-direction: column;
    max-width: 520px; margin: 0 auto;
    padding-top: var(--safe-top);
}

/* ==================== top bar ==================== */
#topbar {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px 6px;
}
#tb-logo {
    font-family: var(--font-display);
    font-size: 17px; letter-spacing: 1px; color: var(--chalk);
    text-shadow: 0 0 12px rgba(245, 184, 61, .35);
}
#tb-logo span { color: var(--gold); }
.tb-right { margin-left: auto; display: flex; gap: 6px; }
.tb-btn {
    min-width: 36px; height: 36px; padding: 0 10px;
    border: 1px solid var(--panel-line); border-radius: 10px;
    background: rgba(232, 228, 216, .06);
    color: var(--chalk); font-family: var(--font-head); font-size: 14px;
    cursor: pointer; transition: transform .12s, background .2s;
}
.tb-btn:active { transform: scale(.92); background: rgba(232, 228, 216, .14); }
.tb-nick { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--gold); }
.tb-icon { font-size: 16px; }
.tb-gems { display: flex; align-items: center; gap: 4px; padding: 0 8px; color: var(--gold); }
.tb-gems b { font-family: var(--font-display); font-size: 13px; }
.gem-ico { font-size: 13px; filter: drop-shadow(0 0 4px rgba(89, 227, 255, .6)); }

/* ==================== shop ==================== */
.shop-top { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.shop-balance {
    display: flex; align-items: center; gap: 6px; padding: 8px 14px;
    background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px;
}
.shop-balance b { font-family: var(--font-display); font-size: 18px; color: var(--gold); }
.shop-balance .gem-ico { font-size: 18px; }
.shop-earn { flex: 1; padding: 10px 6px; font-size: 13.5px; }
.shop-sub {
    display: flex; align-items: center; gap: 10px; justify-content: space-between;
    padding: 12px 14px; margin-bottom: 10px; border-radius: 14px;
    background: linear-gradient(180deg, rgba(245,184,61,.14), rgba(245,184,61,.05));
    border: 1px solid rgba(245, 184, 61, .35); font-size: 13.5px;
}
.shop-sub .btn { flex: none; padding: 9px 14px; font-size: 13.5px; }
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-bottom: 20px;
    grid-auto-rows: 1fr; }   /* 모든 카드 높이 동일 (설명 줄수가 달라도) */
.shop-card {
    display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 10px;
    background: var(--panel); border: 1px solid var(--panel-line); border-radius: 16px;
}
.shop-card .shop-btn { margin-top: auto; }   /* 구매/장착 버튼은 카드 하단에 정렬 */
.shop-card.is-equipped { border-color: var(--gold); box-shadow: 0 0 14px rgba(245, 184, 61, .2); }
.shop-name { font-family: var(--font-head); font-size: 14px; text-align: center; }
.shop-sw { width: 60px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.shop-sw-board { position: relative; border: 1px solid rgba(255,255,255,.15); }
.shop-sw-board i { width: 70%; height: 2px; border-radius: 2px; }
.shop-sw-beam { height: 8px; width: 54px; border-radius: 6px; box-shadow: 0 0 10px currentColor; }
.shop-sw-gem { gap: 4px; }
.shop-sw-gem i { width: 12px; height: 12px; border-radius: 3px; transform: rotate(45deg); }
.shop-sw-title { font-size: 30px; }
.shop-btn {
    width: 100%; padding: 8px; border: none; border-radius: 10px; cursor: pointer;
    font-family: var(--font-head); font-size: 13.5px;
    display: flex; align-items: center; justify-content: center; gap: 4px;
}
.shop-btn.buy { color: #1a1206; background: linear-gradient(180deg, #ffd76e, #f5a623); }
.shop-btn.own { color: var(--cyan); background: rgba(89, 227, 255, .12); border: 1px solid var(--cyan); }
.shop-btn.equipped { color: var(--gold); background: rgba(245, 184, 61, .12); border: 1px solid var(--gold); }
.shop-btn:active { transform: scale(.96); }
.rank-title {
    display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 6px;
    font-size: 10px; color: var(--gold); background: rgba(245, 184, 61, .14); vertical-align: middle;
}
.shop-sub-2x { margin-left: auto; padding: 6px 12px; border-radius: 10px; font-family: var(--font-display);
    font-size: 13px; color: #1a1206; background: linear-gradient(180deg, #ffd76e, #f5a623); }
.shop-cat-scroll { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none;
    /* overflow-x:auto → overflow-y:auto 로 계산되며 이 바가 스크롤 컨테이너가 됨.
       그러면 flex item 의 min-height:auto 가 0 이 되어, 아이템이 많아 .screen 이
       넘칠 때 이 바만 찌부러져(높이 붕괴) 사라짐. flex-shrink:0 으로 축소를 막는다. */
    flex: 0 0 auto;
    /* 스크롤 시 카테고리 탭을 상단에 고정 (음수 margin으로 화면 좌우 끝까지 배경 확장) */
    position: sticky; top: 0; z-index: 5;
    margin: -8px -14px 8px; padding: 8px 14px;
    background: var(--bg); box-shadow: 0 6px 10px -6px rgba(0, 0, 0, .45); }
.shop-cat-scroll::-webkit-scrollbar { display: none; }
/* #id 특이도로 .seg button{flex:1} 오버라이드 → 탭이 찌그러지지 않고 가로 스크롤 */
#shop-cat.shop-cat-scroll button { flex: 0 0 auto; white-space: nowrap; padding-left: 14px; padding-right: 14px; }
.shop-desc { display: block; color: var(--chalk-dim); font-size: 11px; text-align: center; line-height: 1.35; }
.shop-qty { font-size: 12px; color: var(--cyan); }
.shop-sw-emoji { font-size: 34px; }
.shop-btn em { font-style: normal; opacity: .8; font-size: 11px; }

/* roulette */
.roulette-box {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    padding: 14px; margin-bottom: 12px; border-radius: 18px;
    background: var(--panel); border: 1px solid var(--panel-line);
}
.roulette-box.collapsed { padding: 12px 14px; }
.roulette-head {
    display: flex; align-items: center; gap: 8px;
    font-family: var(--font-head); font-size: 15px; color: var(--gold);
}
.roulette-head .roulette-ico { font-size: 22px; }
.wheel-wrap { position: relative; width: 190px; height: 190px;
    animation: wheel-pop .35s cubic-bezier(.2,.9,.3,1.4); }
@keyframes wheel-pop { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }
.wheel { width: 100%; height: 100%; border-radius: 50%; box-shadow: 0 0 0 4px rgba(245,184,61,.4), 0 8px 22px rgba(0,0,0,.5); }
.wheel-pointer { position: absolute; top: -8px; left: 50%; transform: translateX(-50%); color: var(--gold); font-size: 22px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); z-index: 2; }
.wheel-hub { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 40px; height: 40px; border-radius: 50%; background: #0c1526; border: 2px solid var(--gold);
    display: flex; align-items: center; justify-content: center; font-size: 18px; z-index: 2; }
.roulette-actions { display: flex; gap: 8px; width: 100%; }
.roulette-actions .btn { flex: 1; padding: 11px 6px; font-size: 14px; }
.roulette-actions .btn b { margin-left: 4px; font-family: var(--font-display); }
.roulette-timer { font-size: 12px; color: var(--chalk-dim); min-height: 16px; }

/* gacha */
.gacha-box { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 12px;
    border-radius: 16px; background: linear-gradient(180deg, rgba(89,227,255,.1), rgba(89,227,255,.03));
    border: 1px solid rgba(89,227,255,.3); }
.gacha-visual { font-size: 40px; }
.gacha-visual.shaking { animation: gacha-shake .3s ease-in-out infinite; }
@keyframes gacha-shake { 0%,100%{transform:rotate(-8deg)} 50%{transform:rotate(8deg)} }
.gacha-info { flex: 1; display: flex; flex-direction: column; }
.gacha-info b { font-family: var(--font-head); font-size: 15px; }
.gacha-info small { color: var(--chalk-dim); font-size: 11.5px; }
.gacha-box .btn { flex: none; padding: 9px 12px; display: flex; align-items: center; gap: 4px; }

/* pet companion — 항상 숨쉬고, 걷는 방향으로 몸을 돌리는 살아있는 펫 */
#pet-companion {
    position: fixed; left: 12px; bottom: calc(72px + var(--safe-bottom)); z-index: 40;
    width: 60px; height: 64px; cursor: pointer; pointer-events: auto;
    -webkit-tap-highlight-color: transparent; touch-action: manipulation;
    --face: 1;   /* 1=왼쪽 보기(기본), -1=오른쪽 보기 (걷는 방향) */
}
#pet-companion.in-game { bottom: calc(58px + var(--safe-bottom)); }
.pet-body {
    display: block; position: absolute; left: 50%; bottom: 6px;
    transform: translateX(-50%) scaleX(var(--face));
    font-size: 46px; line-height: 1; transform-origin: 50% 100%;
    animation: pet-bob 2.8s ease-in-out infinite;
}
.pet-shadow {
    position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%);
    width: 40px; height: 9px; border-radius: 50%; background: rgba(0,0,0,.4);
    filter: blur(2px); animation: pet-shadow 2.8s ease-in-out infinite;
}
/* 숨쉬기: 위아래 둥실 + 살짝 눌렸다 펴지는 스쿼시 */
@keyframes pet-bob { 0%,100%{transform:translateX(-50%) scaleX(var(--face)) translateY(0) scaleY(1)} 50%{transform:translateX(-50%) scaleX(var(--face)) translateY(-7px) scaleY(1.04)} }
@keyframes pet-shadow { 0%,100%{transform:translateX(-50%) scaleX(1);opacity:.4} 50%{transform:translateX(-50%) scaleX(.78);opacity:.24} }

/* 반응 애니메이션 (pet-body 위에 얹힘) */
.pet-body.pet-hop   { animation: pet-hop .6s ease; }
.pet-body.pet-blink { animation: pet-blink .4s ease; }
.pet-body.pet-look  { animation: pet-look .55s ease; }
.pet-body.pet-shake { animation: pet-shake .6s ease; }
.pet-body.pet-cheer { animation: pet-cheer .6s ease 3; }
.pet-body.pet-walk  { animation: pet-walk .4s ease-in-out 6; }
@keyframes pet-hop   { 0%,100%{transform:translateX(-50%) scaleX(var(--face)) translateY(0) scale(1)} 40%{transform:translateX(-50%) scaleX(var(--face)) translateY(-20px) scale(1.08)} 70%{transform:translateX(-50%) scaleX(var(--face)) translateY(-4px) scale(.96)} }
@keyframes pet-blink { 0%,100%{transform:translateX(-50%) scaleX(var(--face)) scaleY(1)} 50%{transform:translateX(-50%) scaleX(var(--face)) scaleY(.55)} }
@keyframes pet-look  { 0%,100%{transform:translateX(-50%) scaleX(var(--face)) rotate(0)} 30%{transform:translateX(-50%) scaleX(var(--face)) rotate(-14deg)} 65%{transform:translateX(-50%) scaleX(var(--face)) rotate(14deg)} }
@keyframes pet-shake { 0%,100%{transform:translateX(-50%) scaleX(var(--face)) rotate(0)} 20%{transform:translateX(-58%) scaleX(var(--face)) rotate(-8deg)} 60%{transform:translateX(-42%) scaleX(var(--face)) rotate(8deg)} }
@keyframes pet-cheer { 0%,100%{transform:translateX(-50%) scaleX(var(--face)) translateY(0) scale(1)} 30%{transform:translateX(-50%) scaleX(var(--face)) translateY(-22px) scale(1.22) rotate(-12deg)} 60%{transform:translateX(-50%) scaleX(var(--face)) translateY(-8px) scale(1.12) rotate(12deg)} }
/* 걷기: 총총 뛰는 잔걸음 */
@keyframes pet-walk  { 0%,100%{transform:translateX(-50%) scaleX(var(--face)) translateY(0) rotate(0)} 25%{transform:translateX(-50%) scaleX(var(--face)) translateY(-6px) rotate(-4deg)} 75%{transform:translateX(-50%) scaleX(var(--face)) translateY(-6px) rotate(4deg)} }

/* 말풍선 */
.pet-bubble {
    position: absolute; left: 50%; bottom: 50px; transform: translateX(-50%) scale(.4);
    min-width: 26px; padding: 4px 8px; border-radius: 12px; border-bottom-left-radius: 4px;
    background: #fdf6e3; color: #1a1206; font-size: 16px; line-height: 1; text-align: center;
    box-shadow: 0 3px 8px rgba(0,0,0,.4); opacity: 0; pointer-events: none; white-space: nowrap;
    transition: transform .2s cubic-bezier(.2,.9,.3,1.5), opacity .2s ease;
}
.pet-bubble.show { opacity: 1; transform: translateX(-50%) scale(1); }
.pet-bubble::after {
    content: ''; position: absolute; left: 14px; bottom: -5px; width: 10px; height: 10px;
    background: #fdf6e3; transform: rotate(45deg); border-radius: 2px;
}

/* 파티클 (하트/별 떠오름) */
.pet-particle {
    position: absolute; bottom: 34px; font-size: 15px; pointer-events: none;
    animation: pet-particle 1.1s ease-out forwards;
}
@keyframes pet-particle {
    0%   { opacity: 0; transform: translate(0, 0) scale(.5); }
    20%  { opacity: 1; }
    100% { opacity: 0; transform: translate(var(--dx, 0), -46px) scale(1.15); }
}

/* emotes */
#btn-emote { position: fixed; right: 12px; bottom: calc(70px + var(--safe-bottom)); width: 46px; height: 46px;
    border-radius: 50%; border: 1px solid var(--panel-line); background: rgba(21,33,57,.95); color: var(--chalk);
    font-size: 22px; z-index: 41; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.5); }
.emote-picker { position: fixed; right: 12px; bottom: calc(124px + var(--safe-bottom)); z-index: 42;
    display: flex; flex-wrap: wrap; gap: 6px; max-width: 210px; padding: 8px;
    background: rgba(12,21,38,.96); border: 1px solid var(--panel-line); border-radius: 14px; }
.emote-picker button { width: 40px; height: 40px; font-size: 22px; border: none; border-radius: 10px;
    background: rgba(232,228,216,.08); cursor: pointer; }
#emote-layer { position: fixed; inset: 0; pointer-events: none; z-index: 45; }
.emote-float { position: absolute; font-size: 72px; animation: emote-pop 2.6s ease forwards;
    filter: drop-shadow(0 4px 14px rgba(0,0,0,.6)); }
.emote-float.em-me { left: 18px; bottom: 38%; }
.emote-float.em-opp { right: 18px; top: 20%; }
/* 누가 보냈는지 라벨 */
.emote-float::after { content: attr(data-who); position: absolute; left: 50%; bottom: -18px; transform: translateX(-50%);
    font-size: 12px; font-family: var(--font-head); white-space: nowrap; padding: 2px 8px; border-radius: 8px;
    background: rgba(12,21,38,.9); border: 1px solid var(--panel-line); }
.emote-float.em-me::after { color: var(--gold); }
.emote-float.em-opp::after { color: var(--cyan); }
@keyframes emote-pop { 0%{opacity:0;transform:scale(.4)} 12%{opacity:1;transform:scale(1.3)} 26%{transform:scale(1)} 82%{opacity:1} 100%{opacity:0;transform:translateY(-46px) scale(.9)} }

/* HUD 상대 칭호 칩 */
.hud-title { display: inline-block; padding: 0 5px; margin-right: 2px; border-radius: 6px;
    font-size: 10px; color: var(--gold); background: rgba(245,184,61,.14); vertical-align: middle; }

/* 대결 난이도 카드: 실시간 대기 인원 뱃지 */
.mode-wait { position: absolute; top: 10px; right: 12px; padding: 3px 9px; border-radius: 10px;
    font-size: 11.5px; font-family: var(--font-head); color: var(--cyan);
    background: rgba(89,227,255,.12); border: 1px solid rgba(89,227,255,.4); }

/* solo consumables: 버튼 + 모달 목록 */
.btn-items { flex: 0 0 auto; padding-left: 14px; padding-right: 14px; }
.items-body { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 6px 0 4px; }
.items-empty { text-align: center; color: var(--chalk-dim); font-size: 13px; padding: 12px 0; }
.solo-item { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 12px; border-radius: 12px; border: 1px solid var(--panel-line);
    background: rgba(232,228,216,.05); color: var(--chalk); font-size: 18px; cursor: pointer; }
.solo-item .si-name { font-size: 11px; color: var(--chalk); font-family: var(--font-head); }
.solo-item .si-desc { font-size: 10px; color: var(--chalk-dim); max-width: 96px; line-height: 1.3; text-align: center; }
.solo-item.is-used { opacity: .45; }
.solo-item.is-used .si-qty { background: var(--cyan); }
.solo-item.is-passive { cursor: default; border-style: dashed; }
.solo-item.is-passive .si-qty { background: rgba(89,227,255,.2); color: var(--cyan); font-size: 9px; }

/* language select modal */
.lang-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 4px; }
.lang-opt {
    padding: 12px 8px; border-radius: 12px; cursor: pointer;
    background: rgba(232, 228, 216, .05); border: 1px solid var(--panel-line);
    color: var(--chalk); font-family: var(--font-head); font-size: 15px;
}
.lang-opt.active { background: rgba(245, 184, 61, .14); border-color: var(--gold); color: var(--gold); }
.lang-opt:active { transform: scale(.96); }
.solo-item .si-qty { position: absolute; top: -6px; right: -4px; min-width: 16px; height: 16px; padding: 0 3px;
    border-radius: 8px; background: var(--gold); color: #1a1206; font-size: 10px; font-family: var(--font-display);
    display: flex; align-items: center; justify-content: center; }
.solo-item:active { transform: scale(.95); }

/* ==================== screens ==================== */
.screen {
    flex: 1; display: none; flex-direction: column;
    padding: 8px 14px calc(14px + var(--safe-bottom));
    overflow-y: auto; overflow-x: hidden;
    animation: scr-in .35s cubic-bezier(.2, .9, .3, 1.2);
}
.screen.active { display: flex; }
@keyframes scr-in {
    from { opacity: 0; transform: translateY(14px) scale(.985); }
    to   { opacity: 1; transform: none; }
}

.scr-title {
    font-family: var(--font-head); font-size: 22px; margin: 8px 2px 14px;
    color: var(--gold);
    text-shadow: 0 0 18px rgba(245, 184, 61, .3);
}

/* ==================== home ==================== */
.home-hero { text-align: center; padding: 26px 0 10px; }
.hero-gems { display: flex; justify-content: center; gap: 14px; margin-bottom: 14px; }
.hgem {
    width: 22px; height: 22px; display: inline-block;
    transform: rotate(45deg); border-radius: 4px;
    animation: bob 2.6s ease-in-out infinite;
}
.hgem:nth-child(2) { animation-delay: .3s; }
.hgem:nth-child(3) { animation-delay: .6s; }
.hgem:nth-child(4) { animation-delay: .9s; }
.hg-red    { background: var(--gem-red);    box-shadow: 0 0 18px rgba(224, 65, 60, .7); }
.hg-yellow { background: var(--gem-yellow); box-shadow: 0 0 18px rgba(242, 177, 53, .7); }
.hg-blue   { background: var(--gem-blue);   box-shadow: 0 0 18px rgba(46, 111, 216, .8); }
.hg-white  { background: var(--gem-white);  box-shadow: 0 0 18px rgba(242, 234, 216, .7); }
@keyframes bob {
    0%, 100% { transform: rotate(45deg) translateY(0); }
    50%      { transform: rotate(45deg) translateY(-7px); }
}
.game-title { line-height: 1.1; }
.gt-main {
    display: block; font-family: var(--font-display);
    font-size: clamp(30px, 9vw, 44px); letter-spacing: 2px;
    background: linear-gradient(180deg, #ffe9b0 0%, var(--gold) 55%, #c98a1b 100%);
    -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .45)) drop-shadow(0 0 22px rgba(245, 184, 61, .25));
}
.gt-sub {
    display: block; margin-top: 8px; font-family: var(--font-head);
    font-size: 14px; color: var(--chalk-dim); letter-spacing: 1px;
}

.home-menu { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.menu-card {
    position: relative; display: grid;
    grid-template-columns: 52px 1fr; grid-template-rows: auto auto;
    align-items: center; column-gap: 12px; text-align: left;
    padding: 16px 18px;
    background: var(--panel);
    border: 1px solid var(--panel-line); border-radius: 18px;
    color: var(--chalk); cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .06);
    transition: transform .15s, border-color .2s, box-shadow .2s;
    overflow: hidden;
}
.menu-card::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, .06) 45%, transparent 60%);
    transform: translateX(-120%);
    transition: transform .5s;
}
.menu-card:active { transform: scale(.97); }
.menu-card:active::after { transform: translateX(120%); }
.mc-solo   { border-left: 4px solid var(--gold); }
.mc-battle { border-left: 4px solid var(--danger); }
.mc-friend { border-left: 4px solid var(--cyan); }
.mc-ico { grid-row: span 2; font-size: 30px; text-align: center; filter: drop-shadow(0 0 8px rgba(245,184,61,.4)); }
.mc-label { font-family: var(--font-head); font-size: 19px; }
.mc-desc { font-size: 12.5px; color: var(--chalk-dim); }

.home-row { display: flex; gap: 12px; }
.menu-mini {
    flex: 1; padding: 13px; display: flex; align-items: center; justify-content: center; gap: 8px;
    background: rgba(232, 228, 216, .05);
    border: 1px solid var(--panel-line); border-radius: 14px;
    color: var(--chalk); font-family: var(--font-head); font-size: 15px; cursor: pointer;
    transition: transform .15s;
}
.menu-mini:active { transform: scale(.95); }
.menu-mini em { font-style: normal; }

/* ==================== mode select ==================== */
.mode-list { display: flex; flex-direction: column; gap: 12px; }
.mode-card {
    position: relative;
    padding: 18px; text-align: left;
    background: var(--panel); border: 1px solid var(--panel-line); border-radius: 18px;
    color: var(--chalk); cursor: pointer; transition: transform .15s, border-color .2s;
}
.mode-card:active { transform: scale(.97); border-color: var(--gold); }
.mode-card b { display: block; font-family: var(--font-head); font-size: 18px; margin: 8px 0 4px; }
.mode-card small { color: var(--chalk-dim); font-size: 12.5px; line-height: 1.5; display: block; }
.mode-gems { display: flex; gap: 6px; }
.dot { width: 14px; height: 14px; border-radius: 3px; transform: rotate(45deg); display: inline-block; }
.d-red { background: var(--gem-red); } .d-yellow { background: var(--gem-yellow); }
.d-blue { background: var(--gem-blue); } .d-white { background: var(--gem-white); }
.d-crystal { background: var(--gem-crystal); border: 1px solid rgba(190, 230, 255, .8); }
.d-dark { background: var(--gem-dark); border: 1px solid rgba(232, 228, 216, .3); }

/* ==================== game screen ==================== */
#scr-game { padding-left: 8px; padding-right: 8px; }
.game-hud {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 8px 8px; flex-wrap: wrap;
}
.hud-item {
    display: flex; align-items: baseline; gap: 6px;
    font-size: 12px; color: var(--chalk-dim);
}
.hud-item b {
    font-family: var(--font-display); font-size: 18px; color: var(--gold);
    text-shadow: 0 0 10px rgba(245, 184, 61, .4);
}
.hud-vs { margin-left: auto; display: flex; align-items: baseline; gap: 6px; font-size: 12px; color: var(--chalk-dim); }
.hud-vs b { font-family: var(--font-display); font-size: 16px; color: var(--cyan); }

.board-wrap { position: relative; width: 100%; }
#board { display: block; width: 100%; touch-action: none; }

.beam-result {
    position: absolute; left: 50%; top: 50%;
    transform: translate(-50%, -50%) scale(.6);
    padding: 10px 22px; border-radius: 40px;
    background: rgba(12, 21, 38, .92);
    border: 2px solid var(--gold);
    font-family: var(--font-head); font-size: 18px; white-space: nowrap;
    box-shadow: 0 0 30px rgba(245, 184, 61, .35);
    opacity: 0; pointer-events: none;
    transition: opacity .2s, transform .25s cubic-bezier(.2, 1.4, .4, 1);
    z-index: 5;
}
.beam-result.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

.game-log {
    height: 96px; overflow-y: auto;
    /* 페이지(.screen) 스크롤에 제스처를 뺏기지 않고 로그 안에서 세로 스크롤되도록 */
    -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y;
    margin: 6px 4px; padding: 4px 2px;
    background: rgba(0, 0, 0, .25); border: 1px solid var(--panel-line); border-radius: 10px;
    font-size: 12px; line-height: 1.5;
    /* 3열 + 가운데 세로 구분선 */
    display: grid; grid-template-columns: repeat(3, 1fr); align-content: start;
    /* 고정 높이 그리드가 행을 압축(→글자 뭉갬·스크롤 불가)하지 않도록 행 높이를 내용에 고정 */
    grid-auto-rows: min-content;
    background-image:
        linear-gradient(to right, transparent calc(33.33% - 1px), var(--panel-line) 33.33%, transparent calc(33.33% + 1px)),
        linear-gradient(to right, transparent calc(66.66% - 1px), var(--panel-line) 66.66%, transparent calc(66.66% + 1px));
}
.game-log p { color: var(--chalk-dim); text-align: left; padding: 1px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 안내/대기 메시지는 3열 전체 폭 사용 */
.game-log p:not(.log-me):not(.log-opp) { grid-column: 1 / -1; white-space: normal; }
.game-log p b { color: var(--chalk); }
.game-log .log-me b { color: var(--gold); }
.game-log .log-opp b { color: var(--cyan); }

.tool-tabs { display: flex; gap: 6px; margin: 2px 4px; }
.tool-tab {
    flex: 1; padding: 9px 4px; border-radius: 10px;
    background: rgba(232, 228, 216, .05); border: 1px solid var(--panel-line);
    color: var(--chalk-dim); font-family: var(--font-head); font-size: 13.5px; cursor: pointer;
    transition: all .2s;
}
.tool-tab.active {
    background: rgba(245, 184, 61, .14); border-color: var(--gold); color: var(--gold);
    box-shadow: 0 0 14px rgba(245, 184, 61, .2);
}

.piece-tray {
    display: flex; gap: 8px; align-items: center; justify-content: center;
    min-height: 74px; margin: 4px; padding: 6px;
    background: rgba(0, 0, 0, .22); border: 1px dashed rgba(232, 228, 216, .18);
    border-radius: 12px; flex-wrap: wrap;
}
.tray-piece {
    position: relative; cursor: grab; transition: transform .15s, filter .15s;
    touch-action: none;
}
.tray-piece.placed { opacity: .28; filter: grayscale(.8); }
.tray-piece:active { transform: scale(1.08); }
.tray-piece svg { display: block; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .5)); }
.tray-hint { font-size: 12px; color: var(--chalk-dim); width: 100%; text-align: center; }

.game-actions { display: flex; gap: 8px; margin: 6px 4px 2px; }

/* ==================== buttons ==================== */
.btn {
    flex: 1; padding: 13px 10px; border: none; border-radius: 14px;
    font-family: var(--font-head); font-size: 16px; cursor: pointer;
    transition: transform .12s, filter .2s;
}
.btn:active { transform: translateY(2px) scale(.98); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn-gold {
    color: #1a1206;
    background: linear-gradient(180deg, #ffd76e, #f5a623);
    box-shadow: 0 5px 0 var(--gold-deep), 0 8px 18px rgba(0, 0, 0, .4);
}
.btn-gold:active { box-shadow: 0 2px 0 var(--gold-deep); }
.btn-cyan {
    color: #04222b;
    background: linear-gradient(180deg, #8deeff, #38c4e8);
    box-shadow: 0 5px 0 #17708c, 0 8px 18px rgba(0, 0, 0, .4);
}
.btn-cyan:active { box-shadow: 0 2px 0 #17708c; }
.btn-ghost {
    color: var(--chalk); background: rgba(232, 228, 216, .07);
    border: 1px solid var(--panel-line);
}

/* ==================== matching ==================== */
#scr-match { align-items: center; justify-content: center; text-align: center; }
.match-box { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; }
.match-box h2 { font-family: var(--font-head); font-size: 20px; }
.match-box p { color: var(--chalk-dim); font-size: 14px; min-height: 20px; }
.radar { position: relative; width: 110px; height: 110px; }
.radar i {
    position: absolute; inset: 0; border-radius: 50%;
    border: 2px solid var(--cyan); opacity: 0;
    animation: radar 2.2s ease-out infinite;
}
.radar i:nth-child(2) { animation-delay: .7s; }
.radar i:nth-child(3) { animation-delay: 1.4s; }
@keyframes radar {
    0% { transform: scale(.25); opacity: .9; }
    100% { transform: scale(1.15); opacity: 0; }
}
.room-code-box {
    display: flex; flex-direction: column; gap: 10px; align-items: center;
    padding: 18px 26px; border-radius: 18px;
    background: var(--panel); border: 1px solid var(--panel-line);
}
.room-code-box label { font-size: 12px; color: var(--chalk-dim); }
.room-code-box b {
    font-family: var(--font-display); font-size: 32px; letter-spacing: 8px; color: var(--cyan);
    text-shadow: 0 0 20px rgba(89, 227, 255, .5);
}
#btn-cancel-match, #btn-share-room { flex: none; padding: 12px 30px; }

/* ==================== friend ==================== */
.friend-box { display: flex; flex-direction: column; gap: 16px; }
.join-row { display: flex; gap: 10px; }
.join-row input {
    flex: 1; min-width: 0; padding: 13px 16px; border-radius: 14px;
    background: rgba(0, 0, 0, .3); border: 1px solid var(--panel-line);
    color: var(--cyan); font-family: var(--font-display); font-size: 20px; letter-spacing: 5px;
    text-transform: uppercase; text-align: center; outline: none;
}
.join-row input:focus { border-color: var(--cyan); }
.join-row .btn { flex: none; padding-left: 22px; padding-right: 22px; }

/* ==================== ranking ==================== */
.seg { display: flex; gap: 6px; margin-bottom: 8px; }
.seg button {
    flex: 1; padding: 10px 4px; border-radius: 10px;
    background: rgba(232, 228, 216, .05); border: 1px solid var(--panel-line);
    color: var(--chalk-dim); font-family: var(--font-head); font-size: 13.5px; cursor: pointer;
}
.seg-sm button { padding: 7px 4px; font-size: 12px; }
.seg button.active { background: rgba(245, 184, 61, .14); border-color: var(--gold); color: var(--gold); }

.rank-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.rank-row {
    display: grid; grid-template-columns: 44px 1fr auto auto; gap: 8px; align-items: center;
    padding: 11px 14px; border-radius: 12px;
    background: var(--panel); border: 1px solid var(--panel-line);
    animation: scr-in .3s both;
}
.rank-row.top1 { border-color: var(--gold); box-shadow: 0 0 16px rgba(245, 184, 61, .2); }
.rank-row.top2 { border-color: rgba(200, 208, 220, .6); }
.rank-row.top3 { border-color: rgba(205, 127, 50, .6); }
.rank-row.me { outline: 2px solid var(--cyan); }
.rank-no { font-family: var(--font-display); font-size: 16px; color: var(--chalk-dim); text-align: center; }
.top1 .rank-no { color: var(--gold); } .top2 .rank-no { color: #c8d0dc; } .top3 .rank-no { color: #cd7f32; }
.rank-name { font-family: var(--font-head); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-total { font-family: var(--font-display); font-size: 16px; color: var(--gold); }
.rank-games { font-size: 11px; color: var(--chalk-dim); }
.rank-empty { text-align: center; padding: 40px 0; color: var(--chalk-dim); }

/* ==================== how to ==================== */
.howto-body { line-height: 1.75; font-size: 14.5px; padding-bottom: 30px; }
.howto-body h3 {
    font-family: var(--font-head); color: var(--gold); font-size: 17px;
    margin: 26px 0 8px; padding-left: 10px; border-left: 3px solid var(--gold);
}
.howto-body p { margin-bottom: 8px; color: rgba(232, 228, 216, .85); }
.howto-body .ht-fig {
    margin: 12px 0; padding: 12px; border-radius: 12px;
    background: rgba(0, 0, 0, .25); border: 1px solid var(--panel-line);
    text-align: center;
}
.howto-body .ht-fig svg { max-width: 100%; height: auto; }
.color-table { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.color-chip {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px;
    background: rgba(0, 0, 0, .25); border-radius: 10px; font-size: 12.5px;
    border: 1px solid var(--panel-line);
}
.color-chip i { width: 16px; height: 16px; border-radius: 50%; flex: none; box-shadow: 0 0 8px currentColor; }

/* ==================== modals ==================== */
.modal-back {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(4, 8, 16, .75); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; padding: 22px;
    animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.modal {
    width: 100%; max-width: 360px;
    background: linear-gradient(180deg, #1a2947, #131f36);
    border: 1px solid rgba(245, 184, 61, .35); border-radius: 20px;
    padding: 24px 22px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .6), 0 0 40px rgba(245, 184, 61, .08);
    animation: pop-in .3s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop-in { from { transform: scale(.85); opacity: 0; } }
.modal h3 { font-family: var(--font-head); font-size: 19px; margin-bottom: 14px; color: var(--gold); }
.modal label { display: block; font-size: 12.5px; color: var(--chalk-dim); margin: 10px 0 5px; }
.modal input {
    width: 100%; padding: 12px 14px; border-radius: 12px;
    background: rgba(0, 0, 0, .3); border: 1px solid var(--panel-line);
    color: var(--chalk); font-family: var(--font-body); font-size: 15px; outline: none;
}
.modal input:focus { border-color: var(--gold); }
.modal-err { min-height: 18px; font-size: 12.5px; color: var(--danger); margin-top: 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-divider { height: 1px; background: var(--panel-line); margin: 18px 0 4px; }

/* sound settings toggles */
.sound-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 4px; font-family: var(--font-head); font-size: 16px;
    border-bottom: 1px solid var(--panel-line);
}
.toggle {
    width: 54px; height: 30px; border-radius: 30px; border: none; cursor: pointer;
    background: rgba(232, 228, 216, .15); position: relative; transition: background .2s;
}
.toggle i {
    position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
    background: #cfc9bb; transition: left .2s, background .2s;
}
.toggle.on { background: linear-gradient(180deg, #ffd76e, #f5a623); }
.toggle.on i { left: 27px; background: #fff; }

/* color mixing table modal */
.modal-colors #colors-body { max-height: 60vh; overflow-y: auto; }
/* 색 혼합표: 좌(합성색+이름) ← 우(재료색들) */
.ctbl { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 4px; }
.ctbl-row {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
    padding: 8px 12px; background: rgba(0, 0, 0, .25);
    border: 1px solid var(--panel-line); border-radius: 10px;
}
.ctbl-res { display: flex; align-items: center; gap: 8px; font-family: var(--font-head); font-size: 14px; }
.ctbl-arrow { color: var(--chalk-dim); font-size: 15px; }
.ctbl-src { display: flex; align-items: center; gap: 6px; }
.ct-sw {
    width: 20px; height: 20px; border-radius: 50%; flex: none;
    border: 1px solid rgba(232, 228, 216, .35); box-shadow: 0 0 6px rgba(0, 0, 0, .4);
}
.tool-tab.tool-colors { flex: 0 0 42px; font-size: 16px; }

.modal-result { text-align: center; position: relative; overflow: hidden; }
.modal-result h3 { font-size: 26px; font-family: var(--font-display); }
.modal-result h3.win { color: var(--gold); text-shadow: 0 0 24px rgba(245, 184, 61, .6); }
.modal-result h3.lose { color: var(--danger); }
.modal-result p { color: var(--chalk-dim); font-size: 14px; margin-top: 6px; }
.result-stats {
    display: flex; justify-content: center; gap: 26px; margin: 18px 0 6px;
}
.result-stats div { display: flex; flex-direction: column; gap: 2px; }
.result-stats span { font-size: 11.5px; color: var(--chalk-dim); }
.result-stats b { font-family: var(--font-display); font-size: 22px; color: var(--gold); }
.result-burst { position: absolute; inset: 0; pointer-events: none; }
.result-burst i {
    position: absolute; width: 8px; height: 8px; border-radius: 2px;
    transform: rotate(45deg);
    animation: burst 1s ease-out forwards;
}
@keyframes burst {
    from { opacity: 1; transform: translate(0, 0) rotate(45deg); }
    to   { opacity: 0; transform: translate(var(--tx), var(--ty)) rotate(225deg); }
}

/* ==================== toast ==================== */
#toast {
    position: fixed; left: 50%; bottom: calc(30px + var(--safe-bottom));
    transform: translateX(-50%);
    background: rgba(12, 21, 38, .95); color: var(--chalk);
    border: 1px solid var(--gold); border-radius: 30px;
    padding: 11px 22px; font-size: 14px; z-index: 60;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
    animation: toast-in .25s;
    max-width: 86vw; text-align: center;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* small screens */
@media (max-height: 700px) {
    .home-hero { padding-top: 10px; }
    .game-log { height: 64px; }
}

/* ==================== share button (home) ==================== */
.menu-share {
    display: flex; align-items: center; gap: 12px; width: 100%;
    margin-top: 12px; padding: 13px 16px; border: none; cursor: pointer;
    border-radius: 16px; color: #14202f; text-align: left;
    background: linear-gradient(135deg, #ffd76e, #f5b83d);
    box-shadow: 0 6px 18px rgba(245, 184, 61, .35);
}
.menu-share:active { transform: scale(.98); }
.menu-share .ms-ico { font-size: 22px; }
.menu-share .ms-label { flex: 1; font-family: var(--font-display); font-size: 15px; }
.menu-share .ms-badge {
    display: inline-flex; align-items: center; gap: 4px;
    background: rgba(20, 32, 47, .85); color: var(--gold);
    padding: 5px 11px; border-radius: 20px; font-weight: 800; font-size: 13.5px;
}

/* ==================== result: earned gems + draw ==================== */
.result-earn {
    display: inline-flex; align-items: center; gap: 6px; margin: 6px auto 0;
    padding: 6px 16px; border-radius: 22px; font-family: var(--font-display);
    font-size: 20px; color: var(--gold);
    background: rgba(245, 184, 61, .14); border: 1px solid rgba(245, 184, 61, .4);
    animation: earn-pop .5s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes earn-pop { from { opacity: 0; transform: scale(.5); } }
#result-title.draw { color: var(--cyan); }
.result-earn.minus { color: #ff7a6b; background: rgba(224,65,60,.14); border-color: rgba(224,65,60,.4); }
#result-points { font-size: 16px; }

/* ==================== roulette win burst ==================== */
.spin-burst { position: absolute; left: 50%; top: 46%; pointer-events: none; z-index: 5; }
.spin-burst i {
    position: absolute; width: 8px; height: 8px; border-radius: 2px;
    transform: rotate(45deg); animation: burst 1.1s ease-out forwards;
}

/* ==================== reward FX overlay ==================== */
#reward-fx {
    position: fixed; inset: 0; z-index: 90; pointer-events: none;
    display: flex; align-items: center; justify-content: center;
}
#reward-fx.show .rfx-card { animation: rfx-in .5s cubic-bezier(.2, 1.4, .4, 1) both; }
.rfx-burst { position: absolute; left: 50%; top: 50%; }
.rfx-burst i {
    position: absolute; width: 9px; height: 9px; border-radius: 2px;
    transform: rotate(45deg); animation: burst 1.3s ease-out forwards;
}
.rfx-card {
    position: relative; text-align: center;
    background: rgba(12, 21, 38, .96); border: 1px solid var(--gold);
    border-radius: 20px; padding: 20px 30px;
    box-shadow: 0 12px 44px rgba(0, 0, 0, .55);
}
.rfx-gem { font-size: 40px; line-height: 1; }
.rfx-amt { font-family: var(--font-display); font-size: 30px; color: var(--gold); margin-top: 6px; }
.rfx-msg { font-size: 13px; color: var(--chalk); margin-top: 4px; opacity: .9; }
@keyframes rfx-in { from { opacity: 0; transform: scale(.6) translateY(10px); } }
