/* Pixel Party V2 — 공통 바탕 스타일 (Claude-A)
 * 무대: #stage 1280x720 고정, app.js 가 transform: scale 로 화면에 맞춘다(letterbox).
 * 공통 클래스: .px-btn(버튼) .px-panel(패널) .px-res(자원 칸) .px-bar(막대) .px-toast .px-popup
 * 화면별 스타일은 css/screens.css(Claude-B), css/battle.css(Claude-C) 에.
 */
:root {
  --bg: #0b0d14;
  --ink: #f4f1e8;
  --ink-dim: #b9b4a6;
  --ink-dark: #12131c;
  --line: #10121c;
  --panel: #262838;
  --panel-2: #33364a;
  --panel-hi: #4a4e68;
  --gold: #ffcc4d;
  --gold-dark: #b8791a;
  --green: #5bd16a;
  --green-dark: #2a7a3a;
  --red: #e5554f;
  --red-dark: #8c2a2a;
  --blue: #59a8ff;
  --blue-dark: #2a5a9c;
  --exp: #e7a83c;
  --font: "Galmuri11", "DungGeunMo", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  --outline: 0 2px 0 var(--line), 2px 0 0 var(--line), -2px 0 0 var(--line), 0 -2px 0 var(--line),
             2px 2px 0 var(--line), -2px 2px 0 var(--line), 2px -2px 0 var(--line), -2px -2px 0 var(--line);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: var(--bg); color: var(--ink);
  overflow: hidden; overscroll-behavior: none;
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}
img, canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
canvas { display: block; }
[hidden] { display: none !important; }
button { font-family: inherit; }
input { font-family: inherit; user-select: text; -webkit-user-select: text; }

/* ---------- 무대 ---------- */
#viewport { position: fixed; inset: 0; overflow: hidden; background: #000; }
#stage {
  position: absolute; left: 0; top: 0;
  width: 1280px; height: 720px;
  transform-origin: 0 0;
  overflow: hidden;
  background: var(--bg);
  font-size: 20px;
}
#screen-layer, #hud-layer, #popup-layer, #toast-layer { position: absolute; inset: 0; }
/* 층 순서 고정: 화면 안 z-index 가 아무리 커도 HUD·팝업·알림 아래 */
#screen-layer { z-index: 0; isolation: isolate; }
#hud-layer { z-index: 10; }
#popup-layer { z-index: 20; }
#toast-layer { z-index: 30; }
#hud-layer, #toast-layer { pointer-events: none; }
#hud-layer > *, #toast-layer > * { pointer-events: auto; }
#popup-layer:empty { pointer-events: none; }
.screen { position: absolute; inset: 0; overflow: hidden; isolation: isolate; }
.screen-bg { position: absolute; inset: 0; width: 1280px; height: 720px; object-fit: cover; }

/* 글자 테두리(픽셀 게임 느낌) */
.px-outline { text-shadow: var(--outline); }

