:root {
  --bg: #111015;
  --panel: rgba(28, 25, 32, 0.88);
  --panel-strong: #211b27;
  --gold: #e6bd60;
  --gold-bright: #ffd979;
  --text: #f5ead6;
  --muted: #b9a98f;
  --red: #ef6666;
  --green: #61db91;
  --blue: #63b3ff;
  --purple: #bb7dff;
  --border: rgba(230, 189, 96, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Trebuchet MS", "Malgun Gothic", sans-serif;
  background:
    radial-gradient(circle at 20% 10%, rgba(134, 80, 30, 0.26), transparent 28%),
    radial-gradient(circle at 80% 30%, rgba(89, 72, 126, 0.24), transparent 30%),
    linear-gradient(135deg, #0d0b0f 0%, #1c151a 52%, #121017 100%);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

.particle-field {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(255, 223, 148, 0.42) 0 1px, transparent 2px),
    radial-gradient(circle, rgba(122, 183, 255, 0.22) 0 1px, transparent 2px);
  background-size: 74px 74px, 113px 113px;
  animation: drift 18s linear infinite;
  opacity: 0.38;
}

.game-shell {
  position: relative;
  width: min(1280px, calc(100% - 28px));
  margin: 18px auto 80px;
}

.top-bar,
.forge-panel,
.shop-panel,
.inventory-panel,
.stats-panel,
.log-panel,
.modal-card {
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(10px);
}

.top-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 14px;
  border-radius: 8px;
}

.top-bar div,
.detail-grid div,
.stats-grid div {
  min-width: 0;
  padding: 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.045);
}

.label,
.detail-grid span,
.stats-grid span,
.auto-panel label {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

strong {
  color: var(--gold-bright);
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  margin-top: 16px;
}

.forge-panel,
.shop-panel,
.inventory-panel,
.stats-panel,
.log-panel {
  border-radius: 8px;
  padding: 16px;
}

.selected-card {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 240px;
  align-items: center;
  gap: 16px;
}

.sword-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 360px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent),
    radial-gradient(circle, rgba(230, 189, 96, 0.16), transparent 58%);
  overflow: hidden;
}

.sword-stage::before,
.sword-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 2;
}

.sword-stage.legendary-glow {
  box-shadow: inset 0 0 70px rgba(255, 200, 70, 0.28), 0 0 36px rgba(224, 55, 42, 0.24);
}

.sword-svg {
  width: min(74%, 420px);
  height: auto;
  filter: drop-shadow(0 18px 25px rgba(0, 0, 0, 0.45));
  overflow: visible;
}

.sword-svg .sword-aura {
  transform-origin: 100px 132px;
}

.sword-rare .sword-aura {
  animation: auraPulse 2.8s ease-in-out infinite;
}

.sword-epic .sword-aura {
  animation: auraPulse 2.1s ease-in-out infinite;
}

.sword-legendary {
  animation: legendaryFloat 2.5s ease-in-out infinite;
}

.sword-legendary .sword-aura {
  animation: legendaryAura 1.5s ease-in-out infinite;
}

.sword-stage.shake .sword-svg,
.sword-stage.shake .sword-legendary {
  animation: shake 420ms ease-in-out;
}

.sword-stage.success .impact-ring {
  animation: burst 650ms ease-out;
  border-color: rgba(118, 255, 174, 0.92);
}

.sword-stage.fail .impact-ring {
  animation: crack 650ms ease-out;
  border-color: rgba(255, 83, 83, 0.9);
}

.sword-stage.destroy .sword-svg {
  animation: shatter 760ms ease-in forwards;
}

.sword-stage.destroy::before {
  background:
    linear-gradient(42deg, transparent 47%, rgba(255, 50, 50, 0.95) 48% 50%, transparent 51%),
    linear-gradient(-28deg, transparent 43%, rgba(255, 120, 90, 0.84) 44% 46%, transparent 47%),
    linear-gradient(105deg, transparent 56%, rgba(255, 40, 40, 0.78) 57% 59%, transparent 60%),
    radial-gradient(circle, rgba(255, 0, 0, 0.32), transparent 62%);
  animation: destroyCracks 820ms ease-out;
}

