/* ============================================================
   BASE — 디자인 토큰 + 리셋 + 공용 컴포넌트 (ui-*)
   컨셉: 모바일 캐주얼 대전 게임(Brawl Stars / Stumble Guys / Party Animals)풍의
         "통통한 카툰 UI" — 선명한 색, 굵은 잉크 외곽선, 눌리는 입체 버튼.
   원칙: 모바일 세로 우선(360px~), 터치 타깃 ≥ 44px, safe-area 대응,
         hover 에 의존하지 않기, 넓은 화면에서는 가운데 정렬된 컬럼/다이얼로그.
   로드 순서: base → lobby → hud → setup → meta  (index.html)
   ============================================================ */
:root {
    /* --- Ink & surfaces --- */
    --ink: #120b33;                 /* 외곽선/그림자용 가장 어두운 색 */
    --bg-0: #1b1248;
    --bg-1: #2a1a6e;
    --bg-2: #4a2bb8;
    --panel: #2c2175;               /* 패널 기본면 (불투명) */
    --panel-2: #3a2d93;             /* 패널 안의 카드/행 */
    --panel-3: #4a3bb0;             /* 카드 hover/선택 */
    --panel-line: rgba(255,255,255,0.12);
    --scrim: rgba(10,6,32,0.72);    /* 오버레이 뒤 어둡게 */

    /* --- Brand palette (면 / 어두운 밑단) --- */
    --yellow: #ffcb3d;  --yellow-d: #e08a00;
    --orange: #ff8a3d;  --orange-d: #d2551a;
    --blue:   #3fa9ff;  --blue-d:   #1a66d9;
    --green:  #3ee08a;  --green-d:  #16a05a;
    --red:    #ff5d62;  --red-d:    #c92f3a;
    --purple: #a274ff;  --purple-d: #6a3ee0;
    --pink:   #ff7ac0;  --pink-d:   #d1438f;
    --gray:   #8f8ab8;  --gray-d:   #5d588a;

    /* --- Text --- */
    --text: #ffffff;
    --text-dim: rgba(255,255,255,0.72);
    --text-faint: rgba(255,255,255,0.45);
    --text-on-bright: #3a2300;      /* 노랑/주황 버튼 위 글자 */

    /* --- Semantic (기존 이름 유지: JS 인라인 스타일/구 코드 호환) --- */
    --c-brand: var(--purple);       --c-brand-light: #c6adff;
    --c-player: var(--blue);        --c-player-light: #8fd0ff;
    --c-enemy: var(--red);          --c-enemy-light: #ff9a9d;
    --c-accent: var(--yellow);      --c-accent-soft: #ffe9a8;
    --c-win: var(--green);          --c-win-dark: var(--green-d);
    --c-lose: var(--red);
    --c-campaign: var(--orange);    --c-campaign-light: var(--yellow);
    --bg-panel: var(--panel);       --bg-card: var(--panel-2);
    --bg-overlay: var(--scrim);
    --border-subtle: var(--panel-line);
    --border-medium: rgba(255,255,255,0.22);

    /* --- Type --- */
    --font-display: ui-rounded, 'SF Pro Rounded', 'Hiragino Maru Gothic ProN', 'Apple SD Gothic Neo',
                    'Noto Sans KR', 'Malgun Gothic', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-body: var(--font-display);
    --fs-xs: 11px;  --fs-sm: 13px;  --fs-md: 15px;  --fs-lg: 18px;
    --fs-xl: 24px;  --fs-2xl: 34px; --fs-display: 52px;

    /* --- Shape --- */
    --r-sm: 10px;  --r-md: 16px;  --r-lg: 24px;  --r-pill: 999px;
    --line: 3px;                     /* 잉크 외곽선 두께 */
    --depth: 5px;                    /* 버튼 밑단 두께 */

    /* --- Elevation --- */
    --shadow-sm: 0 3px 0 rgba(0,0,0,0.25);
    --shadow-md: 0 6px 0 rgba(0,0,0,0.28);
    --shadow-lg: 0 10px 0 rgba(0,0,0,0.3), 0 24px 48px rgba(0,0,0,0.35);
    --text-outline: -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink), 0 4px 0 var(--ink);
    --text-shadow: 0 2px 0 rgba(0,0,0,0.35);

    /* --- Motion --- */
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);

    /* --- Safe area / layout --- */
    --sa-t: env(safe-area-inset-top, 0px);
    --sa-r: env(safe-area-inset-right, 0px);
    --sa-b: env(safe-area-inset-bottom, 0px);
    --sa-l: env(safe-area-inset-left, 0px);
    --gutter: 16px;
    --tap: 48px;                     /* 최소 터치 타깃 */
    --col: 480px;                    /* 넓은 화면에서의 콘텐츠 컬럼 폭 */
}