/* ---------- 버튼 ---------- */
.px-btn {
  --c: var(--panel-2); --c-hi: var(--panel-hi); --c-lo: #1c1e2a;
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 64px; min-height: 64px;
  padding: 0 20px;
  border: 3px solid var(--line);
  background: var(--c);
  color: var(--ink);
  font-size: 22px; font-weight: 700; line-height: 1;
  text-shadow: var(--outline);
  box-shadow: inset 0 4px 0 var(--c-hi), inset 0 -5px 0 var(--c-lo), 0 4px 0 var(--line);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 60ms, filter 60ms;
}
.px-btn:hover { filter: brightness(1.08); }
.px-btn:active, .px-btn.pressed { transform: translateY(3px); box-shadow: inset 0 4px 0 var(--c-hi), inset 0 -2px 0 var(--c-lo), 0 1px 0 var(--line); }
.px-btn:disabled, .px-btn.disabled { filter: grayscale(0.85) brightness(0.7); cursor: default; transform: none; }
.px-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.px-btn.primary { --c: #e8962e; --c-hi: #ffc35a; --c-lo: #9a5414; }
.px-btn.green   { --c: #3f9a4a; --c-hi: #6fd27a; --c-lo: #24592b; }
.px-btn.blue    { --c: #3a6fb8; --c-hi: #6ea4ee; --c-lo: #22437a; }
.px-btn.danger  { --c: #b8423d; --c-hi: #e8726a; --c-lo: #6f2220; }
.px-btn.ghost   { --c: rgba(20,22,32,0.72); --c-hi: rgba(255,255,255,0.08); --c-lo: rgba(0,0,0,0.3); }
.px-btn.sm  { min-height: 64px; min-width: 64px; font-size: 18px; padding: 0 14px; }
.px-btn.big { min-height: 84px; font-size: 30px; padding: 0 30px; }
.px-btn.huge { min-height: 120px; min-width: 220px; font-size: 40px; padding: 0 34px; }
.px-btn.icon-only { padding: 0; width: 64px; }
.px-btn .btn-icon { width: 36px; height: 36px; flex: none; }
.px-btn.big .btn-icon { width: 44px; height: 44px; }
.px-btn.huge .btn-icon { width: 64px; height: 64px; }
.px-btn .btn-cost { display: inline-flex; align-items: center; gap: 2px; font-size: 0.8em; }
.px-btn .btn-cost img { width: 26px; height: 26px; }
.px-btn .btn-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }

/* ---------- 패널 ---------- */
.px-panel {
  position: relative;
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: inset 0 0 0 3px var(--panel-hi), inset 0 6px 0 3px rgba(255,255,255,0.06), 0 5px 0 rgba(0,0,0,0.45);
  padding: 18px;
}
.px-panel.dark { background: rgba(14,15,24,0.82); box-shadow: inset 0 0 0 2px rgba(255,255,255,0.12), 0 4px 0 rgba(0,0,0,0.4); }
.px-panel-title {
  margin: -18px -18px 14px; padding: 10px 18px;
  background: var(--panel-2); border-bottom: 3px solid var(--line);
  font-size: 24px; font-weight: 700; text-shadow: var(--outline);
}

/* ---------- 막대 (HP·경험치) ---------- */
.px-bar { position: relative; height: 16px; background: #14151f; border: 3px solid var(--line); box-shadow: inset 0 2px 0 rgba(0,0,0,0.5); }
.px-bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--exp); box-shadow: inset 0 3px 0 rgba(255,255,255,0.3); transition: width 200ms; }
.px-bar.hp > i { background: var(--green); }
.px-bar.enemy > i { background: var(--red); }
.px-bar > span { position: absolute; inset: -3px 0 0; font-size: 12px; text-align: center; line-height: 16px; text-shadow: var(--outline); }

/* ---------- 자원 줄 ---------- */
.px-resbar { position: absolute; top: 12px; right: 16px; display: flex; align-items: center; gap: 14px; z-index: 20; }
.px-res {
  position: relative; display: flex; align-items: center;
  height: 44px; min-width: 170px; padding: 0 16px 0 46px;
  background: rgba(10,11,18,0.78); border: 3px solid var(--line);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.08);
  font-size: 24px; font-weight: 700; justify-content: flex-end;
  text-shadow: var(--outline);
}
.px-res img { position: absolute; left: -10px; top: 50%; width: 48px; height: 48px; transform: translateY(-50%); }
.px-res .res-sub { font-size: 14px; color: var(--ink-dim); margin-right: 8px; align-self: center; }
.px-res.full .res-val { color: var(--green); }

/* ---------- 별 ---------- */
.px-stars { display: inline-flex; gap: 0; }
.px-stars img { width: 22px; height: 22px; }

/* ---------- 알림(toast) ---------- */
#toast-layer { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 86px; gap: 8px; }
.px-toast {
  padding: 12px 26px; max-width: 900px;
  background: rgba(12,13,22,0.92); border: 3px solid var(--line);
  box-shadow: inset 0 0 0 2px var(--panel-hi), 0 4px 0 rgba(0,0,0,0.5);
  font-size: 22px; font-weight: 700; text-shadow: var(--outline); text-align: center;
  animation: toast-in 160ms ease-out;
}
.px-toast.ok { box-shadow: inset 0 0 0 2px var(--green), 0 4px 0 rgba(0,0,0,0.5); }
.px-toast.error { box-shadow: inset 0 0 0 2px var(--red), 0 4px 0 rgba(0,0,0,0.5); }
.px-toast.out { opacity: 0; transform: translateY(-8px); transition: opacity 200ms, transform 200ms; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

/* ---------- 팝업 ---------- */
.px-popup-dim {
  position: absolute; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  animation: dim-in 120ms ease-out;
}
@keyframes dim-in { from { opacity: 0; } to { opacity: 1; } }
.px-popup { min-width: 520px; max-width: 900px; animation: pop-in 140ms ease-out; }
@keyframes pop-in { from { transform: scale(0.92); } to { transform: none; } }
.px-popup-msg { font-size: 24px; line-height: 1.5; text-align: center; margin: 12px 8px 26px; white-space: pre-line; text-shadow: var(--outline); }
.px-popup-btns { display: flex; justify-content: center; gap: 18px; }
.px-popup-btns .px-btn { min-width: 170px; }

/* ---------- 저장 상태 표시(작게) ---------- */
.px-savestate {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  padding: 4px 12px; font-size: 15px; background: rgba(10,11,18,0.85); border: 2px solid var(--line);
  text-shadow: var(--outline); color: var(--ink-dim); z-index: 30;
}
.px-savestate.fail { color: #ffb0a8; box-shadow: inset 0 0 0 2px var(--red); }

/* ---------- 입력칸 ---------- */
.px-field { display: flex; flex-direction: column; gap: 6px; font-size: 18px; color: var(--ink-dim); }
.px-input {
  height: 56px; padding: 0 14px; font-size: 22px; color: var(--ink);
  background: #14151f; border: 3px solid var(--line); box-shadow: inset 0 3px 0 rgba(0,0,0,0.5), 0 0 0 2px var(--panel-hi);
  outline: none;
}
.px-input:focus { box-shadow: inset 0 3px 0 rgba(0,0,0,0.5), 0 0 0 2px var(--gold); }

/* ---------- 슬라이더 ---------- */
.px-range { -webkit-appearance: none; appearance: none; width: 100%; height: 44px; background: transparent; }
.px-range::-webkit-slider-runnable-track { height: 14px; background: #14151f; border: 3px solid var(--line); }
.px-range::-webkit-slider-thumb { -webkit-appearance: none; width: 34px; height: 40px; margin-top: -16px; background: var(--gold); border: 3px solid var(--line); box-shadow: inset 0 -4px 0 var(--gold-dark); }
.px-range::-moz-range-track { height: 14px; background: #14151f; border: 3px solid var(--line); }
.px-range::-moz-range-thumb { width: 30px; height: 36px; background: var(--gold); border: 3px solid var(--line); border-radius: 0; }

/* ---------- 준비 중 / 불러오는 중 ---------- */
.px-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; }
.px-loading-text { font-size: 28px; text-shadow: var(--outline); }

/* ---------- 세로 폰 안내 ---------- */
#rotate-guide {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; text-align: center;
}
.rotate-box { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 340px; }
.rotate-icon {
  width: 64px; height: 104px; border: 6px solid var(--ink); border-radius: 10px; position: relative;
  animation: rotate-phone 2.2s ease-in-out infinite;
}
.rotate-icon::after { content: ""; position: absolute; left: 50%; bottom: 6px; width: 12px; height: 6px; margin-left: -6px; background: var(--ink); }
@keyframes rotate-phone { 0%, 25% { transform: rotate(0); } 55%, 85% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
.rotate-title { margin: 8px 0 0; font-size: 26px; font-weight: 700; text-shadow: var(--outline); }
.rotate-sub { margin: 0 0 10px; font-size: 16px; color: var(--ink-dim); }
#rotate-guide .px-btn { font-size: 22px; min-height: 64px; }

/* ---------- 마을 (town.js) ---------- */
.town .town-fire { position: absolute; left: 640px; top: 412px; width: 0; height: 0; pointer-events: none; }
.town .town-fire i {
  position: absolute; left: -90px; top: -90px; width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,180,80,0.32), rgba(255,140,40,0.1) 55%, transparent 70%);
  animation: fire-glow 1.6s ease-in-out infinite alternate;
}
@keyframes fire-glow { from { transform: scale(0.94); opacity: 0.8; } to { transform: scale(1.06); opacity: 1; } }
.town .town-mercs { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.town .profile, .town .town-save, .town .town-party, .town .town-adventure, .town .town-hint { z-index: 2; }
.town .merc { pointer-events: auto; position: absolute; display: flex; flex-direction: column; align-items: center; transform: translate(-50%, -100%); cursor: pointer; }
.town .merc-label { display: flex; flex-direction: column; align-items: center; gap: 0; margin-bottom: 4px; pointer-events: none; }
.town .merc-name { font-size: 18px; font-weight: 700; text-shadow: var(--outline); white-space: nowrap; }
.town .merc-name b { color: var(--gold); margin-right: 6px; }
.town .merc-sprite { height: 96px; width: auto; transform-origin: 50% 100%; animation: breathe 2.4s ease-in-out infinite; pointer-events: none; }
.town .merc-shadow { width: 64px; height: 12px; margin-top: -6px; border-radius: 50%; background: rgba(0,0,0,0.35); pointer-events: none; }
@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.025, 0.965); } }

