:root {
  color-scheme: dark;
  --bg: #111014;
  --surface: #19151d;
  --surface-2: #211a22;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f8f2e8;
  --muted: #b8aca2;
  --gold: #f2b84b;
  --teal: #41d6ca;
  --rose: #ef476f;
  --violet: #b87bff;
  --green: #91d46f;
  --shadow: rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(242, 184, 75, 0.08), transparent 32%),
    linear-gradient(215deg, rgba(65, 214, 202, 0.07), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
canvas {
  font: inherit;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #2a222a;
  color: var(--text);
  cursor: pointer;
  min-height: 42px;
  padding: 0 16px;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

button:hover:not(:disabled),
button:focus-visible:not(:disabled) {
  background: #352b32;
  border-color: rgba(242, 184, 75, 0.6);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 18px;
  gap: 14px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) minmax(360px, 1.5fr) auto;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.brand-block h1,
.overlay-panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand-block h1 {
  font-size: clamp(1.65rem, 3vw, 3.2rem);
  line-height: 0.95;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hud-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 10px;
}

.fighter-stat {
  min-width: 0;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat-row strong {
  color: var(--text);
  font-size: 0.9rem;
}

.meter {
  position: relative;
  height: 11px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.meter span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  transform-origin: left center;
  transition: transform 160ms ease;
}

.meter.health span {
  background: linear-gradient(90deg, var(--green), var(--gold));
}

.meter.mana span {
  background: linear-gradient(90deg, var(--teal), #78e8e0);
}

.meter.enemy span {
  background: linear-gradient(90deg, var(--rose), var(--violet));
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#soundBtn[aria-pressed="true"] {
  border-color: rgba(65, 214, 202, 0.6);
  background: rgba(65, 214, 202, 0.12);
  color: #dffdf9;
}

.duel-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.arena-shell {
  position: relative;
  min-height: 520px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151217;
  box-shadow: 0 20px 50px var(--shadow);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 520px;
  touch-action: none;
}

.overlay-panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(17, 16, 20, 0.5), rgba(17, 16, 20, 0.7)),
    transparent;
  text-align: left;
}

.overlay-panel[hidden] {
  display: none;
}

.overlay-content {
  width: min(760px, 100%);
}

.overlay-panel h2 {
  margin-bottom: 10px;
  font-size: clamp(2.1rem, 5.6vw, 4.8rem);
  line-height: 0.9;
}

.overlay-copy {
  width: min(560px, 100%);
  margin: 0 0 16px;
  color: var(--muted);
  font-size: clamp(0.96rem, 1.8vw, 1.08rem);
  line-height: 1.45;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  margin-bottom: 14px;
}

.overlay-actions button:first-child {
  background: linear-gradient(135deg, #6e3831, #876328);
  border-color: rgba(242, 184, 75, 0.5);
  font-weight: 800;
}

.menu-options {
  display: grid;
  grid-template-columns: minmax(250px, 0.8fr) minmax(290px, 1.1fr);
  gap: 12px;
  align-items: stretch;
}

.overlay-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(96px, 1fr));
  gap: 8px;
  width: min(650px, 100%);
  margin: 12px 0 14px;
}

.overlay-stats[hidden] {
  display: none;
}

.overlay-stat {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(17, 16, 20, 0.76);
  padding: 10px;
}

.overlay-stat span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.overlay-stat strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: clamp(1rem, 2.2vw, 1.45rem);
  overflow-wrap: anywhere;
}

.menu-options[hidden] {
  display: none;
}

.menu-block {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(17, 16, 20, 0.74);
  padding: 12px;
}

.menu-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.menu-block-header span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.menu-block-header strong {
  color: var(--teal);
  font-size: 0.86rem;
}

.movement-block {
  grid-column: 1 / -1;
}

.movement-block p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.42;
}

.difficulty-picker {
  display: grid;
  gap: 8px;
}

.difficulty-btn {
  display: grid;
  justify-items: start;
  width: 100%;
  height: auto;
  min-height: 54px;
  padding: 9px 11px;
  text-align: left;
  font-weight: 800;
}

.difficulty-btn span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.difficulty-btn.active {
  border-color: rgba(65, 214, 202, 0.65);
  background: rgba(65, 214, 202, 0.12);
}

.gesture-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(76px, 1fr));
  gap: 8px;
}

.gesture-grid > div {
  display: grid;
  justify-items: center;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  padding: 8px 6px;
  text-align: center;
}

.gesture-grid .glyph {
  margin-bottom: 6px;
}

