@font-face {
  font-family: 'Pretendard';
  src: url('fonts/pretendard.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #8fd8ff;
  --surface: #fffdf6;
  --surface-2: #fff3cf;
  --text: #2a3d52;
  --text-muted: #5b6f84;
  --brand: #ff8a3d;
  --brand-hover: #f97a28;
  --brand-active: #e96a18;
  --on-brand: #fffdf6;
  --brand-disabled: #e5d9c4;
  --on-disabled: #7f7361;
  --gold: #ffc53d;
  --gold-deep: #d98a00;
  --silver: #c5ced8;
  --silver-deep: #8794a3;
  --bronze: #e0a06a;
  --bronze-deep: #a8652f;
  --danger: #e5484d;
  --hud-bg: rgba(255, 253, 246, 0.96);
  --scrim: rgba(36, 62, 92, 0.32);
  --focus: #2467d6;
  --shadow: 0 1px 2px rgba(36, 62, 92, 0.1), 0 8px 24px rgba(36, 62, 92, 0.16);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Pretendard', system-ui, -apple-system, 'Segoe UI', sans-serif;
  word-break: keep-all;
  overflow-wrap: break-word;
  line-height: 1.6;
  letter-spacing: -0.01em;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#stage { position: fixed; inset: 0; touch-action: none; }
#stage canvas { display: block; width: 100%; height: 100%; }

#hud {
  position: fixed;
  inset: 0 0 auto 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) calc(env(safe-area-inset-right, 0px) + 16px) 0 calc(env(safe-area-inset-left, 0px) + 16px);
  pointer-events: none;
}
.hud-left { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.hud-center { text-align: center; }
.hud-right { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }

#hearts { display: flex; gap: 4px; }
#hearts svg { display: block; width: 24px; height: 24px; color: var(--danger); filter: drop-shadow(0 1px 1px rgba(36, 62, 92, 0.3)); }
#hearts svg.gone { color: var(--hud-bg); opacity: 0.7; }
#hearts svg.lost { animation: heart-out 320ms var(--ease); }
@keyframes heart-out { from { transform: scale(1.5); } to { transform: scale(1); } }

#score {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--surface);
  text-shadow: 0 2px 0 rgba(36, 62, 92, 0.55), 0 0 8px rgba(36, 62, 92, 0.45);
  font-variant-numeric: tabular-nums;
}
#combo { font-size: 14px; font-weight: 600; color: var(--surface); text-shadow: 0 1px 0 rgba(36, 62, 92, 0.6), 0 0 6px rgba(36, 62, 92, 0.45); }

#coins {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 12px;
  border-radius: 24px;
  background: var(--hud-bg);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.coin-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--gold); box-shadow: inset 0 0 0 2px var(--gold-deep); }

#buffs { display: flex; flex-wrap: wrap; gap: 4px; }
.buff {
  display: flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 12px;
  background: var(--hud-bg);
  font-size: 12px;
  font-weight: 600;
}

.chip { display: flex; align-items: center; gap: 8px; font-weight: 600; font-variant-numeric: tabular-nums; }

#land-name {
  position: fixed;
  top: 25%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--surface);
  text-shadow: 0 2px 0 rgba(36, 62, 92, 0.4);
  pointer-events: none;
}
#coach {
  position: fixed;
  top: 20%;
  left: 16px;
  right: 16px;
  width: fit-content;
  max-width: calc(100% - 32px);
  margin: 0 auto;
  padding: 12px 24px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  pointer-events: none;
}
#land-name.fade { animation: land-in 2400ms var(--ease) both; }
@keyframes land-in {
  0% { opacity: 0; transform: translateY(8px); }
  12%, 72% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--hud-bg);
  color: var(--text);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 150ms var(--ease), background-color 150ms var(--ease);
}
.icon-btn:hover { background: var(--surface); }
.icon-btn:active { transform: scale(0.94); }

