:root {
  color-scheme: dark;
  --page: #08090c;
  --rim: #222834;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 14%, rgba(82, 150, 151, 0.18), transparent 26rem),
    radial-gradient(circle at 85% 88%, rgba(173, 82, 67, 0.18), transparent 26rem),
    var(--page);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game {
  display: block;
  width: min(100vw, 460px);
  height: 100dvh;
  max-height: 940px;
  background: #10131a;
  border-left: 1px solid rgba(244, 226, 184, 0.16);
  border-right: 1px solid rgba(244, 226, 184, 0.16);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 24px 80px rgba(0, 0, 0, 0.58);
  cursor: crosshair;
  touch-action: none;
}

.command-controls {
  position: fixed;
  left: 50%;
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 12px));
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(2, minmax(112px, 1fr));
  gap: 8px;
  width: min(76vw, 330px);
  padding: 6px;
  border: 1px solid rgba(255, 238, 194, 0.24);
  border-radius: 999px;
  background: rgba(8, 10, 14, 0.72);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(9px);
  transform: translateX(-50%);
}

.command-controls[hidden] {
  display: none;
}

.command-button {
  min-width: 0;
  min-height: 42px;
  border: 1px solid rgba(255, 238, 194, 0.18);
  border-radius: 999px;
  background: rgba(23, 25, 31, 0.76);
  color: rgba(255, 247, 224, 0.74);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}

.command-button.is-active {
  border-color: rgba(255, 230, 166, 0.72);
  background: linear-gradient(180deg, rgba(248, 220, 151, 0.98), rgba(189, 126, 69, 0.96));
  color: #1b120d;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 226, 0.56),
    0 0 24px rgba(104, 232, 137, 0.18);
}

.command-button:focus-visible {
  outline: 2px solid #dfffd9;
  outline-offset: 3px;
}

.splash-screen,
.instructions-screen,
.end-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.splash-screen {
  cursor: pointer;
  background: #08090c;
  touch-action: manipulation;
}

.splash-screen:focus-visible {
  outline: 2px solid #f4dc9e;
  outline-offset: -8px;
}

.splash-art {
  width: min(100vw, 460px);
  height: 100dvh;
  max-height: 940px;
  object-fit: cover;
  border-left: 1px solid rgba(244, 226, 184, 0.18);
  border-right: 1px solid rgba(244, 226, 184, 0.18);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.05),
    0 24px 80px rgba(0, 0, 0, 0.64);
}

.splash-scrim {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(8, 9, 12, 0.12), rgba(8, 9, 12, 0.08) 42%, rgba(8, 9, 12, 0.48)),
    radial-gradient(circle at 50% 86%, rgba(113, 229, 144, 0.22), transparent 15rem);
  pointer-events: none;
}

.splash-copy {
  position: absolute;
  left: 50%;
  bottom: max(34px, calc(env(safe-area-inset-bottom) + 28px));
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(88vw, 390px);
  transform: translateX(-50%);
  text-align: center;
  color: #fff4d6;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.86);
  pointer-events: none;
}

