:root {
  --bg: #07070c;
  --bg-subtle: #0d0d16;
  --surface: rgba(20, 20, 32, 0.86);
  --surface-2: rgba(32, 32, 50, 0.9);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --text-subtle: #71717a;
  --brand: #818cf8;
  --brand-hover: #a5b4fc;
  --brand-subtle: rgba(129, 140, 248, 0.14);
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --dust: #fde68a;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-6: 24px; --space-8: 32px; --space-12: 48px;
  --radius: 8px; --radius-lg: 16px; --radius-xl: 20px;
  --ease-out: cubic-bezier(0.16, 1, 0.30, 1);
  --shadow-lg: 0 1px 2px rgba(0, 0, 10, 0.3), 0 12px 32px rgba(0, 0, 10, 0.5);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--bg); }
body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  letter-spacing: -0.01em;
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
p { max-width: 68ch; margin: 0 0 var(--space-4); }
h2 { font-size: 20px; font-weight: 600; margin: 0; }
button { font: inherit; color: inherit; letter-spacing: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

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

/* ---------- HUD ---------- */
.hud { position: fixed; left: 0; right: 0; display: flex; align-items: flex-start; justify-content: space-between; padding: var(--space-4); pointer-events: none; z-index: 10; }
.hud > * { pointer-events: auto; }
.hud-top { top: var(--safe-t); }
.hud-bottom { bottom: var(--safe-b); justify-content: center; gap: var(--space-2); padding-bottom: var(--space-4); }

.dust { display: flex; flex-direction: column; gap: 0; }
.dust-row { display: flex; align-items: center; gap: var(--space-2); }
.ic-dust { color: var(--dust); width: 24px; height: 24px; }
.dust-num { font-size: 32px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; color: var(--text); text-shadow: 0 2px 12px rgba(0,0,0,.6); }
.dust-rate { color: var(--text-muted); font-size: 14px; font-variant-numeric: tabular-nums; padding-left: 32px; }
.mult { color: var(--brand); margin-left: var(--space-1); }
.mult:empty { display: none; }

.hud-actions { display: flex; gap: var(--space-2); }
.icon-btn {
  width: 44px; height: 44px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center;
  backdrop-filter: blur(12px); transition: background-color 180ms var(--ease-out), color 180ms var(--ease-out), transform 180ms var(--ease-out);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn[aria-pressed="true"] { color: var(--text-subtle); }

.tab-btn {
  position: relative; flex: 1; max-width: 160px; min-height: 56px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  backdrop-filter: blur(12px); font-size: 12px;
  transition: background-color 180ms var(--ease-out), color 180ms var(--ease-out), transform 180ms var(--ease-out);
}
.tab-btn:hover { background: var(--surface-2); color: var(--text); }
.tab-btn:active { transform: scale(0.97); }
.tab-btn .ic { color: inherit; }
.dot { position: absolute; top: 8px; right: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 8px var(--brand); }

.hint {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 96px); transform: translateX(-50%);
  padding: var(--space-2) var(--space-4); border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 14px; pointer-events: none; z-index: 9; backdrop-filter: blur(12px);
  transition: opacity 250ms var(--ease-out), transform 250ms var(--ease-out); white-space: nowrap;
}
.hint b { color: var(--text); font-weight: 600; }
.hint[hidden] { display: block; opacity: 0; transform: translateX(-50%) translateY(-8px); }
.hint.warn { color: var(--warning); border-color: rgba(251,191,36,.3); }

.launch-info {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 84px); transform: translateX(-50%);
  color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; pointer-events: none; z-index: 9;
  text-shadow: 0 1px 8px rgba(0,0,0,.8); white-space: nowrap;
}
.launch-info b { color: var(--dust); font-weight: 600; }
.launch-info.poor b { color: var(--danger); }

/* ---------- Popover ---------- */
.popover {
  position: fixed; z-index: 12; width: 200px; padding: var(--space-3); border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); backdrop-filter: blur(12px); box-shadow: var(--shadow-lg);
  transform: translate(-50%, -100%); transition: opacity 160ms var(--ease-out);
}
.popover[hidden] { display: block; opacity: 0; pointer-events: none; }
.pop-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-2); }
.pop-head canvas { width: 40px; height: 40px; flex: none; }
.pop-name { font-weight: 600; }
.pop-sub { font-size: 12px; color: var(--text-muted); }
.pop-stats { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; margin-bottom: var(--space-3); }
.popover .btn { width: 100%; }
.dust-num.bump { animation: bump 220ms var(--ease-out); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }

