:root {
  color-scheme: dark;
  font-family: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --paper: #f8ebd7;
  --muted: #bcb4a8;
  --gold: #ffbc79;
  --slot-edge: #61504a;
  --fire-hue: #ff8049;
  color: var(--paper);
  background: #0d1418;
  -webkit-text-size-adjust: 100%;
  font-synthesis: none;
}
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 50%, #334043 0%, #182327 40%, #0b1116 78%);
}
h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid #ffce91; outline-offset: 3px; }
img { display: block; image-rendering: pixelated; user-select: none; -webkit-user-drag: none; }
[hidden] { display: none !important; }
.game {
  width: min(100%, 520px);
  height: 100vh; height: 100svh;
  min-height: 454px;
  display: grid;
  grid-template-rows: auto minmax(150px, 1fr) auto;
  isolation: isolate;
  background: #1a1e22;
  box-shadow: 0 12px 90px #000b;
}
.masthead {
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) max(17px, env(safe-area-inset-right)) 14px max(17px, env(safe-area-inset-left));
  background: linear-gradient(115deg, #2f292a, #242529 65%);
  border-bottom: 2px solid #684a3d;
  box-shadow: 0 3px 0 #14191b90;
}
.identity, .header-actions, .target-line, .bench-heading { display: flex; align-items: center; }
.identity { gap: 11px; }
.crest {
  display: grid; place-items: center;
  width: 43px; height: 43px;
  border: 1px solid #805b42;
  box-shadow: inset 0 0 0 3px #2e2626, inset 0 0 0 4px #503a31;
  background: #382b28;
  border-radius: 7px;
}
.crest img { width: 27px; height: auto; }
h1 { font-weight: 850; font-size: clamp(22px, 5.3vw, 27px); line-height: 1.08; letter-spacing: -.055em; }
.location { margin-top: 4px; color: #d3b59b; font-size: 12px; font-weight: 620; }
.header-actions { gap: 10px; }
.damage-meter { display: flex; align-items: center; gap: 8px; padding: 5px 10px; background: #191b20; border: 1px solid #474143; border-radius: 5px; color: #ebd9c6; }
.damage-meter span { font-size: 12px; white-space: nowrap; }
.damage-meter strong { font-size: 18px; color: #ffc68d; font-variant-numeric: tabular-nums; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; background: transparent; border: 0; border-radius: 6px; color: #d7c7b5; }
.icon-button:active { background: #3c3432; }
.sound-off, .icon-button[aria-pressed="false"] .sound-on { display: none; }
.icon-button[aria-pressed="false"] .sound-off { display: block; }
.arena { position: relative; overflow: hidden; min-height: 0; isolation: isolate; background: #36313a; }
.ground, .ground::after { position: absolute; inset: 0; }
.ground {
  z-index: -2;
  background: center / cover no-repeat url("assets/clearing.png");
  image-rendering: pixelated;
}
.ground::after { content: ""; background: linear-gradient(#0c171c48, transparent 28%, transparent 69%, #191b294a); }
.arena-hud { position: absolute; z-index: 4; top: 15px; inset-inline: 15px; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; pointer-events: none; }
.target, .kill-counter, #battle-result:not(:empty) {
  border: 1px solid #9f989035; border-radius: 5px;
  background: #161c20ee; box-shadow: 0 2px 0 #0f181c73;
}
.target { min-width: 145px; max-width: 70%; padding: 7px 9px 8px; }
.target-line { gap: 5px; line-height: 1; }
.target-line img { width: 19px; height: 19px; }
.target-line strong { font-size: 12px; white-space: nowrap; }
.target-line span { margin-left: auto; padding-left: 8px; color: #c8c0b7; font-size: 11px; font-variant-numeric: tabular-nums; }
.hp-track { height: 4px; margin-top: 5px; background: #514048; }
#hp-fill { display: block; width: 100%; height: 100%; background: #ea8a6e; transform-origin: left; transition: transform .12s ease-out; }
.kill-counter { padding: 5px 9px; display: flex; gap: 6px; align-items: center; color: #cbbfb4; font-size: 12px; }
.kill-counter strong { color: #f6e7ce; font-size: 13px; font-variant-numeric: tabular-nums; }
.fire-place, .firelight, #ring { position: absolute; left: 50%; top: 50%; pointer-events: none; }
.fire-place { z-index: 1; width: var(--hero-size, 69px); transform: translate(-50%, -50%); }
.fire-place img { position: relative; width: 100%; height: auto; transform-origin: bottom center; animation: flicker 1.1s steps(2, end) infinite; }
.shadow { position: absolute; left: 15%; bottom: 3%; width: 70%; height: 15%; background: #18151b7a; border-radius: 50%; }
.firelight {
  z-index: -1; width: calc(var(--hero-size, 69px) * 3); aspect-ratio: 1;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse, color-mix(in srgb, var(--fire-hue) 30%, transparent), transparent 64%);
}
#ring { width: var(--ring-size, 195px); aspect-ratio: 1; border: 2px solid var(--fire-hue); border-radius: 50%; transform: translate(-50%, -50%) scale(.2); opacity: 0; }
#enemy { position: absolute; top: 0; left: 0; width: var(--mob-size, 39px); will-change: transform; }
#enemy img { width: 100%; }
#spark-field { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.ember { position: absolute; top: 50%; left: 50%; width: 3px; height: 3px; background: var(--fire-hue); opacity: 0; animation: rise 2.4s linear infinite; }
.arena-foot { position: absolute; z-index: 3; left: 0; right: 0; bottom: 11px; display: flex; justify-content: center; pointer-events: none; }
#battle-result:not(:empty) { padding: 5px 11px; color: #eddfce; font-size: 12px; white-space: nowrap; }
.workbench {
  z-index: 3; padding: 16px max(17px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(17px, env(safe-area-inset-left));
  background: linear-gradient(120deg, #2f2c30, #24252a 90%);
  border-top: 2px solid #745442; box-shadow: 0 -3px 0 #19181c55;
}
.bench-heading { justify-content: space-between; margin-bottom: 12px; }
h2 { font-size: 19px; letter-spacing: -.04em; font-weight: 770; }
.merge-count { color: #b9afa5; font-size: 12px; }
.merge-count b { margin-left: 3px; color: #edcfaa; font-variant-numeric: tabular-nums; }
.slots { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.slot {
  min-width: 0; height: clamp(78px, 12svh, 108px); padding: 5px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(150deg, #463a36, #3b3234);
  border: 1px solid var(--slot-edge); border-bottom: 3px solid #211d22;
  box-shadow: inset 0 1px #6c534480; border-radius: 7px;
  touch-action: none; user-select: none; -webkit-user-select: none;
  transition: background .12s, border-color .12s;
}
.slot:hover { border-color: #aa7f62; }
.slot[aria-pressed="true"], .slot.drop-target { border-color: #edb77b; background: #5d473b; box-shadow: inset 0 0 0 1px #c99566; }
.slot.dragging .slot-image img { opacity: .30; }
.slot-image { width: clamp(32px, 8vw, 42px); height: 46px; flex-shrink: 0; display: grid; place-items: center; }
.slot-image img { width: 100%; max-height: 100%; object-fit: contain; }
.slot-image i { display: none; font: 400 29px/1 system-ui; color: #f6bb85; }
.slot-copy { min-width: 0; display: grid; text-align: left; gap: 3px; }
.slot-copy small { font-size: 11px; color: #dbac86; font-variant-numeric: tabular-nums; }
.slot-copy strong { font-size: clamp(13px, 3.5vw, 16px); font-weight: 700; }
.slot[data-level="0"] { border-style: dashed; border-width: 1px; background: #29272b; }
.slot[data-level="0"] .slot-image { width: 26px; }
.slot[data-level="0"] .slot-image img { display: none; }
.slot[data-level="0"] .slot-image i { display: block; }
.slot:disabled { color: var(--muted); cursor: default; }
#merge-result { min-height: 24px; display: grid; align-items: end; color: #f1b67c; font-size: 12px; }
#drag-fire, #flying-fire { position: fixed; z-index: 10; width: 50px; height: auto; pointer-events: none; }
#drag-fire { filter: drop-shadow(0 2px 5px #321a1580); }
@keyframes flicker { 50% { transform: translateY(-1px) scale(.97,1.025); } }
@keyframes rise { 0% { opacity: 0; transform: translate(var(--x), -17px); } 20% { opacity: .7; } 85% { opacity: .45; } 100% { opacity: 0; transform: translate(var(--drift), -68px); } }
@media (min-width: 600px) and (min-height: 650px) {
  .game { height: min(90svh, 880px); border: 1px solid #60504b; border-radius: 12px; overflow: hidden; }
  .masthead { padding: 17px 22px; }
  .workbench { padding: 19px 21px 13px; }
}
@media (max-height: 590px) and (orientation: portrait) {
  .masthead { padding-block: max(7px, env(safe-area-inset-top)) 7px; }
  .workbench { padding-top: 10px; }
  .bench-heading { margin-bottom: 7px; }
  .slot { height: 68px; }
}
@media (orientation: landscape) and (max-height: 590px) {
  .game { width: min(100%, 930px); height: 100svh; min-height: 280px; grid-template-columns: 1.45fr 1fr; grid-template-rows: auto 1fr; }
  .masthead { grid-column: 1 / -1; padding-block: max(5px, env(safe-area-inset-top)) 5px; }
  .arena { grid-column: 1; }
  .workbench { grid-column: 2; border-top: 0; border-left: 2px solid #674b40; padding: 10px; display: flex; flex-flow: column; justify-content: center; }
  .slot { min-height: 73px; height: auto; flex-direction: column; gap: 0; }
  .slot-image { height: 35px; width: 31px; }
  .slot-copy { text-align: center; gap: 0; }
  .arena-hud { inset-inline: 8px; top: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