.splash-copy h1 {
  position: relative;
  display: inline-block;
  isolation: isolate;
  margin: 0;
  padding: 0 10px 15px;
  font-family: Papyrus, Copperplate, Georgia, "Times New Roman", serif;
  font-size: 3.05rem;
  font-variant-caps: small-caps;
  font-weight: 900;
  line-height: 0.78;
  letter-spacing: 0;
  text-transform: uppercase;
  color: transparent;
  background:
    linear-gradient(180deg, #ffffdd 0%, #ffd761 27%, #9d4d28 52%, #ffe9ac 66%, #52200f 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-stroke: 1.2px rgba(49, 22, 19, 0.98);
  paint-order: stroke fill;
  transform: perspective(420px) rotateX(8deg) skewX(-5deg);
  text-shadow:
    0 1px 0 #fff1b8,
    0 3px 0 #7b351f,
    0 5px 0 rgba(30, 10, 14, 0.98),
    0 11px 20px rgba(0, 0, 0, 0.84),
    0 0 22px rgba(148, 236, 122, 0.52),
    0 0 34px rgba(217, 101, 232, 0.28);
}

.splash-copy h1::before {
  content: attr(data-title);
  position: absolute;
  inset: 0;
  z-index: -1;
  padding: 0 10px 15px;
  color: rgba(18, 11, 13, 0.96);
  -webkit-text-stroke: 8px rgba(16, 9, 12, 0.98);
  text-shadow:
    0 2px 0 rgba(252, 226, 175, 0.32),
    0 0 34px rgba(112, 255, 144, 0.34),
    0 16px 26px rgba(0, 0, 0, 0.86);
  transform: translateY(4px) scaleY(1.05);
}

.splash-copy h1::after {
  content: "";
  position: absolute;
  left: 11%;
  right: 11%;
  bottom: 0;
  height: 3px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, transparent, rgba(116, 246, 146, 0.78), #ffe6a1, rgba(210, 102, 230, 0.68), transparent);
  box-shadow:
    0 0 14px rgba(116, 246, 146, 0.58),
    0 0 26px rgba(210, 102, 230, 0.3);
}

@media (min-width: 390px) {
  .splash-copy h1 {
    font-size: 3.65rem;
  }
}

.splash-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  margin: 18px 0 0;
  padding: 8px 18px;
  border: 1px solid rgba(252, 226, 175, 0.48);
  border-radius: 999px;
  background: rgba(11, 12, 17, 0.68);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.42);
  color: #fff4d6;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.splash-pill + .splash-pill {
  margin-left: 0;
  margin-top: 8px;
}

.splash-pill-secondary {
  border-color: rgba(174, 238, 255, 0.34);
  background: rgba(17, 20, 29, 0.72);
  color: rgba(226, 249, 255, 0.92);
}

.splash-pill:focus-visible {
  outline: 2px solid #dfffd9;
  outline-offset: 3px;
}

.end-screen {
  z-index: 12;
  background:
    radial-gradient(circle at 50% 30%, rgba(244, 211, 150, 0.12), transparent 18rem),
    rgba(6, 7, 10, 0.78);
  backdrop-filter: blur(7px);
}

.splash-screen[hidden],
.instructions-screen[hidden],
.end-screen[hidden] {
  display: none;
}

.instructions-screen {
  z-index: 11;
  align-items: center;
  background:
    radial-gradient(circle at 50% 18%, rgba(103, 216, 198, 0.13), transparent 18rem),
    radial-gradient(circle at 50% 88%, rgba(211, 99, 230, 0.13), transparent 18rem),
    rgba(5, 7, 10, 0.88);
  backdrop-filter: blur(8px);
}

.instructions-panel {
  width: min(92vw, 430px);
  max-height: min(88dvh, 760px);
  overflow: auto;
  padding: 22px 14px calc(88px + env(safe-area-inset-bottom));
  color: #fff5d9;
  text-align: center;
}

.instructions-panel h2 {
  margin: 0 0 14px;
  font-family: Papyrus, Copperplate, Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 8vw, 3.2rem);
  line-height: 0.9;
  text-transform: uppercase;
  color: #ffe8a8;
  text-shadow:
    0 2px 0 rgba(103, 52, 34, 0.9),
    0 12px 26px rgba(0, 0, 0, 0.74),
    0 0 22px rgba(114, 239, 158, 0.28);
}

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

.spell-card {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 231, 173, 0.18);
  border-radius: 8px;
  background: rgba(11, 13, 18, 0.74);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  text-align: left;
}

.spell-glyph {
  width: 74px;
  height: 52px;
  padding: 5px;
  border: 1px solid rgba(116, 246, 146, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 231, 173, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 231, 173, 0.055) 1px, transparent 1px),
    rgba(5, 8, 12, 0.48);
  background-size: 14px 14px;
  filter: drop-shadow(0 0 8px rgba(116, 246, 146, 0.16));
  overflow: visible;
}