/* ---------- Sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 6, 0.55); z-index: 20; opacity: 1; transition: opacity 200ms var(--ease-out); }
.scrim[hidden] { display: block; opacity: 0; pointer-events: none; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: min(78vh, 640px); overflow: auto;
  background: var(--bg-subtle); border-top: 1px solid var(--border); border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-4) var(--space-4) calc(var(--space-8) + var(--safe-b)); box-shadow: var(--shadow-lg);
  transform: translateY(0); opacity: 1; transition: transform 260ms var(--ease-out), opacity 200ms var(--ease-out);
  -webkit-user-select: none; user-select: none;
}
.sheet[hidden] { display: block; transform: translateY(24px); opacity: 0; pointer-events: none; }
@media (min-width: 720px) {
  .sheet { left: 50%; right: auto; width: 480px; transform: translateX(-50%); border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
  .sheet[hidden] { transform: translateX(-50%) translateY(24px); }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); position: sticky; top: 0; }
.list { display: flex; flex-direction: column; gap: var(--space-2); }
.row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: var(--space-2) var(--space-3); border-radius: var(--radius); background: var(--surface); }
.row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--brand); }

.upg {
  display: grid; grid-template-columns: 40px 1fr auto; gap: var(--space-3); align-items: center;
  padding: var(--space-3); border-radius: 12px; background: var(--surface); border: 1px solid transparent;
  transition: border-color 180ms var(--ease-out), background-color 180ms var(--ease-out);
}
.upg:hover { background: var(--surface-2); }
.upg.can { border-color: rgba(129,140,248,.35); }
.upg-ic { width: 40px; height: 40px; border-radius: 10px; background: var(--brand-subtle); color: var(--brand); display: flex; align-items: center; justify-content: center; }
.upg-body { min-width: 0; }
.upg-name { font-weight: 600; display: flex; align-items: center; gap: var(--space-2); }
.upg-lvl { font-size: 12px; color: var(--text-subtle); font-weight: 400; }
.upg-desc { font-size: 12px; color: var(--text-muted); margin: 0; }
.upg-eff { font-size: 12px; color: var(--success); }
.btn {
  min-height: 44px; padding: 0 var(--space-4); border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums;
  transition: background-color 180ms var(--ease-out), transform 180ms var(--ease-out), opacity 180ms var(--ease-out);
}
.btn:hover { background: rgba(48, 48, 70, 0.95); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn[hidden] { display: none; } /* .btn 의 display 가 hidden 속성을 덮지 않게 */
.btn-primary { background: var(--brand); border-color: transparent; color: #0b0b16; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-outline { background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-danger { background: var(--danger); border-color: transparent; color: #1a0606; }
.btn-danger:hover { background: #fca5a5; }
.btn-sm { min-height: 36px; padding: 0 var(--space-3); font-size: 12px; }
.btn-lg { min-height: 52px; width: 100%; font-size: 16px; }
.btn-buy { min-width: 96px; }
.btn-buy .ic-dust { width: 16px; height: 16px; }
.confirm { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3); border-radius: var(--radius); background: rgba(248,113,113,.1); color: var(--danger); font-size: 12px; }

.codex { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--space-2); }
.codex-item { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); padding: var(--space-3) var(--space-2); border-radius: 12px; background: var(--surface); text-align: center; }
.codex-item.locked { opacity: 0.4; }
.codex-ball { width: 40px; height: 40px; border-radius: 50%; box-shadow: inset -8px -8px 14px rgba(0,0,0,.45), 0 0 16px var(--glow, transparent); }
.codex-item.locked .codex-ball { background: var(--surface-2) !important; box-shadow: none; }
.codex-canvas { width: 56px; height: 56px; }
.codex-item.locked .codex-canvas { visibility: hidden; }
.codex-item.locked { position: relative; }
.codex-item.locked::before { content: '?'; position: absolute; top: 20px; left: 50%; transform: translateX(-50%); width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); color: var(--text-subtle); display: flex; align-items: center; justify-content: center; font-weight: 600; }
.codex-name { font-size: 12px; font-weight: 600; }
.codex-val { font-size: 12px; color: var(--dust); font-variant-numeric: tabular-nums; }

.nova-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); margin-bottom: var(--space-4); }
.nova-stats > div { display: flex; flex-direction: column; padding: var(--space-3); border-radius: 12px; background: var(--surface); font-size: 12px; }
.nova-stats strong { font-size: 20px; font-variant-numeric: tabular-nums; color: var(--text); }

