:root {
  --bg: #0b0806;
  --ink: #ede2cc;
  --mute: #8f816f;
  --dim: #5a4f44;
  --line: rgba(237, 226, 204, .09);
  --ember: #ff7f36;
  --ember-hot: #ffb469;
  --blood: #e8524a;
  --rune: #7cc8ff;
  --gold: #e9bc52;
  --t0: #b8aa98; --t1: #e3e9ec; --t2: #e9bc52; --t3: #7cc8ff; --t4: #ff7f36;
  --tier: var(--t0);
  --lvp: 0;  /* 0~1, 강화 단계에 비례 (+1마다 연출이 조금씩 세짐) */
  --font: 'Pretendard Variable', Pretendard, -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 var(--font); font-feature-settings: 'tnum'; -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--ember-hot); outline-offset: 3px; }

.btn-ghost {
  background: rgba(237, 226, 204, .03); border: 1px solid rgba(237, 226, 204, .16); border-radius: 6px;
  padding: 10px 14px; color: var(--ink); font-weight: 600; transition: border-color .15s, background .15s;
}
.btn-ghost:hover:not(:disabled) { border-color: rgba(237, 226, 204, .4); background: rgba(237, 226, 204, .07); }
.btn-ghost:disabled { opacity: .35; }
.btn-ghost.confirm { border-color: var(--blood); color: #ffb4ad; background: rgba(232, 82, 74, .12); }
.icon { width: 34px; height: 34px; display: inline-grid; place-items: center; border: 0; background: transparent; color: var(--mute); border-radius: 6px; }
.icon:hover { color: var(--ink); background: rgba(237, 226, 204, .06); }

/* ---------- 로그인 ---------- */
#auth {
  min-height: 100%; display: grid; place-content: center; justify-items: center; gap: 44px; padding: 32px; overflow: auto;
  background: linear-gradient(rgba(11, 8, 6, .55), rgba(11, 8, 6, .85)), var(--bg-image, none) center / cover, var(--bg);
}
.auth { width: 300px; display: grid; gap: 10px; }
.logo { margin: 0 0 24px; font-size: 52px; font-weight: 900; letter-spacing: -.05em; text-align: center; text-shadow: 0 0 40px rgba(255, 127, 54, .35); }
.auth input { width: 100%; padding: 13px 2px; background: transparent; border: 0; border-bottom: 1px solid rgba(237, 226, 204, .22); outline: none; }
.auth input:focus { border-bottom-color: var(--ember); }
.auth input::placeholder { color: var(--dim); }
.form-error { min-height: 20px; margin: 4px 0 0; color: var(--blood); font-size: 13px; }
.auth-btns { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.btn-main {
  border: 0; border-radius: 6px; padding: 13px; font-weight: 800; color: #2a1206;
  background: linear-gradient(180deg, #ffa060, #e0611f); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 8px 24px -8px rgba(255, 127, 54, .6);
}
.auth-ranks { width: 300px; }

/* ---------- 게임: 좌 랭킹 / 중앙 무대 / 우 정보 ---------- */
#game { height: 100vh; }
.scene {
  position: relative; height: 100vh; overflow: hidden;
  display: grid; grid-template-columns: 280px minmax(0, 1fr) 280px; grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0 28px; padding: 18px 32px 26px;
  background:
    radial-gradient(42% 46% at 50% 50%, color-mix(in srgb, var(--tier) calc(6% + var(--lvp) * 16%), transparent), transparent 75%),
    linear-gradient(180deg, rgba(11, 8, 6, .55), rgba(11, 8, 6, .2) 40%, rgba(11, 8, 6, .8)),
    var(--bg-image, none) 70% center / cover no-repeat,
    var(--bg);
}
.vignette {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(ellipse at 50% 48%, transparent 38%, rgba(0, 0, 0, .78) 100%);
  transition: opacity .5s;
}
.vignette::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 48%, transparent 18%, rgba(0, 0, 0, .96) 75%); opacity: 0; transition: opacity .35s; }
.scene.tense .vignette::after { opacity: 1; }
.vignette.red { animation: redpulse .7s ease-out 1; }
@keyframes redpulse { 0% { box-shadow: inset 0 0 260px 80px rgba(232, 40, 30, .75); } 100% { box-shadow: inset 0 0 0 0 rgba(232, 40, 30, 0); } }
.vignette.gold { animation: goldpulse .9s ease-out 1; }
@keyframes goldpulse { 0% { box-shadow: inset 0 0 260px 60px color-mix(in srgb, var(--tier) 60%, transparent); } 100% { box-shadow: inset 0 0 0 0 transparent; } }