.spell-glyph path,
.spell-glyph circle {
  fill: none;
  stroke: #b6ffd3;
  stroke-width: 4.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.spell-glyph circle {
  fill: rgba(182, 255, 211, 0.18);
}

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

.spell-copy strong {
  color: #ffe2a8;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.spell-copy span {
  margin-top: 4px;
  color: rgba(255, 247, 226, 0.78);
  font-size: 0.84rem;
  line-height: 1.35;
}

@media (max-width: 360px) {
  .spell-card {
    grid-template-columns: 62px minmax(0, 1fr);
    gap: 8px;
    padding: 9px 10px;
  }

  .spell-glyph {
    width: 62px;
    height: 46px;
  }
}

.instructions-actions {
  position: fixed;
  z-index: 13;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  width: min(92vw, 430px);
  padding: 10px;
  gap: 8px;
  border: 1px solid rgba(255, 238, 194, 0.18);
  border-radius: 999px;
  background: rgba(5, 7, 10, 0.82);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.48);
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
}

.instructions-actions .splash-pill {
  margin-top: 0;
}

.end-panel {
  width: min(92vw, 420px);
  max-height: min(88dvh, 760px);
  overflow: auto;
  padding: 24px 16px 18px;
  color: #fff5d9;
  text-align: center;
}

.result-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  isolation: isolate;
  min-width: clamp(224px, 68vw, 326px);
  min-height: 64px;
  padding: 13px 34px 17px;
  border: 1px solid rgba(249, 223, 166, 0.62);
  border-radius: 999px;
  background: rgba(13, 14, 18, 0.82);
  box-shadow:
    0 0 30px rgba(104, 232, 137, 0.2),
    0 16px 46px rgba(0, 0, 0, 0.52);
  color: transparent;
  font-family: Papyrus, Copperplate, Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 8vw, 3.05rem);
  font-variant-caps: small-caps;
  font-weight: 900;
  line-height: 0.82;
  text-transform: uppercase;
  white-space: nowrap;
}

.result-pill::before,
.result-pill::after {
  content: attr(data-result);
  position: absolute;
  left: 50%;
  top: 50%;
  letter-spacing: 0;
  line-height: 0.82;
  text-transform: uppercase;
  transform: translate(-50%, -49%) perspective(380px) rotateX(8deg) skewX(-5deg);
  white-space: nowrap;
  pointer-events: none;
}

.result-pill::before {
  z-index: 0;
  color: rgba(19, 11, 12, 0.98);
  -webkit-text-stroke: 7px rgba(15, 8, 11, 0.98);
  text-shadow:
    0 2px 0 rgba(255, 239, 184, 0.28),
    0 0 26px rgba(116, 246, 146, 0.36),
    0 13px 24px rgba(0, 0, 0, 0.84);
}

