:root {
  --bg: #060b18;
  --panel: #0a1225;
  --panel-2: #0e1b32;
  --line: rgba(126, 186, 255, 0.16);
  --line-strong: rgba(126, 186, 255, 0.3);
  --text: #edf4ff;
  --muted: #a5b5cc;
  --dim: #7185a3;
  --cyan: #56d8ff;
  --violet: #2788ff;
  --lime: #a9f0ff;
  --gold: #e6b36a;
  --orange: #ffcf78;
  --red: #ff8c9a;
  --mono: "Cascadia Mono", "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(ellipse 70% 42% at 50% 0%, rgba(86, 216, 255, 0.08), transparent 66%),
    radial-gradient(ellipse 50% 40% at 90% 100%, rgba(39, 136, 255, 0.06), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(126, 186, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126, 186, 255, 0.035) 1px, transparent 1px);
  background-size: 40px 40px;
  -webkit-mask-image: radial-gradient(circle at 50% 35%, #000, transparent 78%);
  mask-image: radial-gradient(circle at 50% 35%, #000, transparent 78%);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

button:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

.game {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.6vw, 14px);
  width: min(1080px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(10px, 2vw, 20px);
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}

.hud__brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.hud__mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid rgba(86, 216, 255, 0.3);
  color: var(--cyan);
  background: rgba(86, 216, 255, 0.045);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}

.hud__mark svg {
  width: 24px;
  height: 24px;
}

.hud__brand h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(15px, 2.4vw, 20px);
  font-weight: 600;
  letter-spacing: 0.14em;
  line-height: 1.1;
  text-transform: uppercase;
}

.hud__brand p {
  margin: 3px 0 0;
  overflow: hidden;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 7.5px;
  letter-spacing: 0.11em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.hud__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.hud__button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  background: rgba(10, 18, 37, 0.5);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 7.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
}

.hud__button:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(126, 186, 255, 0.06);
}

.hud__icon {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}

.hud__button b {
  color: var(--dim);
  font-weight: 500;
}

#sound[aria-pressed="true"] {
  color: var(--cyan);
  border-color: rgba(86, 216, 255, 0.36);
}

#sound[aria-pressed="true"] b {
  color: var(--lime);
}

.arena {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: clamp(7px, 1.4vw, 12px);
  min-height: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: rgba(8, 15, 31, 0.66);
}

.stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 9px 12px;
}

.stat + .stat {
  border-left: 1px solid var(--line);
}

.stat__label {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 7px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.stat__value {
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
}

.stat__value--lives {
  color: var(--red);
  font-size: 13px;
  letter-spacing: 0.12em;
}

.board-wrap {
  position: relative;
  display: grid;
  flex: 1;
  place-items: center;
  min-height: 0;
  padding: 2px 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: clamp(7px, 1.4vw, 13px);
  width: min(100%, 660px, calc((100dvh - 225px) * 1.5));
  aspect-ratio: 3 / 2;
  max-height: 100%;
}

.rune {
  --rune: var(--cyan);
  --rune-rgb: 86, 216, 255;
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(var(--rune-rgb), 0.22);
  border-radius: 0;
  background:
    linear-gradient(rgba(var(--rune-rgb), 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--rune-rgb), 0.05) 1px, transparent 1px),
    radial-gradient(circle at 50% 55%, rgba(var(--rune-rgb), 0.11), transparent 62%),
    rgba(8, 15, 31, 0.72);
  background-size: 18px 18px, 18px 18px, auto, auto;
  color: var(--rune);
  transition:
    opacity 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease,
    box-shadow 160ms ease,
    transform 120ms ease;
}

.rune:nth-child(2) {
  --rune: var(--violet);
  --rune-rgb: 39, 136, 255;
}

.rune:nth-child(3) {
  --rune: var(--lime);
  --rune-rgb: 169, 240, 255;
}

.rune:nth-child(4) {
  --rune: var(--gold);
  --rune-rgb: 230, 179, 106;
}

.rune:nth-child(5) {
  --rune: var(--orange);
  --rune-rgb: 255, 207, 120;
}

.rune:nth-child(6) {
  --rune: var(--red);
  --rune-rgb: 255, 140, 154;
}

.rune::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(var(--rune-rgb), 0.1);
  pointer-events: none;
  transition: border-color 160ms ease;
}

.rune__index {
  position: absolute;
  top: 6px;
  left: 8px;
  color: rgba(var(--rune-rgb), 0.55);
  font-family: var(--mono);
  font-size: 7px;
  letter-spacing: 0.08em;
}

.rune__glyph {
  position: relative;
  z-index: 1;
  width: clamp(30px, 7.4vw, 58px);
  height: auto;
  max-height: 58%;
  filter: drop-shadow(0 0 0 rgba(var(--rune-rgb), 0));
  transition: filter 160ms ease, transform 160ms ease;
}

.rune__glyph path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

.board:not(.is-playable) .rune {
  opacity: 0.54;
  pointer-events: none;
}

.board.is-playable .rune:hover {
  border-color: rgba(var(--rune-rgb), 0.52);
  background-color: rgba(var(--rune-rgb), 0.08);
}

.rune:active:not(:disabled) {
  transform: scale(0.985);
}