.hud { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; position: relative; z-index: 5; padding-bottom: 10px; }
.brand { font-size: 22px; font-weight: 900; letter-spacing: -.04em; }
.wallet { display: flex; gap: 10px; }
.wallet span { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px 6px 8px; border-radius: 999px; background: rgba(8, 6, 5, .65); border: 1px solid var(--line); font-weight: 700; font-size: 16px; }
.wallet img { width: 26px; height: 26px; }
.wallet b.tick { animation: tick .35s ease-out 1; }
@keyframes tick { 0% { color: var(--ember-hot); transform: scale(1.15); } }
.me { display: flex; justify-content: flex-end; align-items: center; gap: 2px; color: var(--mute); font-size: 14px; }
.me span { margin-right: 8px; }

.panel {
  position: relative; z-index: 5; align-self: center;
  background: linear-gradient(180deg, rgba(20, 15, 12, .88), rgba(12, 9, 7, .88));
  border: 1px solid var(--line); border-radius: 12px; padding: 20px;
  box-shadow: 0 20px 60px -20px rgba(0, 0, 0, .8), inset 0 1px 0 rgba(255, 255, 255, .04);
}
.panel::before { content: ''; position: absolute; left: 20px; right: 20px; top: -1px; height: 2px; border-radius: 2px; background: var(--tier); opacity: .75; transition: background .4s; }
.panel h3 { margin: 0 0 12px; font-size: 13px; font-weight: 700; color: var(--mute); }

