:root {
  --ink: #101318;
  --paper: #f9f0d2;
  --sand: #d8ad64;
  --gold: #ffc431;
  --teal: #25c7d9;
  --red: #f24c3d;
  --orange: #ff8b23;
  --panel: rgba(17, 21, 28, 0.9);
  --line: rgba(255, 255, 255, 0.16);
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 5%, rgba(255, 196, 49, 0.2), transparent 28%),
    radial-gradient(circle at 88% 12%, rgba(37, 199, 217, 0.18), transparent 26%),
    linear-gradient(135deg, #171b24 0%, #24201d 47%, #101318 100%);
  color: #fff7df;
  font-family: Avenir Next, Trebuchet MS, Verdana, sans-serif;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
}

.game-shell {
  width: min(1480px, 100vw);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.topbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 62% 31%, #fff 0 10%, #ffd65d 11% 20%, transparent 21%),
    linear-gradient(145deg, #111 0 55%, #2d2f35 56%),
    linear-gradient(#ffc431 0 0);
  border: 3px solid #ffc431;
  box-shadow: 0 0 0 5px rgba(255, 196, 49, 0.14);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 38px);
  line-height: 0.9;
  letter-spacing: 0;
}

.brand p {
  margin-top: 5px;
  color: rgba(255, 247, 223, 0.68);
  font-size: 13px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 8px;
}

.metric {
  min-width: 92px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
}

.metric span {
  display: block;
  color: rgba(255, 247, 223, 0.64);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 2px;
  font-size: 22px;
  line-height: 1;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-btn,
.fight-btn,
.weapon-card,
.skill-buttons button {
  border: 0;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, background 0.15s ease;
}

.icon-btn {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.32);
  font-weight: 800;
}

.icon-btn:hover,
.fight-btn:hover,
.weapon-card:hover,
.skill-buttons button:active {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.play-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 322px minmax(0, 1fr);
  gap: 12px;
}

.shop-panel {
  min-height: 0;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h2 {
  font-size: 18px;
}

.fight-btn {
  min-width: 92px;
  height: 42px;
  padding: 0 18px;
  color: #16140d;
  background: linear-gradient(180deg, #ffdf74, #ffad22);
  font-weight: 900;
  box-shadow: 0 8px 0 #9a5b12, 0 14px 28px rgba(0, 0, 0, 0.24);
}

.weapon-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.weapon-card {
  width: 100%;
  min-height: 70px;
  padding: 10px;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
}

.weapon-card.is-selected {
  border-color: var(--gold);
  background: rgba(255, 196, 49, 0.17);
}

.weapon-card.is-locked {
  color: rgba(255, 247, 223, 0.72);
}

.weapon-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #141820;
  background: var(--paper);
  border: 2px solid rgba(255, 255, 255, 0.22);
  font-size: 22px;
  font-weight: 900;
}

.weapon-copy strong,
.weapon-copy span {
  display: block;
}

.weapon-copy strong {
  font-size: 14px;
}

.weapon-copy span {
  margin-top: 3px;
  color: rgba(255, 247, 223, 0.58);
  font-size: 12px;
}

.weapon-price {
  min-width: 60px;
  color: var(--gold);
  font-weight: 900;
  text-align: right;
}

.tips {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px 10px;
  color: rgba(255, 247, 223, 0.72);
  font-size: 12px;
}

kbd {
  min-width: 62px;
  padding: 5px 7px;
  display: inline-block;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  text-align: center;
  font-family: inherit;
  font-weight: 800;
}

.arena-wrap {
  min-width: 0;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: #20170f;
  box-shadow: var(--shadow);
  contain: layout paint;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  image-rendering: auto;
}

.hp-card {
  position: absolute;
  z-index: 3;
  left: 18px;
  top: 18px;
  width: min(330px, calc(100% - 36px));
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(16, 19, 24, 0.78);
  backdrop-filter: blur(12px);
}

.hp-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 900;
}

.hp-track {
  height: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(242, 76, 61, 0.72);
}

.hp-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #58e66d, #f6dc55);
  transition: width 0.18s ease, filter 0.18s ease;
}

.message {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 22px;
  width: min(520px, calc(100% - 38px));
  padding: 13px 16px;
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(16, 19, 24, 0.82);
  text-align: center;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.message.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.message strong,
.message span {
  display: block;
}

.message strong {
  font-size: 18px;
}

.message span {
  margin-top: 4px;
  color: rgba(255, 247, 223, 0.72);
  font-size: 13px;
}

.mobile-controls {
  display: none;
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .game-shell {
    height: auto;
    min-height: 100dvh;
    gap: 8px;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 8px 10px;
  }

  .status-grid {
    grid-column: 1 / -1;
    width: 100%;
    gap: 6px;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .shop-panel {
    order: 2;
    max-height: 330px;
    padding: 12px;
  }

  .arena-wrap {
    min-height: min(62vh, 560px);
  }

  .mobile-controls {
    position: absolute;
    z-index: 5;
    inset: auto 14px 14px 14px;
    display: flex;
    justify-content: space-between;
    align-items: end;
    pointer-events: none;
  }

  .stick-zone {
    width: 112px;
    height: 112px;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.2);
    pointer-events: auto;
    touch-action: none;
  }

  .stick-zone span {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 48px;
    height: 48px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgba(255, 196, 49, 0.82);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  }

  .skill-buttons {
    display: flex;
    gap: 10px;
    pointer-events: auto;
  }

  .skill-buttons button {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    color: #15130d;
    background: #ffd25b;
    font-weight: 900;
    box-shadow: 0 8px 0 #87520f;
  }

  .message {
    bottom: 140px;
    width: calc(100% - 28px);
    padding: 10px 12px;
  }

  .message strong {
    font-size: 16px;
  }

  .message span {
    font-size: 12px;
  }
}

@media (max-width: 560px) {
  .game-shell {
    padding: 8px;
  }

  .topbar {
    min-height: 60px;
    padding: 8px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand p {
    display: none;
  }

  .status-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .metric {
    min-width: 0;
    padding: 6px 8px;
  }

  .metric span {
    font-size: 11px;
  }

  .metric strong {
    font-size: 17px;
  }

  .arena-wrap {
    min-height: 56vh;
  }

  .hp-card {
    left: 10px;
    top: 10px;
    width: calc(100% - 20px);
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }

  .weapon-card {
    min-height: 62px;
    grid-template-columns: 38px 1fr auto;
  }

  .weapon-icon {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  body {
    overflow: hidden;
  }

  .game-shell {
    height: 100dvh;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    min-height: 50px;
    grid-template-columns: auto minmax(240px, 1fr) auto;
  }

  .brand p {
    display: none;
  }

  h1 {
    font-size: 24px;
  }

  .status-grid {
    grid-column: auto;
    grid-template-columns: repeat(3, minmax(74px, 1fr));
  }

  .metric {
    padding: 5px 8px;
  }

  .metric strong {
    font-size: 16px;
  }

  .play-layout {
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 0;
  }

  .shop-panel {
    order: 0;
    max-height: none;
    min-height: 0;
  }

  .arena-wrap {
    min-height: 0;
  }

  .message {
    bottom: 12px;
    width: min(460px, calc(100% - 210px));
  }
}