.rune.is-lit {
  opacity: 1;
  z-index: 1;
  border-color: rgba(var(--rune-rgb), 0.9);
  background:
    radial-gradient(circle at 50% 50%, rgba(var(--rune-rgb), 0.34), transparent 68%),
    rgba(var(--rune-rgb), 0.09);
  box-shadow:
    0 0 0 1px rgba(var(--rune-rgb), 0.32),
    0 0 34px -6px rgba(var(--rune-rgb), 0.8),
    inset 0 0 34px -10px rgba(var(--rune-rgb), 0.9);
  transform: scale(1.015);
}

.rune.is-lit .rune__glyph {
  filter: drop-shadow(0 0 11px rgba(var(--rune-rgb), 0.9));
  transform: scale(1.06);
}

.rune.is-error {
  opacity: 1;
  border-color: var(--red);
  background: rgba(255, 140, 154, 0.16);
  box-shadow: 0 0 30px -8px rgba(255, 140, 154, 0.8);
  animation: rune-error 300ms ease;
}

.gate {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow: auto;
  padding: clamp(16px, 3vh, 30px) clamp(14px, 3vw, 34px);
  border: 1px solid var(--line-strong);
  background:
    radial-gradient(ellipse 70% 60% at 50% 42%, rgba(86, 216, 255, 0.09), transparent 66%),
    rgba(6, 11, 24, 0.94);
  text-align: center;
  animation: gate-in 220ms ease both;
}

.gate--over {
  background:
    radial-gradient(ellipse 70% 60% at 50% 42%, rgba(255, 140, 154, 0.1), transparent 66%),
    rgba(6, 11, 24, 0.96);
}

.gate__sigil {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: 2px;
  border: 1px solid rgba(86, 216, 255, 0.36);
  color: var(--cyan);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}

.gate__sigil svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.gate__code {
  margin: 0;
  color: var(--cyan);
  font-family: var(--mono);
  font-size: 7px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.gate h2 {
  margin: 0;
  font-family: var(--sans);
  font-size: clamp(22px, 3.6vw, 34px);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.gate__copy {
  max-width: 48ch;
  margin: 0;
  color: var(--muted);
  font-size: clamp(10.5px, 1.5vw, 12.5px);
  line-height: 1.6;
}

.rules {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px 18px;
  margin: 2px 0 4px;
  padding: 0;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 7.5px;
  letter-spacing: 0.05em;
  list-style: none;
}

.rules li {
  position: relative;
  padding-left: 10px;
}

.rules li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  width: 4px;
  height: 4px;
  border: 1px solid var(--cyan);
  transform: rotate(45deg);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 22px;
  border: 1px solid var(--line-strong);
  background: rgba(126, 186, 255, 0.05);
  color: var(--text);
  font-family: var(--mono);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: transform 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button--primary {
  border-color: transparent;
  background: linear-gradient(135deg, #a9f0ff, #56d8ff 52%, #2788ff);
  color: #021225;
  box-shadow: 0 12px 34px -18px rgba(86, 216, 255, 0.9);
}

.button--primary:hover {
  background: linear-gradient(135deg, #edf4ff, #56d8ff 52%, #1b6fe0);
  box-shadow: 0 15px 38px -16px rgba(86, 216, 255, 1);
}

.button:active {
  transform: translateY(0);
}

.gate__note {
  margin: 2px 0 0;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 7px;
  letter-spacing: 0.07em;
}

.result {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: min(320px, 100%);
  margin: 4px 0 6px;
}

.result > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px;
  border: 1px solid var(--line);
  background: rgba(126, 186, 255, 0.035);
}

.result span {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 7px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.result strong {
  font-family: var(--mono);
  font-size: 23px;
  font-weight: 500;
  color: var(--cyan);
}

.live {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.foot {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 6.8px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

@keyframes gate-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes rune-error {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

@media (max-width: 520px) {
  .hud__brand p {
    display: none;
  }

  .hud__mark {
    width: 33px;
    height: 33px;
  }

  .hud__button {
    min-height: 32px;
    padding: 5px 7px;
    font-size: 7px;
  }

  .hud__button > span {
    display: none;
  }

  .stat {
    padding: 8px 9px;
  }

  .stat__label {
    font-size: 6.5px;
  }

  .stat__value {
    font-size: 13px;
  }

  .gate {
    justify-content: flex-start;
    padding-top: 14px;
  }

  .gate__sigil {
    display: none;
  }

  .gate__copy {
    font-size: 10px;
  }

  .rules {
    display: none;
  }

  .board {
    width: min(100%, calc((100dvh - 212px) * 1.5));
  }
}

@media (max-height: 520px) {
  .game {
    gap: 6px;
    padding: 9px 12px;
  }

  .hud__brand p,
  .gate__sigil,
  .gate__note,
  .rules {
    display: none;
  }

  .gate {
    justify-content: flex-start;
    gap: 6px;
    padding: 12px 16px;
  }

  .gate h2 {
    font-size: 21px;
  }

  .gate__copy {
    line-height: 1.45;
  }

  .button {
    min-height: 36px;
    padding: 8px 18px;
  }

  .stat {
    padding: 6px 9px;
  }

  .foot {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