/* 랭킹 */
.rank-panel { grid-column: 1; grid-row: 2; max-height: 100%; overflow: auto; }
.ranks { list-style: none; margin: 0; padding: 0; }
.ranks li { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.ranks li:last-child { border-bottom: 0; }
.ranks .n { color: var(--dim); font-weight: 800; font-size: 14px; text-align: center; }
.ranks .n img { width: 28px; height: 28px; display: block; margin: -4px auto; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .6)); }
.ranks .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.ranks .lvl { font-weight: 800; font-size: 16px; }
.ranks li:nth-child(1) .lvl { color: var(--gold); font-size: 18px; }
.ranks li:nth-child(2) .lvl { color: #d6dde1; }
.ranks li:nth-child(3) .lvl { color: #d0915e; }
.ranks li.mine .name { color: var(--ember-hot); }
.ranks li.empty { display: block; color: var(--dim); border: 0; }
.my-rank { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; color: var(--ember-hot); font-weight: 700; }

/* 무대 */
.forge { grid-column: 2; grid-row: 2; position: relative; z-index: 2; min-height: 0; }
.fx { position: absolute; inset: -18% -40%; width: 180%; height: 136%; pointer-events: none; z-index: 6; }
.rays {
  position: absolute; left: 50%; top: 50%; width: 760px; height: 760px; margin: -380px 0 0 -380px; z-index: 0; pointer-events: none;
  background: repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--tier) 55%, transparent) 0deg 4deg, transparent 4deg 18deg);
  -webkit-mask: radial-gradient(circle, #000 0%, transparent 62%); mask: radial-gradient(circle, #000 0%, transparent 62%);
  opacity: calc(max(0, var(--lvp) - .2) * .7); animation: spin calc(48s - var(--lvp) * 30s) linear infinite; transition: opacity .6s;
}
@keyframes spin { to { transform: rotate(360deg); } }
.glow {
  position: absolute; left: 50%; top: 50%; width: calc(380px + var(--lvp) * 320px); height: calc(380px + var(--lvp) * 320px);
  transform: translate(-50%, -50%); z-index: 1; opacity: calc(.25 + var(--lvp) * .75);
  background: radial-gradient(circle, color-mix(in srgb, var(--tier) 30%, transparent), transparent 62%);
  animation: breathe calc(3.4s - var(--lvp) * 1.6s) ease-in-out infinite; transition: width .5s, height .5s, opacity .5s;
}
.glow.img { background: var(--glow-image) center / contain no-repeat; }
.scene[data-tier="1"] .glow.img { filter: saturate(.15) brightness(1.25); }
.scene[data-tier="3"] .glow.img { filter: hue-rotate(180deg) saturate(1.4); }
@keyframes breathe { 50% { transform: translate(-50%, -50%) scale(1.08); } }
.weapon {
  position: absolute; left: 50%; top: 50%; width: min(440px, 92%); aspect-ratio: 1; z-index: 3;
  transform: translate(-50%, -50%) scale(calc(.86 + var(--lvp) * .2));
  filter: drop-shadow(0 24px 24px rgba(0, 0, 0, .65)) drop-shadow(0 0 calc(6px + var(--lvp) * 30px) color-mix(in srgb, var(--tier) 55%, transparent));
  animation: float 3.6s ease-in-out infinite; transition: filter .5s;
}
@keyframes float { 50% { translate: 0 -9px; } }
.weapon.strike { animation: strike .12s ease-out 1; }
@keyframes strike { 40% { translate: 0 8px; rotate: -1.5deg; } }
.weapon.pop { animation: pop .6s cubic-bezier(.2, 1.6, .35, 1) 1; }
@keyframes pop { 0% { scale: .7; filter: brightness(3) drop-shadow(0 0 40px #fff); } 100% { scale: 1; } }
.weapon.hurt { animation: hurt .4s linear 1; }
@keyframes hurt { 15%, 55% { translate: -10px 0; filter: brightness(1.8) sepia(1) saturate(6) hue-rotate(-40deg); } 35%, 75% { translate: 10px 0; } }
.anvil { display: none; }
.orbit { position: absolute; left: 50%; top: 50%; width: 0; height: 0; z-index: 4; pointer-events: none; animation: spin calc(9s - var(--lvp) * 4s) linear infinite; }
.orbit i {
  position: absolute; width: 9px; height: 9px; margin: -4.5px; border-radius: 50%;
  background: radial-gradient(circle, #fff, var(--tier) 55%, transparent 70%); box-shadow: 0 0 14px 4px var(--tier);
}
.crack-overlay {
  position: absolute; left: 50%; top: 50%; width: min(300px, 64%); aspect-ratio: 1; transform: translate(-50%, -50%) rotate(-8deg);
  z-index: 4; pointer-events: none; filter: drop-shadow(0 0 10px rgba(255, 80, 30, .9)); animation: throb 1.4s ease-in-out infinite;
}
@keyframes throb { 50% { opacity: .6; } }
.flash { position: absolute; inset: -40% -60%; pointer-events: none; z-index: 7; opacity: 0; }
.flash.go { animation: flash .55s ease-out 1; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
.banner {
  position: absolute; left: -40%; right: -40%; top: 50%; z-index: 8; text-align: center; pointer-events: none; opacity: 0;
  font-size: clamp(56px, 8vw, 110px); font-weight: 900; letter-spacing: -.04em; line-height: 1;
  -webkit-text-stroke: 2px rgba(0, 0, 0, .55); paint-order: stroke fill; text-shadow: 0 0 30px currentColor, 0 6px 0 rgba(0, 0, 0, .6);
}
.banner small { display: block; margin-top: 10px; font-size: .24em; font-weight: 700; letter-spacing: 0; color: var(--ink); -webkit-text-stroke: 0; text-shadow: 0 2px 8px #000; }
.banner.go { animation: banner 1.3s cubic-bezier(.2, 1, .3, 1) 1; }
@keyframes banner {
  0% { opacity: 0; transform: translateY(-50%) scale(2.3); filter: blur(8px); }
  14% { opacity: 1; transform: translateY(-50%) scale(1); filter: none; }
  72% { opacity: 1; transform: translateY(-58%) scale(1); }
  100% { opacity: 0; transform: translateY(-68%) scale(.96); }
}
.shard-piece { position: absolute; z-index: 5; pointer-events: none; }
.fx-sprite { position: absolute; left: 50%; top: 50%; width: 640px; height: 640px; margin: -320px 0 0 -320px; pointer-events: none; z-index: 6; }
.ring { position: absolute; left: 50%; top: 50%; width: 200px; height: 200px; margin: -100px 0 0 -100px; border-radius: 50%; border: 5px solid var(--tier); z-index: 6; pointer-events: none; box-shadow: 0 0 40px var(--tier), inset 0 0 30px var(--tier); }
.scene.grey .forge, .scene.grey .panel { filter: grayscale(1) brightness(.5); }

/* 돌파 시련 */
.trial { position: absolute; inset: 0; z-index: 9; display: grid; place-content: center; justify-items: center; gap: 22px; cursor: pointer; }
.trial::before { content: ''; position: absolute; inset: -30% -60%; background: radial-gradient(closest-side, rgba(8, 6, 5, .92), rgba(8, 6, 5, .55)); z-index: -1; }
.trial-title { font-size: 44px; font-weight: 900; color: var(--ember-hot); text-shadow: 0 0 30px rgba(255, 127, 54, .6); letter-spacing: -.02em; }
.gauge { position: relative; width: min(480px, 80vw); height: 14px; border-radius: 7px; background: rgba(237, 226, 204, .1); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6); }
.sweet { position: absolute; left: 37.5%; width: 25%; top: 0; bottom: 0; border-radius: 7px; background: linear-gradient(90deg, rgba(255, 127, 54, .25), rgba(255, 160, 80, .75), rgba(255, 127, 54, .25)); }
.sweet::after { content: ''; position: absolute; left: 50%; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: #fff3d6; box-shadow: 0 0 8px #ffb469; }
.needle { position: absolute; top: -12px; bottom: -12px; width: 4px; margin-left: -2px; border-radius: 2px; background: #fff; box-shadow: 0 0 14px rgba(255, 255, 255, .8); }
.trial-grade { height: 40px; font-size: 32px; font-weight: 900; }

/* 상점 */
.shop { position: absolute; inset: 0; z-index: 9; display: grid; place-content: center; justify-items: center; gap: 18px; }
.shop-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 150px); gap: 10px; }
.shop-grid button {
  width: 100%; display: grid; justify-items: center; gap: 4px; padding: 14px 8px;
  background: rgba(12, 9, 7, .8); border: 1px solid var(--line); border-radius: 12px; transition: transform .15s, border-color .15s, background .15s;
}
.shop-grid button:hover:not(:disabled) { transform: translateY(-3px); border-color: rgba(255, 127, 54, .5); background: rgba(30, 20, 14, .88); }
.shop-grid button:disabled { opacity: .3; }
.shop-grid img { width: 96px; height: 96px; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .6)); }
.shop-grid b { font-weight: 700; font-size: 15px; }
.shop-grid small { color: var(--mute); font-size: 12px; }

/* 정보 패널 */
.stat-panel { grid-column: 3; grid-row: 2; display: grid; gap: 6px; }
.title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.title h2 { margin: 0; font-size: 18px; font-weight: 700; white-space: nowrap; }
.prefix { color: var(--mute); font-size: 13px; cursor: help; white-space: nowrap; }
.lv { font-size: 84px; font-weight: 900; line-height: .95; letter-spacing: -.05em; color: var(--tier); text-shadow: 0 0 calc(10px + var(--lvp) * 40px) color-mix(in srgb, var(--tier) 50%, transparent); transition: color .4s; }
.lv.bump { animation: bump .5s cubic-bezier(.2, 1.6, .4, 1) 1; }
@keyframes bump { 0% { transform: scale(1.35); filter: brightness(2); } }
.lv-title { font-size: 13px; font-weight: 700; color: var(--tier); opacity: .85; margin-top: -2px; }
.cracks { display: flex; gap: 6px; height: 16px; align-items: center; margin-bottom: 6px; }
.crack { width: 26px; height: 5px; border-radius: 3px; background: rgba(237, 226, 204, .13); transform: skewX(-30deg); }
.crack.on { background: var(--blood); box-shadow: 0 0 10px rgba(232, 82, 74, .8); }
.crack.new { animation: crackin .45s ease-out 1; }
@keyframes crackin { 0% { transform: skewX(-30deg) scaleX(2.6); filter: brightness(2.5); } }
.stats { margin: 0; border-top: 1px solid var(--line); }
.stats .row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.stats dt { color: var(--mute); font-size: 13px; }
.stats dd { margin: 0; font-weight: 700; text-align: right; }
.stats .row.big dd { font-size: 26px; font-weight: 900; }
.stats .up { color: #9fd47d; font-weight: 700; font-size: 13px; margin-left: 4px; }
.stats .danger { color: var(--blood); }
.stats .safe { color: var(--mute); font-weight: 600; }
.panel-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.panel-actions.solo { grid-template-columns: 1fr; }

/* 하단 조작 */
.controls { grid-column: 1 / -1; grid-row: 3; position: relative; z-index: 5; display: grid; justify-items: center; gap: 22px; }
.opts { display: flex; gap: 10px; }
.opt { position: relative; width: 64px; height: 72px; display: grid; justify-items: center; align-content: center; gap: 3px; background: rgba(12, 9, 7, .8); border: 1px solid var(--line); border-radius: 10px; transition: border-color .15s, background .15s, transform .15s; }
.opt img { width: 38px; height: 38px; opacity: .5; transition: opacity .15s, transform .15s; }
.opt em { font-style: normal; font-size: 11px; color: var(--mute); white-space: nowrap; font-weight: 600; }
.opt:hover:not(:disabled) { border-color: rgba(237, 226, 204, .28); transform: translateY(-2px); }
.opt[aria-pressed="true"] { border-color: var(--ember); background: rgba(255, 127, 54, .14); box-shadow: 0 0 22px -4px rgba(255, 127, 54, .7); }
.opt[aria-pressed="true"] img { opacity: 1; transform: scale(1.08); }
.opt[aria-pressed="true"] em { color: var(--ember-hot); }
.opt:disabled { opacity: .4; }

.hit {
  min-width: 360px; height: 72px; border: 0; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; gap: 14px;
  font-size: 26px; font-weight: 900; color: #2a1206; letter-spacing: -.02em;
  background: linear-gradient(180deg, #ffa05e 0%, #ef6d27 55%, #c9531a 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .4), inset 0 -3px 0 rgba(0, 0, 0, .28), 0 12px 40px -10px rgba(255, 127, 54, .7);
  transition: transform .06s, filter .15s;
}
.hit small { font-size: 15px; font-weight: 700; opacity: .75; }
.hit:hover:not(:disabled) { filter: brightness(1.08); }
.hit:active:not(:disabled) { transform: translateY(2px) scale(.99); }
.hit:disabled { filter: grayscale(.85) brightness(.5); box-shadow: none; }
.hit.img { width: 420px; height: 154px; margin: -38px 0 -42px; min-width: 0; border-radius: 0; background: var(--btn-image) center / contain no-repeat; box-shadow: none; color: #ffe6c8; text-shadow: 0 2px 0 rgba(0, 0, 0, .8), 0 0 18px rgba(255, 120, 40, .6); }
.hit.img small { color: #f6c095; }
.hit.img:active:not(:disabled) { background-image: var(--btn-pressed); }
.hit.img:not(:disabled) { animation: btnglow 2.4s ease-in-out infinite; }
@keyframes btnglow { 50% { filter: brightness(1.12) drop-shadow(0 0 16px rgba(255, 120, 40, .45)); } }

/* 토스트 */
.toast { position: fixed; left: 50%; top: 76px; transform: translate(-50%, -10px); z-index: 50; padding: 10px 18px; border-radius: 999px; background: rgba(20, 15, 12, .95); border: 1px solid var(--line); font-weight: 600; box-shadow: 0 12px 30px rgba(0, 0, 0, .5); opacity: 0; transition: opacity .15s, transform .15s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(232, 82, 74, .6); }

@media (max-width: 1180px) {
  .scene { grid-template-columns: 230px minmax(0, 1fr) 250px; padding: 16px 20px 22px; gap: 0 18px; }
  .lv { font-size: 68px; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  #game, .scene { height: auto; min-height: 100vh; }
  .scene { display: flex; flex-direction: column; gap: 12px; padding: 12px 14px 24px; overflow: visible; }
  .hud { grid-template-columns: auto 1fr auto; }
  .brand { display: none; }
  .wallet { justify-content: flex-start; }
  .me span { display: none; }
  .forge { height: 340px; flex: none; }
  .weapon { width: 320px; }
  .stat-panel { order: 3; }
  .controls { order: 4; }
  .rank-panel { order: 5; max-height: none; }
  .lv { font-size: 60px; }
  .hit { min-width: 0; width: 100%; }
  .hit.img { width: 100%; height: 130px; margin: -30px 0 -34px; }
  .shop-grid { grid-template-columns: repeat(3, 1fr); width: 100%; }
  .shop-grid img { width: 72px; height: 72px; }
}
@media (prefers-reduced-motion: reduce) {
  .weapon, .rays, .glow, .crack-overlay, .hit.img, .orbit { animation: none !important; }
}