/* ===== RESET ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
    width: 100%; height: 100vh; height: 100dvh;
    overflow: hidden;
    font-family: var(--font-body);
    font-weight: 700;
    color: var(--text);
    background: #000;
    touch-action: none;
    -webkit-user-select: none; user-select: none;
    -webkit-text-size-adjust: 100%;
}
canvas { display: block; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
input { font: inherit; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ===== 버튼: 눌리는 입체 버튼 =====
   <button class="ui-btn ui-btn--primary">  색은 --btn / --btn-d 두 변수로 바꾼다. */
.ui-btn {
    --btn: var(--blue); --btn-d: var(--blue-d); --btn-text: #fff;
    position: relative;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--tap); padding: 0 20px;
    border: var(--line) solid var(--ink); border-radius: var(--r-md);
    background: linear-gradient(180deg, rgba(255,255,255,0.28) 0%, rgba(255,255,255,0) 46%), var(--btn);
    box-shadow: inset 0 calc(-1 * var(--depth)) 0 var(--btn-d), 0 4px 0 rgba(0,0,0,0.3);
    color: var(--btn-text);
    font-family: var(--font-display); font-size: var(--fs-md); font-weight: 900; letter-spacing: 0.3px;
    text-shadow: var(--text-shadow);
    padding-bottom: var(--depth);
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
}
.ui-btn:active:not(:disabled) {
    transform: translateY(3px);
    box-shadow: inset 0 -2px 0 var(--btn-d), 0 1px 0 rgba(0,0,0,0.3);
}
.ui-btn:disabled, .ui-btn.is-disabled { filter: grayscale(0.85) brightness(0.75); }
.ui-btn--primary { --btn: var(--yellow); --btn-d: var(--yellow-d); --btn-text: var(--text-on-bright); text-shadow: 0 1px 0 rgba(255,255,255,0.45); }
.ui-btn--orange  { --btn: var(--orange); --btn-d: var(--orange-d); }
.ui-btn--green   { --btn: var(--green);  --btn-d: var(--green-d); --btn-text: #06331c; text-shadow: 0 1px 0 rgba(255,255,255,0.4); }
.ui-btn--red     { --btn: var(--red);    --btn-d: var(--red-d); }
.ui-btn--purple  { --btn: var(--purple); --btn-d: var(--purple-d); }
.ui-btn--ghost   { --btn: var(--panel-2); --btn-d: #241a63; }
.ui-btn--lg { min-height: 64px; font-size: var(--fs-xl); border-radius: var(--r-lg); --depth: 7px; padding-left: 28px; padding-right: 28px; }
.ui-btn--sm { min-height: 38px; font-size: var(--fs-sm); padding-left: 14px; padding-right: 14px; border-radius: var(--r-sm); --depth: 4px; }
.ui-btn--block { display: flex; width: 100%; }
.ui-btn--icon { width: var(--tap); padding-left: 0; padding-right: 0; font-size: 22px; }

/* ===== 오버레이 + 시트 =====
   좁은 화면: 아래에서 올라오는 바텀시트 / 넓은 화면: 가운데 다이얼로그.
   <div class="ui-overlay"><div class="ui-sheet"><header class="ui-sheet__head">…<div class="ui-sheet__body"> */
.ui-overlay {
    position: fixed; inset: 0;
    display: flex; align-items: flex-end; justify-content: center;
    background: var(--scrim);
    -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.ui-sheet {
    display: flex; flex-direction: column;
    width: 100%; max-width: var(--col); max-height: calc(100dvh - var(--sa-t) - 24px);
    border: var(--line) solid var(--ink); border-bottom: 0;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    background: var(--panel);
    box-shadow: 0 -8px 40px rgba(0,0,0,0.45);
    padding-bottom: var(--sa-b);
    animation: ui-sheet-up 0.28s var(--ease-out) both;
    overflow: hidden;
}
.ui-sheet__head {
    flex: none; display: flex; align-items: center; gap: 10px;
    min-height: 60px; padding: 8px 10px 8px 18px;
    background: linear-gradient(180deg, var(--bg-2), #3a22a0);
    border-bottom: var(--line) solid var(--ink);
}
.ui-sheet__title { flex: 1; font-size: var(--fs-lg); font-weight: 900; text-shadow: var(--text-shadow); }
.ui-sheet__body {
    flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch; touch-action: pan-y;
    padding: var(--gutter);
}
.ui-close {
    flex: none; width: 44px; height: 44px; border-radius: 14px;
    border: var(--line) solid var(--ink); background: var(--red);
    box-shadow: inset 0 -4px 0 var(--red-d);
    color: #fff; font-size: 20px; font-weight: 900; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center; padding-bottom: 3px;
}
.ui-close:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 var(--red-d); }
@keyframes ui-sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes ui-pop { from { transform: scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) and (min-height: 560px) {
    .ui-overlay { align-items: center; padding: 24px; }
    .ui-sheet {
        border-bottom: var(--line) solid var(--ink); border-radius: var(--r-lg);
        max-height: min(720px, calc(100dvh - 48px)); padding-bottom: 0;
        box-shadow: var(--shadow-lg);
        animation-name: ui-pop;
    }
}

/* ===== 카드 / 행 ===== */
.ui-card {
    border: var(--line) solid var(--ink); border-radius: var(--r-md);
    background: var(--panel-2);
    box-shadow: inset 0 2px 0 rgba(255,255,255,0.1), 0 4px 0 rgba(0,0,0,0.25);
}

/* ===== 재화/정보 알약 ===== */
.ui-pill {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 34px; padding: 0 14px 0 8px;
    border: 2px solid var(--ink); border-radius: var(--r-pill);
    background: rgba(18,11,51,0.7);
    font-size: var(--fs-md); font-weight: 900; font-variant-numeric: tabular-nums;
}

/* ===== 진행 바 ===== */
.ui-progress {
    height: 14px; border-radius: var(--r-pill);
    border: 2px solid var(--ink); background: rgba(18,11,51,0.75); overflow: hidden;
}
.ui-progress > * , .ui-progress__fill {
    display: block; height: 100%; border-radius: inherit;
    background: linear-gradient(180deg, rgba(255,255,255,0.45), rgba(255,255,255,0) 55%), var(--green);
    transition: width 0.4s var(--ease-out);
}

/* ===== 알림 점 / 뱃지 ===== */
.ui-dot {
    position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 4px;
    border: 2px solid var(--ink); border-radius: var(--r-pill); background: var(--red);
    color: #fff; font-size: 10px; font-weight: 900; line-height: 14px; text-align: center;
}

/* ===== 제목 글자 (굵은 외곽선) ===== */
.ui-title { font-family: var(--font-display); font-weight: 900; color: #fff; text-shadow: var(--text-outline); letter-spacing: 0.5px; }

/* ===== 탭 ===== */
.ui-tabs { display: flex; gap: 6px; padding: 4px; border-radius: var(--r-md); background: rgba(18,11,51,0.6); border: 2px solid var(--ink); }
.ui-tab { flex: 1; min-height: 40px; border-radius: 12px; color: var(--text-dim); font-weight: 900; font-size: var(--fs-sm); }
.ui-tab.active, .ui-tab.is-active { background: var(--yellow); color: var(--text-on-bright); box-shadow: inset 0 -3px 0 var(--yellow-d); }

/* ===== 공용 등장 애니메이션 (JS 가 클래스만 토글) ===== */
.stagger-hidden { opacity: 0; transform: translateY(12px); }
.stagger-show { opacity: 1; transform: none; transition: opacity 0.35s ease, transform 0.35s var(--ease-bounce); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
.overlay-exit { animation: fadeOut 0.3s ease-out forwards; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* 스태거로 등장하는 버튼도 눌림 반응은 즉각적으로 */
.ui-btn.stagger-show { transition: opacity 0.35s ease, transform 0.08s ease, box-shadow 0.08s ease; }
/* body 가 user-select:none 이므로 입력창은 명시적으로 허용 */
input, textarea { -webkit-user-select: text; user-select: text; touch-action: manipulation; }
