:root {
  --bg: #0f1419;
  --bg-card: #1a2332;
  --bg-deep: #0a0f15;
  --accent: #ffd700;
  --text: #e8edf2;
  --text-dim: #8b9bb0;
  --win: #4ade80;
  --neutral: #fbbf24;
  --loss: #f87171;
  --border: #2a3a52;
  --primary: linear-gradient(135deg, #ff6b35, #f72585);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: radial-gradient(circle at top left, rgba(255, 107, 53, 0.12), transparent 22rem), var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.container {
  flex: 1;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding: 10px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.page-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 2px 0 4px;
}
.page-title {
  min-width: 0;
  text-align: center;
  font-size: 16px;
  font-weight: 900;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-btn {
  min-width: 58px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 11px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  white-space: nowrap;
}
.nav-btn:active { transform: scale(0.97); }

.topbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.topcard {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.topcard-label { font-size: 10px; font-weight: 700; color: var(--text-dim); letter-spacing: 0.5px; }
.topcard-value { font-size: 22px; font-weight: 900; line-height: 1; }
.topcard-value.ei { color: var(--accent); }
.topcard-value.power { color: #ff6b35; }
.power-inline-row { display: flex; align-items: baseline; gap: 5px; min-width: 0; overflow: hidden; }
.power-inline-stats { font-size: 9px; font-weight: 700; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.matbar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.mat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.mat-icon { font-size: 22px; }
.mat-info { flex: 1; min-width: 0; }
.mat-name { font-size: 9px; color: var(--text-dim); letter-spacing: 0.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mat-count { font-size: 16px; font-weight: 800; color: var(--text); }

.section-title {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 6px 2px 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.section-title .sub { font-size: 10px; letter-spacing: 0.5px; text-transform: none; opacity: 0.7; }

.slot-grid { display: grid; gap: 8px; }
.slot-grid.cols-1 { grid-template-columns: 1fr; }
.slot-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.slot {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}
.slot-head { display: flex; align-items: center; gap: 10px; }
.slot-icon {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  background: var(--bg-deep);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}
.slot-text { flex: 1; min-width: 0; }
.slot-name { font-size: 11px; color: var(--text-dim); letter-spacing: 0.5px; line-height: 1.2; }
.slot-weight { color: #ff6b35; font-weight: 700; margin-left: 4px; font-size: 10px; }
.slot-level {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.05;
  margin-top: 3px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.slot-status {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 700;
  font-family: ui-monospace, monospace;
  letter-spacing: 0.3px;
  line-height: 1.1;
}
.transcend-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.3px;
  font-family: ui-monospace, monospace;
  vertical-align: 3px;
}
.transcend-badge.t1 { color: #38bdf8;   background: rgba(56, 189, 248, 0.14); border: 1px solid rgba(56, 189, 248, 0.4); }
.transcend-badge.t2 { color: #a78bfa;   background: rgba(167, 139, 250, 0.14); border: 1px solid rgba(167, 139, 250, 0.4); }
.transcend-badge.t3 { color: #fbbf24;   background: rgba(251, 191, 36, 0.14); border: 1px solid rgba(251, 191, 36, 0.4); }
.transcend-badge.t4 { color: #ff6b35;   background: rgba(255, 107, 53, 0.14); border: 1px solid rgba(255, 107, 53, 0.4); }
.transcend-badge.t5 { color: #f87171;   background: rgba(248, 113, 113, 0.18); border: 1px solid rgba(248, 113, 113, 0.55); box-shadow: 0 0 10px rgba(248, 113, 133, 0.45); }
.slot-power {
  color: #ff6b35;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.15;
  margin-left: 5px;
}
.slot-meta {
  font-size: 10px;
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
  line-height: 1.2;
  min-height: 14px;
  margin-top: 1px;
}
.slot-meta .dot { color: var(--border); padding: 0 3px; }

.enhance-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 0;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-deep);
  min-height: 44px;
}
.enhance-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 9px 0 0 9px;
  padding: 7px 8px 8px;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  letter-spacing: 0;
  transition: transform 0.08s;
  line-height: 1.2;
  min-width: 0;
}
.enhance-btn:active { transform: scale(0.97); }
.enhance-btn:disabled { opacity: 0.4; cursor: not-allowed; background: var(--bg-deep); color: var(--text-dim); box-shadow: none; }
.enhance-btn .cost { display: block; font-size: 9px; font-weight: 700; margin-top: 2px; opacity: 0.85; }
.enhance-btn .cost.cant { color: #ffb4b4; opacity: 1; }
.target-stepper {
  min-width: 0;
  background: var(--bg-deep);
  border: none;
  border-left: 1px solid var(--border);
  border-radius: 0;
  display: grid;
  grid-template-columns: 28px 1fr 28px;
  align-items: center;
  overflow: hidden;
}
.target-btn {
  height: 100%;
  min-height: 42px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}
.target-btn:active { background: rgba(255, 255, 255, 0.07); }
.target-btn:disabled { color: var(--text-dim); opacity: 0.35; cursor: not-allowed; }
.target-value {
  min-width: 0;
  text-align: center;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 5px 2px 4px;
}
.target-label { display: block; color: var(--text-dim); font-size: 8px; font-weight: 700; letter-spacing: 0.5px; }
.target-number { display: block; color: var(--accent); font-size: 13px; font-weight: 900; line-height: 1.2; margin-top: 1px; }
.prob-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  min-height: 28px;
}
.prob-row.maxed {
  grid-template-columns: 1fr;
}
.prob-chip {
  background: var(--bg-deep);
  border: 1px solid rgba(42, 58, 82, 0.72);
  border-radius: 7px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  padding: 6px 3px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}
.prob-chip b {
  font-size: 10px;
  font-weight: 900;
}
.prob-chip.success b { color: var(--win); }
.prob-chip.maintain b { color: var(--neutral); }
.prob-chip.fail b { color: var(--loss); }
.slot.wide .slot-head { padding-bottom: 0; }
.slot.wide .slot-icon { width: 52px; height: 52px; font-size: 30px; }
.slot.wide .slot-level { font-size: 26px; }

.log {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 4px 0;
  max-height: 220px;
  overflow-y: auto;
  font-size: 13px;
  border: 1px solid var(--border);
  flex: 1;
  min-height: 80px;
}
.log-entry { padding: 8px 14px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 8px; }
.log-entry:last-child { border-bottom: none; }
.log-entry.success { color: var(--win); }
.log-entry.maintain { color: var(--neutral); }
.log-entry.fail { color: var(--loss); }
.log-entry.transcend { color: var(--accent); }
.log-entry.placeholder { color: var(--text-dim); justify-content: center; padding: 20px; }
.log-entry .delta { color: var(--text-dim); font-size: 11px; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: fadeIn 0.18s ease;
}
.overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%;
  max-width: 340px;
  background: var(--bg-card);
  border-radius: 18px;
  padding: 22px 18px;
  text-align: center;
  border: 1px solid var(--border);
}
.anim-icon { font-size: 32px; animation: pulse 0.6s ease infinite alternate; opacity: 0.72; }
@keyframes pulse { from { transform: scale(1); filter: brightness(1); } to { transform: scale(1.15); filter: brightness(1.4); } }
.anim-status { color: var(--text-dim); font-size: 13px; margin-top: 14px; }
.progress-level {
  color: var(--accent);
  font-size: 72px;
  line-height: 0.95;
  font-weight: 950;
  letter-spacing: 0;
  text-shadow: 0 0 26px rgba(255, 209, 102, 0.22);
  display: inline-block;
}
/* 자동강화 결과별 시각 효과 — 320ms 라운드에 맞춰 거의 풀로 채움 */
.progress-level.fx-success {
  animation: progressLevelSuccess 0.30s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes progressLevelSuccess {
  0%   { transform: scale(0.9);  text-shadow: 0 0 26px rgba(255, 209, 102, 0.22); color: var(--accent); }
  35%  { transform: scale(1.55); text-shadow: 0 0 80px rgba(255, 215, 0, 1), 0 0 30px rgba(255, 235, 110, 1), 0 0 12px #fff; color: #ffffff; }
  100% { transform: scale(1);    text-shadow: 0 0 26px rgba(255, 209, 102, 0.55);  color: var(--accent); }
}
.progress-level.fx-fail {
  animation: progressLevelFail 0.30s ease-in-out both;
}
@keyframes progressLevelFail {
  0%   { transform: translateX(0);    color: var(--accent); text-shadow: 0 0 26px rgba(255, 209, 102, 0.22); }
  10%  { transform: translateX(-18px); color: var(--loss); text-shadow: 0 0 40px rgba(248, 113, 113, 1); }
  25%  { transform: translateX(15px);  color: var(--loss); }
  40%  { transform: translateX(-13px); color: var(--loss); }
  55%  { transform: translateX(11px);  color: var(--loss); }
  70%  { transform: translateX(-7px);  color: var(--loss); }
  85%  { transform: translateX(4px);   color: var(--loss); }
  100% { transform: translateX(0);    color: var(--accent); text-shadow: 0 0 26px rgba(255, 209, 102, 0.22); }
}
.progress-level.fx-stay {
  animation: progressLevelStay 0.26s ease both;
}
@keyframes progressLevelStay {
  0%   { opacity: 1; transform: scale(1); color: var(--accent); }
  50%  { opacity: 0.4; transform: scale(0.88); color: var(--text-dim); }
  100% { opacity: 1; transform: scale(1); color: var(--accent); }
}

/* 모달 배경 글로우 — JS에서 modal에 클래스 부착 */
.modal.flash-success {
  animation: modalFlashSuccess 0.28s ease-out;
}
.modal.flash-fail {
  animation: modalFlashFail 0.28s ease-out;
}
@keyframes modalFlashSuccess {
  0%   { box-shadow: 0 0 0 transparent; }
  40%  { box-shadow: 0 0 60px 10px rgba(255, 215, 0, 0.65); border-color: var(--accent); }
  100% { box-shadow: 0 0 0 transparent; }
}
@keyframes modalFlashFail {
  0%   { box-shadow: 0 0 0 transparent; }
  40%  { box-shadow: 0 0 60px 10px rgba(248, 113, 113, 0.65); border-color: var(--loss); }
  100% { box-shadow: 0 0 0 transparent; }
}
.level-jump { display: flex; justify-content: center; align-items: baseline; gap: 12px; margin: 16px 0; font-weight: 900; }
.level-from { font-size: 38px; color: #9fb3d1; }
.level-arrow { font-size: 22px; color: var(--text-dim); }
.level-to { font-size: 58px; color: var(--accent); line-height: 0.95; text-shadow: 0 0 24px rgba(255, 209, 102, 0.22); white-space: nowrap; }
.level-to.fail-color { color: var(--loss); }
.level-to.maintain-color { color: var(--neutral); }
.result-level-jump { margin: 18px 0 12px; }
.result-title { font-size: 25px; font-weight: 900; letter-spacing: 0; margin-bottom: 4px; }
.result-title.success { color: var(--win); }
.result-title.maintain { color: var(--neutral); }
.result-title.fail { color: var(--loss); }
.result-sub { color: var(--text-dim); font-size: 12px; }
.result-sub span { color: #ff6b35; font-weight: 700; }
.power-jump { color: var(--text-dim); font-size: 12px; margin-top: -10px; margin-bottom: 10px; }
.power-jump span { color: #ff6b35; font-weight: 700; }
.power-jump b { margin-left: 6px; }
.power-jump b.up { color: var(--win); }
.power-jump b.down { color: var(--loss); }
.rate-grid, .auto-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 14px 0 8px; }
.auto-summary { margin: 14px 0; }
.rate-cell, .auto-cell { background: var(--bg-deep); border-radius: 8px; padding: 8px 4px; }
.rate-cell-label, .auto-cell-label { font-size: 10px; color: var(--text-dim); }
.rate-cell-value, .auto-cell-value { font-size: 15px; font-weight: 700; margin-top: 2px; }
.auto-cell-value { font-size: 16px; font-weight: 800; }
.rate-cell.success .rate-cell-value, .auto-cell.success .auto-cell-value { color: var(--win); }
.rate-cell.maintain .rate-cell-value { color: var(--neutral); }
.rate-cell.fail .rate-cell-value, .auto-cell.fail .auto-cell-value { color: var(--loss); }
.cost-bar {
  background: var(--bg-deep);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-dim);
  margin: 4px 0 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.cost-bar .cost-val { color: var(--accent); font-weight: 700; }
.close-btn {
  width: 100%;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s;
}
.close-btn:active { transform: scale(0.98); }
.stop-btn {
  width: 100%;
  margin-top: 18px;
  background: var(--bg-deep);
  color: var(--loss);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
}
.stop-btn:active { transform: scale(0.98); }
.stop-btn:disabled {
  color: var(--text-dim);
  opacity: 0.7;
  cursor: not-allowed;
}
.reset-hint { text-align: center; color: var(--text-dim); font-size: 10px; margin-top: 4px; opacity: 0.5; }
