:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0c1b14;
  color: #fff;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

body {
  background: #0c1b14;
}

#gameShell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #193d25;
}

.hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 5;
  width: min(380px, calc(100vw - 24px));
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(7, 17, 13, 0.72);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
}

.hud-row {
  display: grid;
  grid-template-columns: 44px minmax(110px, 1fr) 72px;
  align-items: center;
  column-gap: 10px;
  min-height: 24px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}

.hud-row + .hud-row {
  margin-top: 8px;
}

.hud-icon {
  width: auto;
  color: #f2f7ee;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.hud-value {
  min-width: 72px;
  text-align: right;
  color: #f9f9f2;
}

.meter {
  position: relative;
  flex: 1;
  height: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.34);
}

.meter-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  transition: width 120ms linear;
}

.hp-fill {
  background: linear-gradient(90deg, #e63946, #ffb703);
}

.exp-fill {
  background: linear-gradient(90deg, #ffe066, #8ce99a);
}

.blade-fill {
  background: linear-gradient(90deg, #74c0fc, #b197fc);
}

.hud-stats {
  display: flex;
  justify-content: space-between;
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
}

.buff-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
  margin-top: 0;
  overflow: hidden;
  transition: min-height 120ms ease, margin-top 120ms ease;
}

.buff-tray:not(:empty) {
  min-height: 28px;
  margin-top: 9px;
}

.buff-chip {
  display: grid;
  grid-template-columns: 22px 1fr 34px;
  align-items: center;
  gap: 6px;
  width: min(176px, 100%);
  min-height: 28px;
  padding: 4px 7px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.buff-icon {
  text-align: center;
}

.buff-meter {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.36);
}

.buff-meter-fill {
  height: 100%;
  border-radius: inherit;
}

.buff-time {
  text-align: right;
  color: rgba(255, 255, 255, 0.86);
  font-variant-numeric: tabular-nums;
}

.joystick {
  position: fixed;
  z-index: 6;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 0 22px rgba(255, 255, 255, 0.08);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9);
  transition: opacity 120ms ease, transform 120ms ease;
}

.joystick.active {
  opacity: 1;
  transform: scale(1);
}

.joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  transform: translate(0, 0);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.62);
}

.hidden {
  display: none;
}

.result-panel,
.level-panel {
  width: min(420px, 100%);
  padding: 28px 24px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(13, 22, 18, 0.94);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.result-panel h1,
.level-panel h1 {
  margin: 0 0 18px;
  color: #ffdddd;
  font-size: 34px;
  letter-spacing: 0;
}

.level-panel h1 {
  color: #fff3bf;
}

.level-panel p {
  margin: -8px 0 18px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 14px;
}

.skill-grid {
  display: grid;
  gap: 10px;
}

.skill-card {
  width: 100%;
  min-height: 86px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  text-align: left;
}

.skill-card:hover,
.skill-card:focus-visible {
  background: rgba(247, 201, 72, 0.18);
  outline: 2px solid rgba(247, 201, 72, 0.72);
  outline-offset: 2px;
}

.skill-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 16px;
  font-weight: 900;
}

.skill-desc {
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}

.final-stats {
  display: grid;
  gap: 8px;
  margin-bottom: 22px;
  color: rgba(255, 255, 255, 0.86);
  font-size: 15px;
}

button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: #f7c948;
  color: #1f1b08;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

button:active {
  transform: translateY(1px);
}

@media (max-width: 520px) {
  .hud {
    min-width: auto;
    right: max(12px, env(safe-area-inset-right));
    padding: 9px 10px;
  }

  .hud-row {
    grid-template-columns: 42px minmax(96px, 1fr) 66px;
    font-size: 12px;
  }

  .hud-value {
    min-width: 62px;
  }
}