/* 스킬 버튼: 코인이 모일수록 테두리가 차오른다. 화면 오른쪽 점프 영역 위에 떠 있다. */
.skill-btn {
  position: fixed;
  right: calc(env(safe-area-inset-right, 0px) + 24px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  display: grid;
  place-items: center;
  width: 80px;
  height: 80px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--hud-bg);
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  touch-action: none;
  transition: transform 150ms var(--ease), background-color 150ms var(--ease), color 150ms var(--ease);
}
.skill-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--brand) calc(var(--fill) * 360deg), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
}
#skill-name { position: relative; max-width: 64px; }
.skill-btn.ready { background: var(--brand); color: var(--on-brand); }
.skill-btn.ready .skill-ring { background: var(--gold); }
.skill-btn:hover { transform: scale(1.04); }
.skill-btn:active { transform: scale(0.94); }
.skill-btn:disabled { opacity: 0.6; cursor: default; }
.skill-btn.pop { animation: skill-pop 420ms var(--ease); }
@keyframes skill-pop { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
@media (pointer: fine) { .skill-btn { width: 64px; height: 64px; } #skill-name { max-width: 52px; font-size: 11px; } }

/* 메달: 금·은·동 동그라미. 숫자는 옆에 둔다. */
.medal { display: inline-block; flex: none; width: 16px; height: 16px; border-radius: 50%; vertical-align: -3px; }
.medal.gold { background: var(--gold); box-shadow: inset 0 0 0 2px var(--gold-deep); }
.medal.silver { background: var(--silver); box-shadow: inset 0 0 0 2px var(--silver-deep); }
.medal.bronze { background: var(--bronze); box-shadow: inset 0 0 0 2px var(--bronze-deep); }
.medal.off { opacity: 0.3; }
.medal-shelf { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 12px; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.medal-count { display: inline-flex; align-items: center; gap: 4px; }
.medal-week { display: inline-flex; align-items: center; gap: 4px; color: var(--text-muted); font-weight: 500; }
.medal-news { font-size: 14px; font-weight: 600; color: var(--brand-active); text-align: center; }
.rank-info { font-size: 12px; color: var(--text-muted); }
.crown { display: inline-block; width: 16px; height: 16px; margin-right: 4px; color: var(--gold-deep); vertical-align: -2px; }
.rank-row .place { display: inline-flex; align-items: center; gap: 4px; }
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); overflow-x: auto; }
.tabs button { flex: 1 0 auto; min-height: 36px; padding: 4px 12px; border: 0; border-radius: 8px; background: transparent; color: var(--text-muted); font: inherit; font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.award-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; text-align: left; }
.award-list li { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: var(--surface-2); font-size: 14px; }

.settings-account { font-size: 14px; color: var(--text); }
.settings-version { font-size: 12px; color: var(--text-muted); text-align: center; }

.shop-req { font-size: 12px; color: var(--brand-active); }
.shop-row.locked img { filter: grayscale(1); opacity: 0.6; }

.panel-wrap {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: safe center;
  padding: 16px;
  background: var(--scrim);
  overflow-y: auto;
}
.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(100%, 360px);
  padding: 24px;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}
.panel h1 { margin: 0; font-size: 32px; line-height: 1.2; letter-spacing: -0.03em; }
.panel h2 { margin: 0; font-size: 20px; line-height: 1.3; }
.panel p { margin: 0; }
.sub { color: var(--text-muted); }
.best { font-weight: 600; }
.error { color: var(--danger); font-size: 14px; }

.keys, .result { display: grid; gap: 8px; margin: 0; }
.keys div, .result div { display: flex; justify-content: space-between; gap: 16px; }
.keys dt, .result dt { color: var(--text-muted); font-size: 14px; }
.keys dd, .result dd { margin: 0; font-weight: 600; font-size: 14px; }
.only-touch { display: none; }
@media (pointer: coarse) { .only-touch { display: block; } .only-mouse { display: none; } }

.new-best { color: var(--brand-active); font-weight: 600; }
.result-score { font-size: 32px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }

.btn {
  min-height: 48px;
  padding: 8px 24px;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: var(--on-brand);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 150ms var(--ease), background-color 150ms var(--ease);
}
.btn:hover:not(:disabled) { background: var(--brand-hover); }
.btn:active:not(:disabled) { background: var(--brand-active); transform: scale(0.98); }
.btn:disabled { background: var(--brand-disabled); color: var(--on-disabled); cursor: default; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost:active:not(:disabled) { background: var(--surface-2); }

.account-line, .save-status, .rank-state, .rank-me { font-size: 14px; color: var(--text-muted); text-align: center; }
.save-status.warn { color: var(--danger); }
.rank-me { font-weight: 600; color: var(--text); }
.rank-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; max-height: min(50vh, 400px); overflow-y: auto; }
.rank-list:empty { display: none; }
.rank-row { display: grid; grid-template-columns: 48px 1fr auto; gap: 8px; align-items: center; min-height: 40px; padding: 4px 12px; border-radius: 8px; font-variant-numeric: tabular-nums; }
.rank-row strong { min-width: 0; overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.rank-row.me { background: var(--surface-2); }
.btn .coin-dot { display: inline-block; vertical-align: -2px; margin-left: 4px; }
.btn-sm { min-height: 44px; padding: 4px 12px; font-size: 14px; white-space: nowrap; }

.panel-wide { width: min(100%, 440px); text-align: left; }
.panel h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text-muted); }
.shop-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.shop-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.shop-row { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); }
.shop-row img { flex: none; width: 64px; height: 64px; }
.shop-text { display: grid; flex: 1; min-width: 0; font-size: 14px; }
.shop-text strong { font-size: 16px; font-weight: 600; }
.shop-text span { color: var(--text-muted); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.portal-links { display: flex; justify-content: center; gap: 16px; font-size: 14px; }
.portal-links a { color: var(--text-muted); }
.portal-links a:hover { color: var(--text); }