.gesture-grid strong,
.gesture-grid span {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.gesture-grid strong {
  font-size: 0.78rem;
}

.gesture-grid div > span:last-child {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.68rem;
}

.game-message {
  position: absolute;
  left: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100% - 36px));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(17, 16, 20, 0.72);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 800;
  padding: 10px 12px;
  pointer-events: none;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.22);
}

.overlay-panel:not([hidden]) ~ .game-message {
  display: none;
}

.spell-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(25, 21, 29, 0.9);
  box-shadow: 0 18px 44px var(--shadow);
}

.panel-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header strong {
  color: var(--teal);
}

.spell-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.spell-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 76px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  padding: 10px;
}

.spell-row strong,
.spell-row span,
.spell-row small {
  display: block;
  min-width: 0;
}

.spell-row strong {
  font-size: 0.94rem;
}

.spell-row div > span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.spell-row small {
  margin-top: 4px;
  color: rgba(248, 242, 232, 0.72);
  font-size: 0.72rem;
  line-height: 1.2;
}

.spell-row.cooling {
  opacity: 0.6;
}

.spell-row.ready {
  border-color: rgba(65, 214, 202, 0.34);
}

.glyph {
  position: relative;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background: #181318;
}

.slash-glyph::before,
.dash-glyph::before,
.bolt-glyph::before,
.bolt-glyph::after,
.flare-glyph::before {
  position: absolute;
  content: "";
  display: block;
}

.slash-glyph::before {
  left: 7px;
  top: 17px;
  width: 24px;
  height: 4px;
  border-radius: 999px;
  background: var(--gold);
  transform: rotate(-28deg);
}

.ward-glyph {
  border-color: rgba(65, 214, 202, 0.4);
}

.ward-glyph::before {
  position: absolute;
  inset: 8px;
  content: "";
  border: 3px solid var(--teal);
  border-radius: 50%;
}

.bolt-glyph::before,
.bolt-glyph::after {
  width: 19px;
  height: 4px;
  border-radius: 999px;
  background: var(--violet);
}

.bolt-glyph::before {
  left: 7px;
  top: 12px;
  transform: rotate(25deg);
}

.bolt-glyph::after {
  left: 12px;
  top: 21px;
  transform: rotate(-25deg);
}

.dash-glyph::before {
  left: 17px;
  top: 8px;
  width: 4px;
  height: 22px;
  border-radius: 999px;
  background: var(--green);
}

.dash-glyph::after {
  position: absolute;
  left: 12px;
  top: 7px;
  width: 12px;
  height: 12px;
  content: "";
  border-top: 4px solid var(--green);
  border-left: 4px solid var(--green);
  transform: rotate(45deg);
}

.flare-glyph::before {
  inset: 11px;
  border-radius: 50%;
  background: var(--rose);
  box-shadow: 0 0 0 5px rgba(239, 71, 111, 0.22);
}

.tip-panel {
  display: grid;
  gap: 6px;
  margin: 0 12px 12px;
  border: 1px solid rgba(65, 214, 202, 0.18);
  border-radius: 8px;
  background: rgba(65, 214, 202, 0.055);
  padding: 12px;
}

.tip-panel strong {
  color: var(--teal);
  font-size: 0.86rem;
}

.tip-panel span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.round-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin-top: auto;
  border-top: 1px solid var(--line);
  background: var(--line);
}

.round-panel > div {
  min-width: 0;
  background: rgba(25, 21, 29, 0.96);
  padding: 14px;
}

.round-panel span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.round-panel strong {
  display: block;
  margin-top: 5px;
  color: var(--text);
  font-size: clamp(1rem, 2.5vw, 1.6rem);
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: flex-start;
  }

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

  .spell-panel {
    min-height: auto;
  }

  .spell-list {
    grid-template-columns: repeat(5, minmax(140px, 1fr));
    overflow-x: auto;
  }

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

  .menu-options {
    grid-template-columns: 1fr;
  }

  .gesture-grid {
    grid-template-columns: repeat(5, minmax(74px, 1fr));
    overflow-x: auto;
  }

  .overlay-stats {
    grid-template-columns: repeat(2, minmax(96px, 1fr));
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 10px;
  }

  .hud-strip {
    grid-template-columns: 1fr;
  }

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

  button {
    padding-inline: 10px;
  }

  .arena-shell,
  #gameCanvas {
    min-height: 640px;
  }

  .spell-list {
    grid-template-columns: repeat(5, 132px);
  }

  .overlay-panel {
    align-items: start;
    overflow-y: auto;
    padding: 18px;
  }

  .overlay-panel h2 {
    font-size: clamp(2rem, 12vw, 3rem);
  }

  .gesture-grid {
    grid-template-columns: repeat(5, 82px);
  }

  .overlay-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}
