:root {
  --ink-dark: #1e293b;
  --ink-muted: #64748b;
  --cream-bg: #fff9eb;
  --accent-blue: #3b82f6;
  --accent-blue-dark: #1d4ed8;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-yellow: #facc15;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 20%, #2d1b4e 0%, #131129 65%, #090814 100%);
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink-dark);
  overflow: hidden;
}

#app {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  width: 100%;
  padding: 8px;
}

/* 메인 게임 프레임 */
.game-frame {
  width: 100%;
  max-width: 440px;
  height: 100%;
  max-height: 820px;
  background: var(--cream-bg);
  border-radius: 26px;
  border: 3.5px solid var(--ink-dark);
  box-shadow: 0 10px 0 #0f172a, 0 24px 50px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* 초슬림 통합 상단 HUD */
.hud {
  background: linear-gradient(180deg, #fffdf7 0%, #fef3c7 100%);
  border-bottom: 3px solid var(--ink-dark);
  padding: 8px 12px 7px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 5;
}

.hud-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.stage-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--ink-dark);
  color: #fde047;
  border: none;
  border-radius: 999px;
  padding: 4px 10px 4px 5px;
  font-family: 'Jua', sans-serif;
  font-size: 13px;
  cursor: pointer;
  max-width: 58%;
  transition: transform 0.1s;
}

.stage-btn:active {
  transform: scale(0.96);
}

.stage-btn span:nth-child(2) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fde047, #f59e0b);
  color: #78350f;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
  flex-shrink: 0;
}

.chevron {
  font-size: 11px;
  opacity: 0.85;
}

.hud-right-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.combo-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, #f97316, #ef4444);
  border: 2px solid var(--ink-dark);
  color: #fff;
  font-family: 'Jua', sans-serif;
  font-size: 11px;
  box-shadow: 0 2px 0 var(--ink-dark);
}

.timer-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #3b82f6;
  border: 2px solid var(--ink-dark);
  border-radius: 999px;
  padding: 3px 10px;
  color: #fff;
  box-shadow: 0 2px 0 var(--ink-dark);
}

.timer-pill.sim {
  background: #f97316;
}

.timer-pill.urgent {
  background: #ef4444;
  animation: pulse 0.45s infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

.timer-dot {
  font-size: 10px;
  font-weight: 800;
  opacity: 0.9;
}

.hud-timer {
  font-family: 'Jua', sans-serif;
  font-size: 14px;
}

.mini-icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--ink-dark);
  background: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--ink-dark);
}

.hud-row-wallet {
  background: #ffffff;
  border: 2px solid var(--ink-dark);
  border-radius: 12px;
  padding: 5px 10px 6px;
}

.wallet-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.balance-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.wallet-tag {
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-muted);
}

.hud-balance {
  font-family: 'Jua', sans-serif;
  font-size: 20px;
  line-height: 1.1;
  color: var(--ink-dark);
}

.hud-balance.safe { color: #15803d; }
.hud-balance.danger { color: #dc2626; }

.target-chip {
  font-size: 10px;
  font-weight: 900;
  background: #dbeafe;
  color: #1d4ed8;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1.5px solid #93c5fd;
}

.gauge-track {
  position: relative;
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border: 1.5px solid var(--ink-dark);
  border-radius: 999px;
  margin-top: 4px;
  overflow: hidden;
}

.gauge-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  transition: width 0.12s ease, background 0.15s;
}

.gauge-fill.danger {
  background: linear-gradient(90deg, #ef4444, #f97316);
}

.gauge-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #1e293b;
  left: 70%;
  z-index: 2;
}

.hint-strip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.85);
  border: 1.5px solid #fcd34d;
  border-radius: 8px;
  padding: 3px 8px;
}

.hint-icon { font-size: 12px; }

.stage-hint {
  font-size: 11px;
  font-weight: 700;
  color: #475569;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 캔버스 영역 */
.canvas-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  background: var(--cream-bg);
  touch-action: none;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* 하단 펜 슬롯 바 */
.bottom-bar {
  background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
  border-top: 3px solid var(--ink-dark);
  padding: 8px 12px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pen-selector {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.pen-btn {
  position: relative;
  border: 2.5px solid var(--ink-dark);
  background: #ffffff;
  border-radius: 13px;
  padding: 6px 4px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink-dark);
  transition: transform 0.1s, box-shadow 0.1s, background 0.12s;
}

.pen-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink-dark);
}

.pen-btn.active {
  background: #dbeafe;
  border-color: #1d4ed8;
  box-shadow: 0 3px 0 #1d4ed8;
}

.pen-btn[data-pen="highlighter"].active {
  background: #fef08a;
  border-color: #ca8a04;
  box-shadow: 0 3px 0 #ca8a04;
}