.sword-stage.destroy::after {
  border: 5px solid rgba(255, 42, 42, 0.88);
  border-radius: 999px;
  margin: auto;
  width: 120px;
  height: 120px;
  inset: 0;
  box-shadow: 0 0 36px rgba(255, 40, 40, 0.8), inset 0 0 24px rgba(255, 40, 40, 0.55);
  animation: destroyShockwave 820ms ease-out;
}

.sword-stage.sell::before {
  background:
    radial-gradient(circle at 50% 48%, rgba(255, 226, 125, 0.88), transparent 18%),
    radial-gradient(circle at 34% 62%, rgba(255, 199, 58, 0.58), transparent 9%),
    radial-gradient(circle at 67% 36%, rgba(255, 239, 170, 0.64), transparent 8%),
    radial-gradient(circle, rgba(255, 190, 73, 0.28), transparent 62%);
  animation: sellGlow 760ms ease-out;
}

.sword-stage.sell::after {
  content: "G  ✦  G  ✦  G";
  display: grid;
  place-items: center;
  color: #ffdf76;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 12px;
  text-shadow: 0 0 14px rgba(255, 199, 80, 0.95), 0 0 34px rgba(255, 162, 36, 0.8);
  animation: sellCoins 760ms ease-out;
}

.impact-ring {
  position: absolute;
  width: 90px;
  height: 90px;
  border: 3px solid transparent;
  border-radius: 999px;
  opacity: 0;
}

.empty-sword {
  color: var(--muted);
  font-size: 22px;
}

.selected-name {
  margin: 0;
  color: var(--muted);
}

.sword-info h1 {
  margin: 6px 0 12px;
  font-size: 74px;
  line-height: 1;
  color: var(--gold-bright);
  text-shadow: 0 0 24px rgba(230, 189, 96, 0.35);
}

.grade-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 118px;
  padding: 9px 12px;
  border-radius: 999px;
  font-weight: 800;
  border: 1px solid currentColor;
}

