/* ============================================================
   Math Wizard - 공통 스타일 (모든 화면이 공유)
   디자인 좌표계: #app 1280 x 720 고정, JS가 화면 크기에 맞춰 scale
   ============================================================ */

:root {
  /* 색상 팔레트 */
  --c-bg1: #7ec8f5;
  --c-bg2: #cdeaff;
  --c-panel: #fffaf0;
  --c-panel-border: #eadbb8;
  --c-primary: #ff9f1c;
  --c-primary-dark: #e68a00;
  --c-accent: #7b5cd6;
  --c-accent-soft: #ece5ff;
  --c-good: #3ec96f;
  --c-good-dark: #2ba85a;
  --c-bad: #ff6b6b;
  --c-text: #3a3450;
  --c-text-soft: #7a7590;
  --c-coin: #f7b32b;
  --c-hp: #ff5e7e;
  --c-exp: #58c9f3;

  /* 아이템 등급 색 */
  --r-common: #8d99ae;
  --r-rare: #3f8efc;
  --r-epic: #b04ae2;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 6px 16px rgba(50, 40, 90, 0.18);
  --shadow-sm: 0 3px 8px rgba(50, 40, 90, 0.12);
  --font: 'Jua', 'BM Jua', 'Malgun Gothic', '맑은 고딕', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #4f9fd9;
  font-family: var(--font);
  color: var(--c-text);
  -webkit-user-select: none; user-select: none;
}

input, textarea { -webkit-user-select: text; user-select: text; }

#app-wrap { position: fixed; inset: 0; overflow: hidden; }

#app {
  position: absolute;
  left: 50%; top: 50%;
  width: 1280px; height: 720px;
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg, var(--c-bg1) 0%, var(--c-bg2) 100%);
  border-radius: 0;
  overflow: hidden;
}

/* ===== 화면 시스템 ===== */
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }

/* ===== 버튼 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font);
  font-size: 20px;
  color: #fff;
  background: var(--c-accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 22px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.18);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.12s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.18); }
.btn:disabled { filter: grayscale(0.6) brightness(0.9); cursor: not-allowed; }

.btn-primary { background: linear-gradient(180deg, #ffb547, var(--c-primary)); color: #6b3c00; text-shadow: 0 1px 0 rgba(255,255,255,0.4); }
.btn-good { background: linear-gradient(180deg, #54dd85, var(--c-good)); color: #0c4d26; }
.btn-blue { background: linear-gradient(180deg, #6cb8ff, #3f8efc); }
.btn-ghost { background: #fff; color: var(--c-text); border: 2px solid #ddd3c0; box-shadow: 0 3px 0 rgba(0,0,0,0.08); }
.btn-big { font-size: 26px; padding: 14px 34px; border-radius: 14px; }
.btn-small { font-size: 16px; padding: 6px 14px; }

/* ===== 패널 ===== */
.panel {
  background: var(--c-panel);
  border: 3px solid var(--c-panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-title {
  font-size: 20px;
  color: var(--c-text);
  padding: 10px 14px 6px;
  display: flex; align-items: center; gap: 6px;
}

/* ===== 게이지 바 (HP / EXP) ===== */
.meter {
  position: relative;
  height: 18px;
  background: #e8e2d4;
  border-radius: 9px;
  overflow: hidden;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.12);
}
.meter > .meter-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  border-radius: 9px;
  transition: width 0.35s ease;
}
.meter-hp > .meter-fill { background: linear-gradient(180deg, #ff8ba3, var(--c-hp)); }
.meter-exp > .meter-fill { background: linear-gradient(180deg, #8edcff, var(--c-exp)); }
.meter > .meter-label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.45);
}

/* ===== 코인 칩 ===== */
.coin-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: #fff6dd;
  border: 2px solid #f2d98c;
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 18px;
  color: #8a6100;
}

/* ===== 배지 ===== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  color: #fff;
}
.badge-clear { background: var(--c-good); }
.badge-lock { background: #a8a4b8; }
.badge-ready { background: var(--c-exp); }

/* ===== 아이템 카드 (MW.UI.itemCardHTML 이 생성) ===== */
.item-card {
  position: relative;
  width: 132px;
  background: #fff;
  border: 3px solid var(--r-common);
  border-radius: 14px;
  padding: 10px 8px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.1s;
}
.item-card:hover { transform: translateY(-3px); }
.item-card .item-emoji { font-size: 40px; line-height: 1.1; }
.item-card .item-name { font-size: 15px; margin-top: 4px; }
.item-card .item-rarity { font-size: 12px; margin-top: 2px; }
.item-card .item-stats { font-size: 13px; color: var(--c-good-dark); margin-top: 3px; line-height: 1.25; }
.item-card .item-count {
  position: absolute; right: -6px; top: -6px;
  background: var(--c-text); color: #fff;
  font-size: 12px; border-radius: 999px; padding: 2px 8px;
}
.item-card .item-equipped {
  position: absolute; left: -6px; top: -6px;
  background: var(--c-good); color: #fff;
  font-size: 11px; border-radius: 999px; padding: 2px 8px;
}
.item-card.rarity-common { border-color: var(--r-common); }
.item-card.rarity-rare   { border-color: var(--r-rare); box-shadow: 0 0 10px rgba(63,142,252,0.35); }
.item-card.rarity-epic   { border-color: var(--r-epic); box-shadow: 0 0 14px rgba(176,74,226,0.45); }
.item-card.rarity-common .item-rarity { color: var(--r-common); }
.item-card.rarity-rare   .item-rarity { color: var(--r-rare); }
.item-card.rarity-epic   .item-rarity { color: var(--r-epic); }

/* ===== 토스트 ===== */
#toast-root {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  z-index: 9000;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(48, 40, 74, 0.92);
  color: #fff;
  font-size: 18px;
  border-radius: 999px;
  padding: 10px 24px;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease, toast-out 0.3s ease 2.2s forwards;
  white-space: nowrap;
}
.toast.toast-good { background: rgba(46, 160, 92, 0.95); }
.toast.toast-bad  { background: rgba(214, 84, 84, 0.95); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.9); } to { opacity: 1; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }

