:root {
  color-scheme: dark;
  --bg: #111c22;
  --surface: rgba(15, 27, 34, 0.92);
  --surface-strong: rgba(20, 35, 44, 0.97);
  --border: rgba(235, 197, 108, 0.34);
  --text: #f3f7f5;
  --muted: #a6bec4;
  --gold: #f2c057;
  --emerald: #3be3a4;
  --crimson: #ff4c65;
  --cyan: #5ce8ff;
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

[hidden] {
  display: none !important;
}

#arena {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

.topbar {
  position: fixed;
  z-index: 12;
  top: max(12px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.topbar a,
.topbar button {
  pointer-events: auto;
}

.home-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(15, 27, 34, 0.85);
  border: 1px solid var(--border);
}

.home-btn img {
  display: block;
  border-radius: 6px;
}

.wordmark {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.65);
}

.top-actions {
  margin-left: auto;
  display: flex;
  gap: 7px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: rgba(15, 27, 34, 0.86);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn[aria-pressed="true"] {
  background: var(--emerald);
  color: #0e231e;
  border-color: transparent;
}

.hud {
  position: fixed;
  z-index: 4;
  top: max(56px, calc(env(safe-area-inset-top) + 46px));
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100% - 28px));
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.hud-pill {
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(12, 23, 30, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
}

.hud-lv {
  color: var(--cyan);
}

.hud-gold {
  color: var(--gold);
}

.xp-bar {
  height: 5px;
  border-radius: 999px;
  background: rgba(12, 23, 30, 0.78);
  overflow: hidden;
  border: 1px solid rgba(92, 232, 255, 0.28);
}

.xp-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8, #5ce8ff);
  transition: width 0.15s ease;
}

.hp-wrap {
  position: relative;
  height: 17px;
  border-radius: 999px;
  background: rgba(12, 23, 30, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

.hp-bar {
  width: 100%;
  height: 100%;
}

.hp-bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  transition: width 0.14s ease;
}

.hp-wrap.low .hp-bar i {
  background: linear-gradient(90deg, #ef4444, #f97316);
}

.hp-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 900;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  font-variant-numeric: tabular-nums;
}

.boss-hud {
  margin-top: 4px;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(28, 12, 18, 0.86);
  border: 1px solid rgba(255, 76, 101, 0.55);
}

.boss-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 11px;
  margin-bottom: 4px;
}

.boss-meta span {
  color: var(--gold);
  font-weight: 850;
  letter-spacing: 0.08em;
}

.boss-bar {
  height: 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.boss-bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #dc2626, #fb7185);
  transition: width 0.12s ease;
}

.toast {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  pointer-events: none;
  max-width: calc(100% - 28px);
  text-align: center;
}

.toast:not(:empty) {
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(14, 29, 36, 0.9);
  border: 1px solid var(--emerald);
  color: #e9fff7;
  font-size: 12.5px;
  font-weight: 800;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

.joystick {
  position: fixed;
  z-index: 3;
  pointer-events: none;
  width: 112px;
  height: 112px;
  transform: translate(-50%, -50%);
}

.joy-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.34);
  background: rgba(16, 32, 40, 0.26);
}

.joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #d6fff0, #3be3a4);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

/* Overlays */
.overlay-root {
  position: fixed;
  z-index: 10;
  inset: 0;
  background: rgba(8, 15, 20, 0.64);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(56px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  overflow-y: auto;
  touch-action: pan-y;
}

.overlay-card {
  width: min(500px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--surface-strong);
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 20px 18px;
  box-shadow: 0 24px 54px rgba(0, 0, 0, 0.55);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  color: var(--gold);
  text-transform: uppercase;
}

.overlay-card h1,
.overlay-card h2 {
  margin: 0 0 8px;
  font-size: clamp(24px, 6vw, 36px);
  line-height: 1.08;
  font-weight: 900;
}

.overlay-card p {
  margin: 6px 0 14px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--muted);
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 12px;
}

.mode-btn,
.btn {
  border-radius: 12px;
  padding: 10px 14px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 800;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  transition: transform 0.1s ease, background 0.15s ease;
}

.mode-btn:active,
.btn:active {
  transform: scale(0.97);
}

.mode-btn.active,
.btn.primary {
  background: linear-gradient(135deg, #2dd4a0, #16a374);
  color: #071e17;
  border-color: transparent;
}

.btn.gold {
  background: linear-gradient(135deg, #f8cf65, #d99126);
  color: #211303;
  border-color: transparent;
}

.btn.danger {
  background: linear-gradient(135deg, #f43f5e, #be123c);
  color: #ffffff;
  border-color: transparent;
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.chapter-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 14px;
}

.chapter-card {
  text-align: left;
  padding: 10px 11px;
  border-radius: 13px;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chapter-card.selected {
  border-color: var(--emerald);
  background: rgba(59, 227, 164, 0.14);
}

.chapter-card:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.chapter-card small {
  font-size: 11px;
  color: var(--muted);
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.actions-row .btn {
  flex: 1 1 auto;
}

.meta-strip {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  font-weight: 750;
  color: var(--gold);
  padding: 8px 10px;
  border-radius: 11px;
  background: rgba(242, 192, 87, 0.1);
  margin-bottom: 10px;
}

.hint-line {
  font-size: 12px !important;
  color: #cde3e8 !important;
  margin-top: 12px !important;
  margin-bottom: 0 !important;
}

/* Skill draft cards */
.draft-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  margin-top: 12px;
}

.skill-card {
  position: relative;
  text-align: center;
  padding: 14px 9px 12px;
  border-radius: 15px;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.skill-card:hover,
.skill-card:focus-visible {
  border-color: var(--gold);
  background: rgba(242, 192, 87, 0.14);
}

.skill-card.cat-geo { border-top: 4px solid #f2c057; }
.skill-card.cat-elem { border-top: 4px solid #38bdf8; }
.skill-card.cat-orbit { border-top: 4px solid #c084fc; }
.skill-card.cat-surv { border-top: 4px solid #4ade80; }
.skill-card.cat-stat { border-top: 4px solid #fb7185; }

.skill-key {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 10px;
  font-weight: 900;
  color: var(--muted);
}

.skill-ico {
  font-size: 26px;
  line-height: 1;
}

.skill-name {
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
}

.skill-desc {
  font-size: 11.5px;
  line-height: 1.38;
  color: var(--muted);
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin: 10px 0 14px;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.item-info strong {
  display: block;
  font-size: 14px;
}

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

.build-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 12px;
}

.build-pill {
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-size: 11.5px;
  font-weight: 750;
}

.guide-block h3 {
  margin: 12px 0 6px;
  font-size: 14.5px;
  color: var(--gold);
}

.guide-block ul {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 520px) {
  .draft-grid {
    grid-template-columns: 1fr;
  }
  .skill-card {
    flex-direction: row;
    text-align: left;
    padding: 11px 12px;
    gap: 10px;
  }
  .skill-key {
    display: none;
  }
  .chapter-list {
    grid-template-columns: 1fr;
  }
}