.pen-btn[data-pen="marker"].active {
  background: #cbd5e1;
  border-color: #0f172a;
  box-shadow: 0 3px 0 #0f172a;
}

.pen-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  box-shadow: none;
}

.pen-badge {
  position: absolute;
  top: -7px;
  right: 6px;
  font-size: 9px;
  font-weight: 900;
  padding: 1px 6px;
  border-radius: 999px;
  background: #334155;
  color: #fff;
  border: 1.5px solid #fff;
}

.pen-badge.neon { background: #eab308; color: #1e293b; }
.pen-badge.heavy { background: #ef4444; color: #fff; }
.pen-icon { font-size: 16px; }
.pen-name { font-family: 'Jua', sans-serif; font-size: 12px; color: var(--ink-dark); }
.pen-cost { font-size: 10px; color: var(--ink-muted); font-weight: 700; }

.quick-retry-btn {
  width: 46px;
  height: 52px;
  border-radius: 13px;
  border: 2.5px solid var(--ink-dark);
  background: #fde047;
  font-size: 22px;
  font-weight: 900;
  color: var(--ink-dark);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink-dark);
  transition: transform 0.1s, box-shadow 0.1s;
}

.quick-retry-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink-dark);
}

/* 모달 */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.76);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 20;
}

.modal-card {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  background: #fffdf7;
  border: 3px solid var(--ink-dark);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 8px 0 var(--ink-dark), 0 20px 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 { margin: 0; font-family: 'Jua', sans-serif; font-size: 21px; }

.close-btn {
  border: 2px solid var(--ink-dark);
  background: #f1f5f9;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-weight: 900;
  cursor: pointer;
}

.modal-desc { margin: 0; font-size: 12px; color: var(--ink-muted); font-weight: 600; }

.stage-list { display: flex; flex-direction: column; gap: 8px; }

.stage-item {
  border: 2.5px solid var(--ink-dark);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  background: #fff;
  box-shadow: 0 3px 0 #cbd5e1;
  text-align: left;
  transition: transform 0.1s;
}

.stage-item:active { transform: translateY(2px); }
.stage-item.active { background: #eff6ff; border-color: var(--accent-blue-dark); box-shadow: 0 3px 0 var(--accent-blue-dark); }
.stage-item-title { font-family: 'Jua', sans-serif; font-size: 14px; }
.stage-item-sub { font-size: 11px; color: var(--ink-muted); font-weight: 600; margin-top: 2px; }

.stage-badge {
  font-size: 11px;
  font-weight: 900;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  border: 1.5px solid #cbd5e1;
  color: #475569;
}

.stage-badge.cleared { background: #dcfce7; border-color: #22c55e; color: #15803d; }

.daily-btn {
  border: 2.5px solid var(--ink-dark);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(135deg, #f97316, #ef4444);
  color: #fff;
  font-family: 'Jua', sans-serif;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink-dark);
}

/* 결과 카드 */
.result-card { align-items: center; text-align: center; gap: 7px; }
.result-stars { font-size: 26px; letter-spacing: 4px; line-height: 1; }
.result-stamp { font-family: 'Jua', sans-serif; font-size: 13px; padding: 3px 13px; border-radius: 999px; border: 2px solid var(--ink-dark); }
.result-stamp.win { background: #4ade80; color: #052e16; }
.result-stamp.lose { background: #f87171; color: #450a0a; }
.result-title { margin: 0; font-family: 'Jua', sans-serif; font-size: 20px; }
.result-summary { margin: 0; font-size: 12px; color: var(--ink-muted); font-weight: 600; }

.receipt-preview-wrap {
  width: 100%;
  max-width: 210px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--ink-dark);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.15);
}

#receipt-canvas { width: 100%; height: auto; display: block; }

.result-stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: #f1f5f9;
  border: 2px solid #cbd5e1;
  padding: 8px;
  border-radius: 12px;
}

.stat-item { display: flex; flex-direction: column; gap: 2px; }
.stat-item span { font-size: 10px; color: var(--ink-muted); font-weight: 700; }
.stat-item strong { font-size: 12px; color: var(--ink-dark); font-weight: 900; }

.result-actions, .viral-actions {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-game {
  border: 2.5px solid var(--ink-dark);
  border-radius: 12px;
  padding: 10px;
  font-family: 'Jua', sans-serif;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink-dark);
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn-game:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink-dark); }
.btn-game.primary { background: #3b82f6; color: #fff; }
.btn-game.secondary { background: #e2e8f0; color: var(--ink-dark); }
.btn-game.dark { background: #1e293b; color: #fff; }
.btn-game.light { background: #fff; color: var(--ink-dark); }
.btn-game.gold { width: 100%; background: linear-gradient(135deg, #fde047, #f59e0b); color: var(--ink-dark); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink-dark);
  border: 2px solid #fde047;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  z-index: 100;
}

.hidden { display: none !important; }