/* ===== 공용 애니메이션 ===== */
@keyframes mw-pop { 0% { transform: scale(0.3); opacity: 0; } 70% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
@keyframes mw-shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }
@keyframes mw-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes mw-float-up { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-46px); } }
@keyframes mw-sparkle { 0% { transform: scale(0) rotate(0deg); opacity: 1; } 100% { transform: scale(1.4) rotate(180deg); opacity: 0; } }
@keyframes mw-fall {
  0% { transform: translateY(-30px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(760px) rotate(540deg); opacity: 0.6; }
}
.anim-pop { animation: mw-pop 0.35s ease; }
.anim-shake { animation: mw-shake 0.4s ease; }

/* MW.UI.burstEmoji 가 만드는 입자 */
.mw-burst-particle {
  position: absolute;
  pointer-events: none;
  z-index: 8000;
  transition: transform 0.8s cubic-bezier(0.15, 0.6, 0.4, 1), opacity 0.8s ease;
}
.mw-confetti {
  position: absolute;
  top: -20px;
  width: 12px; height: 18px;
  border-radius: 3px;
  pointer-events: none;
  z-index: 8000;
  animation: mw-fall 2.4s ease-in forwards;
}

/* ============================================================
   로그인 화면
   ============================================================ */
#screen-login {
  background:
    radial-gradient(circle at 18% 22%, rgba(255,255,255,0.5) 0 3px, transparent 4px),
    radial-gradient(circle at 82% 14%, rgba(255,255,255,0.6) 0 2px, transparent 3px),
    radial-gradient(circle at 64% 30%, rgba(255,255,255,0.5) 0 2px, transparent 3px),
    linear-gradient(180deg, #6db6ec 0%, #a5d8ff 55%, #c0f0c8 100%);
}
.login-deco { position: absolute; font-size: 40px; opacity: 0.85; animation: mw-bob 3s ease-in-out infinite; }
.login-deco-1 { left: 8%; top: 12%; }
.login-deco-2 { right: 10%; top: 18%; font-size: 30px; animation-delay: 0.7s; }
.login-deco-3 { right: 16%; bottom: 16%; animation-delay: 1.2s; }
.login-deco-4 { left: 13%; bottom: 22%; font-size: 26px; animation-delay: 0.4s; }

.login-card {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 560px;
  background: var(--c-panel);
  border: 4px solid var(--c-panel-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 22px 38px 18px;
  text-align: center;
}
.login-wizard { font-size: 58px; line-height: 1; animation: mw-bob 2.6s ease-in-out infinite; }
.login-title {
  font-size: 46px;
  background: linear-gradient(180deg, #7b5cd6, #4a3aa8);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 1px;
}
.login-subtitle { font-size: 17px; color: var(--c-text-soft); margin: 2px 0 14px; }

.login-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.login-row { text-align: left; }
.login-row label { display: block; font-size: 15px; color: var(--c-text-soft); margin-bottom: 3px; }
.login-row input {
  width: 100%;
  font-family: var(--font);
  font-size: 19px;
  padding: 9px 12px;
  border: 3px solid #e3d9c2;
  border-radius: 12px;
  background: #fff;
  color: var(--c-text);
  outline: none;
  transition: border-color 0.15s;
}
.login-row input:focus { border-color: var(--c-primary); }

.login-error {
  margin-top: 10px;
  background: #ffe9e9;
  border: 2px solid #ffc2c2;
  color: #c0392b;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 16px;
}
.login-btn { width: 100%; margin-top: 14px; }
.login-hint {
  margin-top: 12px;
  background: var(--c-accent-soft);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 14px;
  color: #5a4d91;
  line-height: 1.5;
}
.login-teacher-link {
  display: inline-block;
  margin-top: 9px;
  font-size: 14px;
  color: var(--c-text-soft);
  text-decoration: none;
}
.login-teacher-link:hover { color: var(--c-accent); text-decoration: underline; }

/* ===== 테스트 모드 (선생님 도구의 스테이지 테스트) ===== */
.tm-banner {
  position: absolute;
  top: 68px; left: 50%;
  transform: translateX(-50%);
  z-index: 8500;
  background: rgba(122, 62, 210, 0.92);
  color: #fff;
  font-size: 14px;
  border-radius: 999px;
  padding: 5px 16px;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  white-space: nowrap;
}
.tm-end {
  position: absolute; inset: 0;
  z-index: 8600;
  background: rgba(43, 34, 80, 0.55);
  display: flex; align-items: center; justify-content: center;
}
.tm-end-card {
  width: 520px; max-width: 92%;
  padding: 26px 30px 24px;
  text-align: center;
  animation: mw-pop 0.35s ease;
}
.tm-end-title { font-size: 40px; }
.tm-end-stats {
  margin: 14px auto 0;
  max-width: 400px;
  background: #fff;
  border: 2px solid #eee3c8;
  border-radius: 14px;
  padding: 10px 16px;
  font-size: 19px;
  display: flex; flex-direction: column; gap: 4px;
}
.tm-end-note { margin-top: 12px; font-size: 15px; color: var(--c-text-soft); line-height: 1.6; }
.tm-end-btns { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

/* ===== 부팅 에러 ===== */
#boot-error {
  position: fixed; inset: 0;
  background: #5a8fc4;
  display: flex; align-items: center; justify-content: center;
  z-index: 99999;
  font-family: var(--font);
}
#boot-error[hidden] { display: none; }
.boot-error-box {
  background: #fff; border-radius: 20px; padding: 40px 60px;
  text-align: center; color: var(--c-text);
}
.boot-error-box h2 { margin: 10px 0; }
.boot-error-box p { color: var(--c-text-soft); line-height: 1.6; }

/* ============================================================
   세로 모드 (720x1280) — body.mw-portrait
   #app 의 크기 전환은 main.js 가 담당 (여기는 화면별 미세 조정만)
   ============================================================ */
body.mw-portrait .login-card { width: 600px; max-width: calc(100% - 40px); }
body.mw-portrait .login-grid { grid-template-columns: 1fr; gap: 8px; }
body.mw-portrait .login-title { font-size: 40px; }
body.mw-portrait .login-wizard { font-size: 50px; }
body.mw-portrait .login-row input { font-size: 20px; padding: 11px 12px; }