.common { color: #d8d4cc; }
.rare { color: #6cbcff; }
.epic { color: #c184ff; }
.legendary { color: #ffcd62; text-shadow: 0 0 14px rgba(255, 68, 47, 0.7); }

.detail-grid,
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.auto-panel {
  margin-top: 14px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.auto-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.auto-controls input {
  width: 110px;
  padding: 12px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #16131a;
}

.auto-controls .btn {
  flex: 1 1 150px;
}

.repeat-toggle,
.keep-grade-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--text);
}

.repeat-toggle {
  cursor: pointer;
  user-select: none;
}

.repeat-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
}

.keep-grade-control {
  margin-left: 16px;
}

.keep-grade-control select {
  min-height: 34px;
  padding: 6px 10px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #16131a;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.btn,
.shop-item {
  min-height: 50px;
  padding: 12px 14px;
  color: #21170a;
  font-weight: 900;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  background: linear-gradient(180deg, #f5d37a, #b77b28);
  box-shadow: 0 7px 0 #684316, 0 14px 28px rgba(0, 0, 0, 0.28);
  transition: transform 150ms ease, filter 150ms ease, opacity 150ms ease;
}

.btn:hover,
.shop-item:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.btn:active,
.shop-item:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #684316, 0 8px 18px rgba(0, 0, 0, 0.24);
}

.btn:disabled,
.shop-item:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.btn.primary {
  background: linear-gradient(180deg, #ffde8a, #d38a28);
}

.btn.secondary {
  color: var(--text);
  background: linear-gradient(180deg, #4f465b, #272230);
  box-shadow: 0 7px 0 #17131d, 0 14px 28px rgba(0, 0, 0, 0.28);
}

.btn.danger {
  color: #fff4ef;
  background: linear-gradient(180deg, #d86454, #8b2e2b);
  box-shadow: 0 7px 0 #501b1c, 0 14px 28px rgba(0, 0, 0, 0.28);
}

.side-column {
  display: grid;
  gap: 16px;
}

.shop-panel h2,
.inventory-panel h2,
.stats-panel h2,
.log-panel h2 {
  margin: 0 0 12px;
  color: var(--gold-bright);
  font-size: 20px;
}

.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: 10px;
  color: var(--text);
  background: linear-gradient(180deg, #3a3343, #221c29);
  box-shadow: 0 6px 0 #141018, 0 12px 24px rgba(0, 0, 0, 0.24);
}

.shop-item.accent {
  border: 1px solid rgba(112, 193, 255, 0.35);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title span {
  color: var(--muted);
}

.inventory-list {
  display: grid;
  gap: 8px;
  max-height: 460px;
  overflow: auto;
  padding-right: 4px;
}

.inventory-item {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.045);
  cursor: pointer;
}

.inventory-item.selected {
  border-color: var(--gold);
  background: rgba(230, 189, 96, 0.13);
}

.mini-sword {
  width: 48px;
  height: 48px;
}

.item-title {
  display: block;
  font-weight: 800;
}

.item-sub {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.lower-grid {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 16px;
  margin-top: 16px;
}

.stats-grid {
  grid-template-columns: repeat(2, 1fr);
  margin-top: 0;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  height: 210px;
  overflow: auto;
}

.log-entry {
  padding: 8px 10px;
  border-left: 4px solid var(--gold);
  border-radius: 4px;
  color: #e8dcc9;
  background: rgba(255, 255, 255, 0.045);
  font-size: 14px;
}

.log-success { border-left-color: var(--green); }
.log-fail { border-left-color: var(--red); }
.log-destroy { border-left-color: #ff3030; color: #ffd1d1; }
.log-buy { border-left-color: var(--blue); }
.log-sell { border-left-color: var(--gold); }
.log-legendary { border-left-color: #ffcf5a; color: #ffe4a3; }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
  z-index: 20;
}

.modal.hidden,
.hidden {
  display: none;
}

.modal-card {
  width: min(460px, 100%);
  padding: 24px;
  border-radius: 8px;
  text-align: center;
}

.modal-card h2 {
  margin: 0 0 10px;
  color: var(--gold-bright);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

.volume-control {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(18, 15, 22, 0.92);
  z-index: 10;
}

.volume-control input {
  width: 130px;
}

@keyframes drift {
  from { background-position: 0 0, 0 0; }
  to { background-position: 240px 420px, -260px 310px; }
}

@keyframes shake {
  0%, 100% { transform: rotate(0deg) translateX(0); }
  18% { transform: rotate(-3deg) translateX(-7px); }
  36% { transform: rotate(4deg) translateX(8px); }
  55% { transform: rotate(-2deg) translateX(-5px); }
  74% { transform: rotate(2deg) translateX(4px); }
}

@keyframes burst {
  0% { opacity: 0.95; transform: scale(0.2); box-shadow: 0 0 18px currentColor; }
  100% { opacity: 0; transform: scale(5); box-shadow: 0 0 80px currentColor; }
}

@keyframes crack {
  0% { opacity: 0.95; transform: scale(0.2) rotate(0deg); box-shadow: 0 0 16px rgba(255, 50, 50, 0.9); }
  100% { opacity: 0; transform: scale(4.2) rotate(26deg); box-shadow: 0 0 58px rgba(255, 50, 50, 0.8); }
}

@keyframes shatter {
  0% { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; filter: saturate(1.2); }
  45% { transform: translateY(12px) rotate(9deg) scale(0.95); opacity: 0.8; filter: saturate(2) hue-rotate(-30deg); }
  100% { transform: translateY(110px) rotate(-18deg) scale(0.28); opacity: 0; filter: blur(2px); }
}

@keyframes destroyCracks {
  0% { opacity: 0; transform: scale(0.72) rotate(-3deg); filter: brightness(1); }
  28% { opacity: 1; transform: scale(1.02) rotate(1deg); filter: brightness(1.8); }
  100% { opacity: 0; transform: scale(1.28) rotate(4deg); filter: brightness(0.8) blur(1px); }
}

@keyframes destroyShockwave {
  0% { opacity: 0.95; transform: scale(0.22); }
  100% { opacity: 0; transform: scale(5.4); }
}

@keyframes sellGlow {
  0% { opacity: 0; transform: scale(0.7); filter: brightness(1); }
  32% { opacity: 1; transform: scale(1.04); filter: brightness(1.55); }
  100% { opacity: 0; transform: scale(1.32); filter: brightness(0.9); }
}

@keyframes sellCoins {
  0% { opacity: 0; transform: translateY(28px) scale(0.72); }
  24% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-78px) scale(1.18); }
}

@keyframes auraPulse {
  0%, 100% { transform: scale(0.96); opacity: 0.72; }
  50% { transform: scale(1.08); opacity: 1; }
}

@keyframes legendaryFloat {
  0%, 100% { transform: translateY(0) rotate(-0.6deg); }
  50% { transform: translateY(-8px) rotate(0.6deg); }
}

@keyframes legendaryAura {
  0%, 100% { transform: scale(0.94) rotate(0deg); opacity: 0.78; }
  50% { transform: scale(1.14) rotate(4deg); opacity: 1; }
}

@media (max-width: 980px) {
  .top-bar,
  .main-grid,
  .lower-grid,
  .selected-card {
    grid-template-columns: 1fr;
  }

  .top-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .action-row,
  .detail-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .sword-stage {
    min-height: 300px;
  }
}

@media (max-width: 560px) {
  .game-shell {
    width: min(100% - 18px, 1280px);
    margin: 8px auto 18px;
  }

  .top-bar {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 8px;
  }

  .top-bar div,
  .detail-grid div,
  .stats-grid div {
    padding: 8px;
  }

  .label,
  .detail-grid span,
  .stats-grid span,
  .auto-panel label {
    font-size: 11px;
  }

  .top-bar strong,
  .detail-grid strong,
  .stats-grid strong {
    font-size: 14px;
  }

  .main-grid,
  .lower-grid,
  .side-column {
    gap: 8px;
    margin-top: 8px;
  }

  .forge-panel,
  .shop-panel,
  .inventory-panel,
  .stats-panel,
  .log-panel {
    padding: 10px;
  }

  .selected-card {
    grid-template-columns: minmax(0, 1fr) 104px;
    gap: 8px;
  }

  .sword-stage {
    min-height: 205px;
  }

  .sword-stage.sell::after {
    font-size: 20px;
    letter-spacing: 7px;
  }

  .sword-svg {
    width: min(90%, 250px);
  }

  .sword-info h1 {
    font-size: 42px;
    margin: 4px 0 8px;
  }

  .selected-name {
    font-size: 13px;
  }

  .grade-pill {
    min-width: 92px;
    padding: 7px 8px;
    font-size: 12px;
  }

  .detail-grid,
  .action-row,
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-top: 8px;
  }

  .auto-panel {
    margin-top: 8px;
    padding: 9px;
  }

  .auto-controls {
    display: grid;
    grid-template-columns: 74px 1fr 1fr;
    gap: 6px;
  }

  .auto-controls input {
    width: 100%;
    padding: 10px 8px;
  }

  .auto-controls .btn {
    min-width: 0;
    min-height: 44px;
    padding: 8px 6px;
    font-size: 12px;
  }

  .repeat-toggle,
  .keep-grade-control {
    margin-top: 7px;
    font-size: 12px;
  }

  .keep-grade-control {
    margin-left: 8px;
  }

  .keep-grade-control select {
    min-height: 30px;
    max-width: 104px;
    padding: 4px 6px;
    font-size: 12px;
  }

  .btn,
  .shop-item {
    min-height: 44px;
    padding: 9px 10px;
    box-shadow: 0 4px 0 #684316, 0 10px 18px rgba(0, 0, 0, 0.22);
  }

  .shop-panel h2,
  .inventory-panel h2,
  .stats-panel h2,
  .log-panel h2 {
    margin-bottom: 8px;
    font-size: 16px;
  }

  .shop-item {
    margin-top: 6px;
    font-size: 13px;
  }

  .inventory-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 190px;
    gap: 6px;
  }

  .inventory-item {
    grid-template-columns: 34px 1fr;
    gap: 6px;
    padding: 7px;
  }

  .inventory-item > strong {
    display: none;
  }

  .mini-sword {
    width: 34px;
    height: 34px;
  }

  .item-title {
    font-size: 12px;
  }

  .item-sub {
    font-size: 10px;
  }

  .log-list {
    height: 118px;
  }

  .log-entry {
    padding: 6px 8px;
    font-size: 12px;
  }

  .modal-card {
    padding: 18px;
  }

  .volume-control {
    position: static;
    width: min(100% - 18px, 1280px);
    margin: 8px auto 14px;
    justify-content: space-between;
    padding: 8px 10px;
  }
}

@media (max-width: 390px) {
  .selected-card {
    grid-template-columns: 1fr;
  }

  .sword-stage {
    min-height: 190px;
  }

  .sword-info {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 8px;
  }

  .sword-info h1 {
    font-size: 34px;
  }

  .auto-controls {
    grid-template-columns: 68px 1fr;
  }

  .auto-controls .btn {
    grid-column: span 1;
  }
}