/* ---------- Missions ---------- */
.sheet-sub { font-size: 16px; margin: var(--space-6) 0 var(--space-3); display: flex; align-items: baseline; gap: var(--space-2); }
.mission { display: grid; grid-template-columns: 1fr auto; gap: var(--space-3); align-items: center; padding: var(--space-3); border-radius: 12px; background: var(--surface); border: 1px solid transparent; }
.mission.done { border-color: rgba(253,230,138,.35); }
.mission.claimed { opacity: .5; }
.mission-name { font-weight: 600; }
.mission-reward { font-size: 12px; color: var(--dust); font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: var(--space-2); }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 3px; transition: width 300ms var(--ease-out); }
.mission.done .bar > i { background: var(--dust); }
.bar-label { font-size: 12px; color: var(--text-subtle); font-variant-numeric: tabular-nums; margin-top: var(--space-1); }
.ach { display: grid; grid-template-columns: 32px 1fr auto; gap: var(--space-3); align-items: center; padding: var(--space-2) var(--space-3); border-radius: var(--radius); background: var(--surface); min-height: 44px; }
.ach.locked { opacity: .55; }
.ach-ic { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--brand-subtle); color: var(--brand); }
.ach.locked .ach-ic { background: var(--surface-2); color: var(--text-subtle); }
.ach-name { font-weight: 600; font-size: 14px; }
.ach-desc { font-size: 12px; color: var(--text-muted); }
.ach-reward { font-size: 12px; color: var(--brand); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- Settings: skins · stats ---------- */
.skin-row { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-2); }
.skin { width: 44px; height: 44px; border-radius: 50%; border: 2px solid transparent; background: var(--surface); display: flex; align-items: center; justify-content: center; padding: 0; transition: transform 180ms var(--ease-out), border-color 180ms var(--ease-out); }
.skin i { width: 24px; height: 24px; border-radius: 50%; background: var(--c); box-shadow: 0 0 12px var(--c); }
.skin:hover { transform: scale(1.04); }
.skin[aria-pressed="true"] { border-color: var(--text); }
.skin:disabled { opacity: .3; cursor: not-allowed; }
.skin:disabled i { background: var(--surface-2); box-shadow: none; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.stats-grid > div { padding: var(--space-2) var(--space-3); border-radius: var(--radius); background: var(--surface); font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; }
.stats-grid strong { font-size: 16px; color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Season · Share ---------- */
.season { position: relative; overflow: hidden; padding: var(--space-4); border-radius: 12px; margin-bottom: var(--space-4); background: var(--surface); border: 1px solid var(--border); }
.season::before { content: ''; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: radial-gradient(circle, var(--c, var(--brand)) 0%, transparent 70%); opacity: .25; pointer-events: none; }
.season-tag { display: inline-block; font-size: 12px; color: var(--c, var(--brand)); font-weight: 600; margin-bottom: var(--space-1); }
.season-name { font-weight: 600; font-size: 16px; }
.season-desc { font-size: 12px; color: var(--text-muted); margin: 0 0 var(--space-2); }
.season .bar > i { background: var(--c, var(--brand)); }
.season.done .season-name { color: var(--c); }
.share-card { max-width: 400px; padding-top: var(--space-6); }
.share-preview { margin: var(--space-3) 0 var(--space-4); border-radius: 12px; overflow: hidden; aspect-ratio: 1080 / 1350; background: var(--surface); }
.share-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: var(--space-4); background: rgba(0,0,6,.6); backdrop-filter: blur(8px); opacity: 1; transition: opacity 200ms var(--ease-out); }
.modal[hidden] { display: flex; opacity: 0; pointer-events: none; }
.modal-card { position: relative; width: min(100%, 400px); padding: var(--space-8) var(--space-6) var(--space-6); border-radius: var(--radius-xl); background: var(--bg-subtle); border: 1px solid var(--border); box-shadow: var(--shadow-lg); text-align: center; overflow: hidden; }
.modal-glow { position: absolute; left: 50%; top: -80px; width: 240px; height: 240px; transform: translateX(-50%); border-radius: 50%; background: radial-gradient(circle, rgba(129,140,248,.35), transparent 70%); pointer-events: none; }
.modal-card p { margin-left: auto; margin-right: auto; }
.offline-num { font-size: 40px; font-weight: 600; color: var(--dust); font-variant-numeric: tabular-nums; margin: var(--space-2) 0 var(--space-6); letter-spacing: -0.02em; }
.modal-actions { display: flex; flex-direction: column; gap: var(--space-2); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; top: calc(var(--safe-t) + 140px); transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--space-2); z-index: 25; pointer-events: none; width: min(92vw, 360px); }
.toast { padding: var(--space-3) var(--space-4); border-radius: 12px; background: var(--surface); border: 1px solid var(--border); backdrop-filter: blur(12px); box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: var(--space-3); animation: toast-in 260ms var(--ease-out); }
.toast.out { opacity: 0; transform: translateY(-8px); transition: opacity 240ms var(--ease-out), transform 240ms var(--ease-out); }
.toast .t-title { font-weight: 600; }
.toast .t-sub { font-size: 12px; color: var(--text-muted); }
.toast.big { border-color: rgba(253,230,138,.4); }
.toast.big .t-title { color: var(--dust); }
.toast .codex-ball { width: 32px; height: 32px; flex: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }

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