/* ==========================================
 * 수신킹 - DESIGN SYSTEM (King / God of Math theme)
 * ========================================== */
:root {
  --primary: #F59E0B;
  --primary-hover: #D97706;
  --primary-light: #FEF3C7;
  --royal: #4C1D95;
  --royal-deep: #1E1035;

  --success: #10B981;
  --danger: #EF4444;
  --warning: #F59E0B;

  --bg-gradient: linear-gradient(160deg, #1E1035 0%, #2E1065 55%, #4C1D95 100%);
  --surface-bg: rgba(255, 255, 255, 0.97);
  --surface-card: #FFFFFF;

  --text-main: #0F172A;
  --text-muted: #64748B;
  --text-inverse: #FFFFFF;

  --border-color: #E5E7EB;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px -5px rgba(245, 158, 11, 0.4);

  --font-main: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
  --font-accent: 'Fredoka', sans-serif;

  /* 실제로 보이는 화면 높이. 자판이 올라오면 app.js가 줄어든 높이로 바꿔준다. */
  --app-height: 100vh;
}

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

body {
  font-family: var(--font-main);
  background: var(--royal-deep);
  color: var(--text-main);
  min-height: var(--app-height);
  display: flex;
  justify-content: center;
  align-items: center;
}

.mobile-wrapper {
  width: 100%;
  max-width: 480px;
  min-height: var(--app-height);
  background: var(--surface-bg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(0,0,0,0.5);
  position: relative;
  overflow: hidden;
}

/* 폰에서는 앱 전체를 "보이는 높이"에 딱 맞춘다.
   자판이 올라오면 --app-height가 그만큼 줄어들어, 화면이 자판 뒤로 밀려나지 않는다. */
@media (max-width: 480px) {
  html, body { height: var(--app-height); overflow: hidden; }
  .mobile-wrapper { height: var(--app-height); min-height: 0; }
}

@media (min-width: 481px) {
  .mobile-wrapper { min-height: 92vh; height: 92vh; border-radius: 28px; margin: 20px 0; }
}

/* Header */
.app-header {
  height: 54px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--royal-deep);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand { display: flex; align-items: center; gap: 8px; cursor: pointer; transition: opacity 0.15s ease; }
.brand:hover, .brand:active { opacity: 0.7; }
.brand-crown { color: var(--primary); font-size: 18px; }
.brand-title {
  font-family: var(--font-accent);
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  letter-spacing: 0.5px;
}

.user-profile-bar { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

.btn-switch-app {
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.12); color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 4px 10px; font-size: 11px; font-weight: 700;
  border-radius: var(--radius-full); text-decoration: none;
  white-space: nowrap; transition: all 0.2s ease;
}
.btn-switch-app:hover { background: var(--primary); color: #1E1035; border-color: var(--primary); }

.user-tag {
  font-size: 11px; font-weight: 700; color: var(--primary);
  background: rgba(245,158,11,0.15); padding: 3px 8px;
  border-radius: var(--radius-full); white-space: nowrap;
}

.btn-icon {
  width: 28px; height: 28px; border-radius: var(--radius-full); border: none;
  background: rgba(255,255,255,0.12); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 12px;
}
.btn-icon:hover { background: rgba(255,255,255,0.25); }

.btn-header-login {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: #1E1035;
  border: none; padding: 4px 12px; font-size: 11px; font-weight: 800;
  border-radius: var(--radius-full); cursor: pointer; white-space: nowrap;
}
.btn-header-login:hover { background: var(--primary-hover); }

/* Main / view toggling */
.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 32px;
  background: var(--surface-bg);
}

.view-section { display: none; }
.view-section.active { display: block; animation: fadeIn 0.25s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Intro hero */
.intro-hero {
  text-align: center;
  background: var(--bg-gradient);
  border-radius: var(--radius-lg);
  padding: 32px 20px 28px;
  color: #fff;
  box-shadow: var(--shadow-lg);
}

.intro-crown { font-size: 40px; color: var(--primary); margin-bottom: 8px; text-shadow: 0 0 20px rgba(245,158,11,0.6); }
.intro-hero h1 { font-family: var(--font-accent); font-size: 26px; margin-bottom: 2px; }
.intro-hero h2 { font-size: 16px; font-weight: 600; opacity: 0.9; margin-bottom: 10px; }
.intro-sub { font-size: 13px; opacity: 0.85; margin-bottom: 20px; line-height: 1.5; }
.text-highlight {
  color: #FDE68A;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.btn-challenge {
  width: 100%;
  padding: 16px;
  font-size: 17px;
  font-weight: 800;
  color: #1E1035;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-full);
  box-shadow: 0 8px 20px rgba(245,158,11,0.45);
  cursor: pointer;
  transition: transform 0.15s ease;
}
.btn-challenge:active { transform: scale(0.97); }

/* 로그인한 회원은 버튼 색을 다르게 표시해 비회원과 구분한다 */
.btn-challenge.member {
  background: linear-gradient(135deg, var(--royal) 0%, #6D28D9 100%);
  color: #FDE68A;
  border: 2px solid var(--primary);
  box-shadow: 0 8px 20px rgba(76, 29, 149, 0.55);
}

/* Leaderboard / 명예의 전당 */
.board-section { margin-top: 24px; }
.board-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.board-title i { color: var(--primary); }
.board-sub { font-size: 11px; font-weight: 500; color: var(--text-muted); margin-left: auto; }

.board-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; padding-right: 2px; }
.board-loading { text-align: center; padding: 20px; color: var(--text-muted); font-size: 13px; }

.board-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: #F8FAFC;
  border: 1px solid var(--border-color);
}
.board-row.top-stage { background: var(--primary-light); border-color: #FCD34D; }

.board-row-top { display: flex; align-items: center; gap: 8px; }

.board-stage-badge {
  min-width: 46px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  background: var(--royal);
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.board-row.top-stage .board-stage-badge { background: var(--primary); color: #1E1035; }
.board-stage-badge.god-badge {
  min-width: auto;
  font-size: 13px;
  letter-spacing: 0.2px;
  background: linear-gradient(135deg, #FFD700, #FFA500);
  color: #1E1035;
  box-shadow: 0 0 0 1px #FCD34D, 0 2px 6px rgba(255, 165, 0, 0.5);
  padding: 4px 10px;
}
.board-stage-badge.god-badge i { margin-right: 2px; }

.board-example {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  background: #fff;
  border: 1px solid var(--border-color);
  padding: 2px 9px;
  border-radius: var(--radius-sm);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-names { display: flex; flex-wrap: wrap; gap: 5px; flex: 1; min-width: 0; }
.board-name-chip {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-main);
  background: #fff;
  border: 1px solid var(--border-color);
  padding: 3px 8px;
  border-radius: var(--radius-full);
}
.board-name-chip.member {
  color: #92400E;
  background: var(--primary-light);
  border: 1px solid #FCD34D;
  display: inline-flex; align-items: center; gap: 4px;
}
.board-name-chip.member i { font-size: 9px; color: var(--primary-hover); }
.board-empty-text { font-size: 12px; color: var(--text-muted); }

/* Center card (login / nickname / result) */
.center-card {
  margin-top: 20px;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.center-icon {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-hover);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.center-card h3 { font-size: 18px; font-weight: 800; margin-bottom: 6px; }
.center-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; line-height: 1.5; }

.auth-tabs, .role-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #F1F5F9;
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}
.auth-tab, .role-tab {
  padding: 8px;
  border: none;
  background: transparent;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-muted);
  border-radius: 10px;
  cursor: pointer;
}
.auth-tab.active, .role-tab.active {
  background: #fff;
  color: var(--primary-hover);
  box-shadow: var(--shadow-sm);
}

.form-group { margin-bottom: 12px; text-align: left; }
.input-with-icon { position: relative; display: flex; align-items: center; }
.input-with-icon i { position: absolute; left: 14px; color: #94A3B8; font-size: 14px; }
.input-with-icon input {
  width: 100%; height: 46px;
  padding: 0 14px 0 38px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 14px; outline: none; transition: all 0.2s;
}
.input-with-icon input:focus { border-color: var(--primary); }

.nickname-input {
  width: 100%; height: 54px;
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 4px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  transition: all 0.2s;
}
.nickname-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(245,158,11,0.18); }

.error-msg { font-size: 12px; color: var(--danger); min-height: 16px; margin-bottom: 10px; }

.link-hint { font-size: 11px; color: var(--text-muted); margin-top: 8px; line-height: 1.4; }

.btn-primary, .btn-outline, .btn-text {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; cursor: pointer; font-family: var(--font-main);
  transition: all 0.15s ease;
}
.btn-primary {
  width: auto; height: 50px; padding: 0 20px;
  background: var(--primary); color: #1E1035;
  font-size: 16px; font-weight: 800;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.98); }

.btn-outline {
  width: auto; height: 50px; padding: 0 20px;
  background: #fff; color: var(--royal);
  font-size: 15px; font-weight: 700;
  border: 2px solid var(--royal);
  border-radius: var(--radius-md);
}

.btn-text {
  width: 100%; height: 40px; margin-top: 10px;
  background: transparent; color: var(--text-muted);
  font-size: 13px; font-weight: 600;
}
.btn-text:hover { color: var(--text-main); }

.w-100 { width: 100%; }

/* Game screen
   자판이 올라와도 하트/단계/타이머(.game-hud)와 입력칸/확인 버튼(.game-actions)은 항상 보이도록
   높이가 부족할 때는 가운데 문제 영역(.game-body)만 줄어든다. */
#gameSection.active {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.game-hud { flex: 0 0 auto; }
.game-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* 내용이 넘칠 땐 가운데 정렬을 풀어 위쪽이 잘리지 않게 한다 (미지원 브라우저는 위 줄로 동작) */
  justify-content: safe center;
}
.game-body .question-card { margin-bottom: 0; }
.game-actions { flex: 0 0 auto; }

.game-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.hearts-row { display: flex; gap: 6px; }
.hearts-row i { font-size: 22px; color: var(--danger); }
.hearts-row i.empty { color: #E2E8F0; }
.stage-counter {
  font-size: 13px; font-weight: 800; color: #fff;
  background: var(--royal); padding: 6px 12px; border-radius: var(--radius-full);
}

.timer-bar-bg { width: 100%; height: 8px; background: #E2E8F0; border-radius: var(--radius-full); overflow: hidden; margin-bottom: 4px; }
.timer-bar-fill { height: 100%; width: 100%; background: var(--success); border-radius: var(--radius-full); transition: width 0.1s linear, background 0.3s ease; }
.timer-num { text-align: right; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 10px; }

.heart-bonus-badge {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: #FEE2E2; color: #B91C1C; font-size: 12px; font-weight: 800;
  padding: 8px; border-radius: var(--radius-md); margin-bottom: 10px;
  animation: pulseBadge 1s ease-in-out infinite;
}
@keyframes pulseBadge { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

.question-card {
  background: var(--bg-gradient);
  border-radius: var(--radius-lg);
  padding: 36px 16px;
  text-align: center;
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
}
.question-text { font-size: 26px; font-weight: 800; color: #fff; word-break: keep-all; }

.answer-area { display: flex; justify-content: center; margin-bottom: 16px; min-height: 48px; }

.feedback-msg { text-align: center; font-size: 14px; font-weight: 700; min-height: 20px; margin-top: 10px; }
.feedback-msg.correct { color: var(--success); }
.feedback-msg.wrong { color: var(--danger); }

/* Result screen */
.result-card { margin-top: 40px; }
.result-icon {
  width: 72px; height: 72px; margin: 0 auto 16px;
  border-radius: 50%; background: var(--primary-light); color: var(--primary-hover);
  display: flex; align-items: center; justify-content: center; font-size: 32px;
}
.result-icon.god { background: var(--royal); color: var(--primary); }
.result-card h2 { font-size: 22px; font-weight: 800; margin-bottom: 8px; }
.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }

/* ==========================================
 * 게임 시작 카운트다운 (3, 2, 1, 시작!)
 * ========================================== */
.countdown-overlay {
  position: fixed; inset: 0;
  background: var(--royal-deep);
  display: none; align-items: center; justify-content: center;
  z-index: 300;
}
.countdown-num {
  font-family: var(--font-accent);
  font-size: 88px;
  font-weight: 700;
  color: var(--primary);
  text-shadow: 0 0 40px rgba(245, 158, 11, 0.6);
  animation: countdownPop 0.7s ease;
}
@keyframes countdownPop {
  0% { transform: scale(0.3); opacity: 0; }
  55% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ==========================================
 * 모달 (QR코드 공유)
 * ========================================== */
.modal-overlay {
  position: fixed; top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.modal-overlay.active { display: flex; animation: fadeIn 0.2s ease; }

.modal-content {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-close { background: transparent; border: none; font-size: 18px; color: var(--text-muted); cursor: pointer; }
.modal-body { padding: 20px; }

/* ==========================================
 * 답안 입력 UI (math 레벨킹과 동일한 채점 엔진을 그대로 사용하기 위한 스타일)
 * ========================================== */
.native-input {
  flex: 1; min-width: 0; width: 100%; height: 52px;
  padding: 0 14px; font-size: 20px; font-weight: 700;
  border: 2px solid var(--border-color); border-radius: var(--radius-md);
  outline: none; transition: all 0.2s; text-align: center;
}
.native-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(245,158,11,0.18); }

.frac-input-group, .mixed-input-group, .pair-input-group, .ratio-input-group {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
}
.frac-input-group .native-input, .mixed-input-group .native-input { width: 100%; padding: 0 4px; }
.mixed-input-group .whole-input { max-width: 52px; }

.frac-stack, .mixed-frac-stack { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.frac-box { max-width: 60px; height: 42px !important; font-size: 18px; }
.frac-divider { width: 32px; height: 2px; background: var(--text-main); border-radius: 2px; }

.frac-display { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 4px; line-height: 1.15; font-size: 0.72em; }
.frac-display .frac-num { border-bottom: 2px solid currentColor; padding: 0 3px 1px; }
.frac-display .frac-den { padding: 1px 3px 0; }

.pair-input-group .pair-item, .ratio-input-group .ratio-item { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1; }
.pair-input-group .pair-item .native-input, .ratio-input-group .ratio-item .native-input { max-width: none; }
.pair-item-label { font-size: 11px; font-weight: 700; color: var(--text-muted); }
.ratio-colon { font-size: 22px; font-weight: 800; color: var(--text-main); padding: 0 2px; }

.choice-btn-group { display: flex; gap: 8px; flex: 1; }
.choice-btn { flex: 1; height: 52px; border: 2px solid var(--border-color); border-radius: var(--radius-md); background: #fff; font-size: 22px; font-weight: 800; color: var(--text-main); cursor: pointer; transition: all 0.15s ease; }
.choice-btn:hover { border-color: var(--primary); }
.choice-btn.selected { border-color: var(--primary); background: var(--primary-light); color: var(--primary-hover); }

/* Scrollbar polish */
.board-list::-webkit-scrollbar { width: 5px; }
.board-list::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 4px; }

/* ==========================================
 * 자판이 올라온 동안의 조밀 모드
 * 아이폰 SE, 갤럭시 S8처럼 작은 화면에서도 하트/단계/타이머/문제/입력칸이
 * 모두 자판 위에 잘리지 않고 들어가도록 여백과 글자 크기를 줄인다.
 * ========================================== */
body.keyboard-open .app-header { height: 42px; }
body.keyboard-open .brand-title { font-size: 15px; }
body.keyboard-open .app-main { padding: 8px 12px 10px; }

body.keyboard-open .game-top { margin-bottom: 6px; }
body.keyboard-open .hearts-row { gap: 4px; }
body.keyboard-open .hearts-row i { font-size: 17px; }
body.keyboard-open .stage-counter { font-size: 11px; padding: 4px 9px; }
body.keyboard-open .timer-bar-bg { height: 6px; margin-bottom: 2px; }
body.keyboard-open .timer-num { font-size: 11px; margin-bottom: 6px; }

body.keyboard-open .heart-bonus-badge { padding: 5px; font-size: 11px; margin-bottom: 6px; }
body.keyboard-open .question-card { padding: 14px 12px; margin-bottom: 10px; }
body.keyboard-open .question-text { font-size: 21px; }

body.keyboard-open .answer-area { margin-bottom: 8px; min-height: 0; }
body.keyboard-open .native-input { height: 44px; font-size: 18px; }
body.keyboard-open .frac-box { height: 36px !important; font-size: 16px; }
body.keyboard-open .choice-btn { height: 44px; font-size: 19px; }
body.keyboard-open .btn-primary { height: 44px; font-size: 15px; }
body.keyboard-open .feedback-msg { margin-top: 4px; min-height: 17px; font-size: 13px; }