.town .profile { position: absolute; left: 16px; top: 12px; display: flex; gap: 12px; align-items: center; padding: 8px 16px 8px 8px; width: 330px; }
.town .profile-face { width: 76px; height: 76px; background: #1a1c28; border: 3px solid var(--line); box-shadow: inset 0 0 0 2px var(--gold-dark); display: flex; align-items: flex-end; justify-content: center; overflow: hidden; flex: none; }
.town .profile-face img { height: 72px; width: auto; }
.town .profile-info { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.town .profile-nick { font-size: 22px; font-weight: 700; text-shadow: var(--outline); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.town .profile-lv { font-size: 18px; color: var(--ink-dim); text-shadow: var(--outline); }
.town .profile .px-bar { height: 18px; }
.town .profile .px-bar > span { line-height: 18px; }
.town .town-save { position: absolute; left: 16px; top: 120px; }
.town .town-adventure { position: absolute; right: 24px; bottom: 22px; }
.town .town-party { position: absolute; left: 24px; bottom: 22px; }
.town .town-hint { position: absolute; right: 270px; bottom: 60px; font-size: 18px; color: var(--gold); text-shadow: var(--outline); animation: hint-bob 1.2s ease-in-out infinite alternate; pointer-events: none; }
@keyframes hint-bob { from { transform: translateX(0); } to { transform: translateX(10px); } }

/* ---------- 로그인 (login.js) ---------- */
.login .login-dim { position: absolute; inset: 0; background: linear-gradient(rgba(5,6,12,0.35), rgba(5,6,12,0.75)); }
.login .login-logo { position: absolute; left: 40px; width: 600px; top: 50%; transform: translateY(-60%); text-align: center; }
.login .logo-title { font-size: 76px; font-weight: 900; letter-spacing: 2px; color: var(--gold); text-shadow: 0 6px 0 var(--gold-dark), var(--outline), 0 10px 0 var(--line); }
.login .logo-sub { margin-top: 18px; font-size: 22px; text-shadow: var(--outline); }
.login .login-panel { position: absolute; left: 700px; top: 50%; width: 520px; transform: translateY(-50%); display: flex; flex-direction: column; gap: 12px; }
.login .login-tabs { display: flex; gap: 0; margin: -18px -18px 4px; }
.login .login-tabs button { flex: 1; height: 64px; border: 0; border-bottom: 3px solid var(--line); background: #1c1e2a; color: var(--ink-dim); font-size: 22px; font-weight: 700; cursor: pointer; text-shadow: var(--outline); }
.login .login-tabs button + button { border-left: 3px solid var(--line); }
.login .login-tabs button.on { background: var(--panel-2); color: var(--ink); box-shadow: inset 0 -4px 0 var(--gold); }
.login .login-msg { min-height: 26px; margin: 0; font-size: 18px; color: #ffb0a8; text-align: center; text-shadow: var(--outline); }
.login .login-panel .px-btn { width: 100%; }

/* ---------- 설정 (settings.js) ---------- */
.settings .settings-panel { position: absolute; left: 50%; top: 50%; width: 760px; transform: translate(-50%, -50%); }
.settings .set-row { display: flex; align-items: center; gap: 20px; margin: 10px 0 18px; font-size: 24px; text-shadow: var(--outline); }
.settings .set-row > label { width: 150px; flex: none; }
.settings .set-row .set-val { width: 70px; text-align: right; flex: none; }
.settings .set-row .px-btn { flex: none; }
.settings .set-btns { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 26px; }
.settings .set-btns .px-btn { flex: 1 1 200px; }
.settings .set-info { margin-top: 18px; font-size: 16px; color: var(--ink-dim); line-height: 1.5; }
.settings .set-close { position: absolute; right: -3px; top: -3px; }