.result-pill::after {
  z-index: 1;
  color: transparent;
  background:
    linear-gradient(180deg, #ffffdf 0%, #ffd965 27%, #9d4d28 52%, #fff0b6 67%, #52200f 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-stroke: 1px rgba(49, 22, 19, 0.98);
  paint-order: stroke fill;
  text-shadow:
    0 1px 0 #fff1b8,
    0 3px 0 #7b351f,
    0 5px 0 rgba(30, 10, 14, 0.98),
    0 10px 19px rgba(0, 0, 0, 0.82),
    0 0 20px rgba(148, 236, 122, 0.46),
    0 0 31px rgba(217, 101, 232, 0.24);
}

.result-pill.is-vanquished {
  border-color: rgba(244, 154, 131, 0.58);
  box-shadow:
    0 0 30px rgba(213, 103, 91, 0.26),
    0 16px 46px rgba(0, 0, 0, 0.52);
}

.result-pill.is-vanquished::before {
  -webkit-text-stroke-color: rgba(23, 6, 9, 0.98);
  text-shadow:
    0 2px 0 rgba(255, 202, 166, 0.22),
    0 0 24px rgba(213, 82, 91, 0.38),
    0 13px 24px rgba(0, 0, 0, 0.84);
}

.result-pill.is-vanquished::after {
  background:
    linear-gradient(180deg, #ffe8c9 0%, #ff956a 26%, #8d242a 54%, #ffd1a5 70%, #31070c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-stroke-color: rgba(54, 10, 14, 0.98);
  text-shadow:
    0 1px 0 rgba(255, 218, 176, 0.88),
    0 3px 0 #78201f,
    0 5px 0 rgba(25, 5, 8, 0.98),
    0 10px 19px rgba(0, 0, 0, 0.82),
    0 0 20px rgba(226, 87, 82, 0.44),
    0 0 31px rgba(232, 142, 92, 0.24);
}

.play-again {
  display: block;
  width: min(72vw, 230px);
  min-height: 44px;
  margin: 18px auto 20px;
  border: 1px solid rgba(252, 226, 175, 0.58);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(248, 221, 165, 0.95), rgba(188, 130, 72, 0.95));
  color: #19110c;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
  font: inherit;
  font-weight: 850;
  cursor: pointer;
}

.play-again:focus-visible {
  outline: 2px solid #dfffd9;
  outline-offset: 3px;
}

.high-score-form {
  margin: -8px auto 14px;
  padding: 12px;
  border: 1px solid rgba(255, 238, 194, 0.18);
  border-radius: 8px;
  background: rgba(10, 11, 15, 0.66);
}

.high-score-form label {
  display: block;
  color: rgba(255, 245, 217, 0.72);
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.high-score-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 8px;
  margin-top: 8px;
}

.high-score-entry input,
.high-score-entry button {
  min-height: 38px;
  border-radius: 999px;
  font: inherit;
  font-weight: 800;
}

.high-score-entry input {
  min-width: 0;
  border: 1px solid rgba(255, 238, 194, 0.26);
  background: rgba(4, 6, 10, 0.72);
  color: #fff8e4;
  padding: 0 14px;
  text-align: center;
}

.high-score-entry input:focus-visible,
.high-score-entry button:focus-visible {
  outline: 2px solid #dfffd9;
  outline-offset: 3px;
}

.high-score-entry button {
  border: 1px solid rgba(252, 226, 175, 0.58);
  background: linear-gradient(180deg, rgba(176, 250, 195, 0.95), rgba(77, 162, 116, 0.95));
  color: #07130c;
  cursor: pointer;
}

.high-score-entry button:disabled {
  cursor: default;
  filter: grayscale(0.7);
  opacity: 0.58;
}

.high-score-status {
  min-height: 18px;
  margin-top: 7px;
  color: rgba(255, 245, 217, 0.72);
  font-size: 0.72rem;
  font-weight: 700;
}

.high-score-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 auto 12px;
}

.high-score-column {
  min-width: 0;
  padding: 9px 8px;
  border: 1px solid rgba(255, 238, 194, 0.18);
  border-radius: 8px;
  background: rgba(10, 11, 15, 0.62);
}

.high-score-column h3 {
  margin: 0 0 7px;
  color: #ffe2a8;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  line-height: 1.12;
  text-transform: uppercase;
}

.score-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.score-list li {
  padding: 5px 0;
  border-top: 1px solid rgba(255, 238, 194, 0.1);
  color: #fff8e4;
  font-size: 0.76rem;
  font-weight: 750;
}

.score-list li:first-child {
  border-top: 0;
}

.score-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.score-name {
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-time {
  color: rgba(255, 245, 217, 0.74);
}

.score-detail {
  margin-top: 2px;
  color: rgba(255, 245, 217, 0.58);
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-align: left;
  text-transform: uppercase;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  gap: 7px;
  margin: 0 auto 12px;
}

.stats-chip {
  min-width: 0;
  padding: 8px 6px;
  border: 1px solid rgba(255, 238, 194, 0.18);
  border-radius: 8px;
  background: rgba(10, 11, 15, 0.64);
}

.stats-chip strong {
  display: block;
  font-size: 1rem;
  line-height: 1.05;
}

.stats-chip span {
  display: block;
  margin-top: 3px;
  color: rgba(255, 245, 217, 0.72);
  font-size: 0.63rem;
  font-weight: 750;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid rgba(255, 238, 194, 0.18);
  border-radius: 8px;
  background: rgba(10, 11, 15, 0.66);
  font-size: clamp(0.68rem, 2.6vw, 0.82rem);
  table-layout: fixed;
}

.stats-table th,
.stats-table td {
  padding: 8px 5px;
  border-bottom: 1px solid rgba(255, 238, 194, 0.12);
}

.stats-table th {
  color: rgba(255, 245, 217, 0.74);
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats-table td {
  color: #fff8e4;
  font-weight: 700;
}

.stats-table tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 520px) {
  #game,
  .splash-art {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    border: 0;
  }

  .end-panel {
    width: 100%;
    padding-inline: 4px;
  }

  .high-score-board {
    grid-template-columns: 1fr;
  }
}
