:root {
  color-scheme: dark;
  --bg: #0e1628;
  --panel: #18243d;
  --muted: #a5b4d0;
  --mint: #9debc8;
  --gold: #f4c884;
  --coral: #f27474;
  --violet: #b185f0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: #f1f5ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}

button, a, input, select {
  -webkit-tap-highlight-color: transparent;
}

button, select {
  font: inherit;
  color: inherit;
  background: #24334f;
  border: 1px solid #43516b;
  border-radius: 9px;
  padding: 9px 13px;
  cursor: pointer;
}

button:hover {
  background: #354867;
}

button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, canvas:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

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

button[aria-pressed="true"] {
  border-color: var(--mint);
  color: var(--mint);
}

a {
  color: var(--mint);
}

header {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1400px;
  margin: auto;
  padding: 12px 32px;
}

.back {
  text-decoration: none;
  font-size: 14px;
  color: #b7c8e8;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 2px;
}

.brand b {
  color: var(--mint);
}

.brand small {
  font-size: 9px;
  letter-spacing: 3px;
  display: block;
  color: var(--muted);
  margin-top: 5px;
}

.sigil {
  font-size: 38px;
  color: var(--mint);
  text-shadow: 0 0 18px #4ae3b588;
}

.tools {
  display: flex;
  gap: 7px;
}

.tools button {
  font-size: 12px;
}

main {
  max-width: 1400px;
  padding: 0 32px;
  margin: auto;
}

.arena {
  position: relative;
  height: clamp(440px, 65vh, 750px);
  overflow: hidden;
  border: 1px solid #3d4b67;
  border-radius: 20px;
  background: #132238;
  user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

canvas:active {
  cursor: grabbing;
}

.hud {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  text-shadow: 0 2px 12px #0a172d;
  gap: 16px;
}

.hud-left {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 55%;
}

.level-caption span, .eyebrow {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--mint);
}

h1 {
  font-size: 23px;
  letter-spacing: -0.6px;
  margin: 4px 0;
}

h2 {
  font-size: 28px;
  line-height: 1.15;
  margin: 10px 0;
}

.difficulty-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 4px 10px;
  border: 1px solid #4ae3b577;
  border-radius: 999px;
  background: #10253ad9;
  color: var(--mint);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.8px;
}

.difficulty-badge[data-tier="2"] {
  border-color: #62d8f5;
  color: #8be9ff;
}

.difficulty-badge[data-tier="3"] {
  border-color: #b185f0;
  color: #d6b8ff;
}

.difficulty-badge[data-tier="4"] {
  border-color: #f4c884;
  color: #ffe2ad;
}

.difficulty-badge[data-tier="5"] {
  border-color: #f27474;
  color: #ffb3b3;
  box-shadow: 0 0 16px #f2747455;
}

/* Goal Card (Tiles in Hole style) */
.goal-card {
  background: #0f1b31e0;
  border: 1px solid #59709466;
  border-radius: 13px;
  padding: 8px 12px;
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: fit-content;
}

.goal-card-title {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.8px;
  color: #b8c8df;
}

.goal-card-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.goal-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 8px;
  background: #182946;
  border: 1px solid #415678;
  font-size: 11px;
  font-weight: 700;
  color: #eef4ff;
  transition: transform 0.16s ease, border-color 0.2s ease, background 0.2s ease;
}

.goal-pill.done {
  background: #173a38;
  border-color: var(--mint);
  color: var(--mint);
}

.goal-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px #ffffff44;
  flex-shrink: 0;
}

.stats {
  display: flex;
  gap: 18px;
  padding: 10px 15px;
  background: #101a30d9;
  border: 1px solid #60739066;
  border-radius: 12px;
}

.stats div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stats small {
  font-size: 9px;
  letter-spacing: 1.3px;
  color: #b8c8df;
}

.stats strong {
  font-size: 25px;
  color: #f3d39b;
  font-variant-numeric: tabular-nums;
}

#timeStat.urgent {
  color: #ff7b7b;
  animation: pulseUrgent 0.7s infinite alternate;
}

@keyframes pulseUrgent {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0.65; transform: scale(1.06); }
}

.goal-track {
  position: absolute;
  top: 94px;
  right: 24px;
  width: 215px;
  height: 5px;
  background: #12223a;
  border-radius: 5px;
  overflow: hidden;
}

.goal-track > div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--mint), var(--gold));
  border-radius: 5px;
  transition: width 0.15s ease;
}

.goal-track > span {
  height: 10px;
  position: absolute;
  top: -3px;
  border-left: 2px solid #ffdf9c;
}

.size-up-banner {
  position: absolute;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 12px 24px;
  border-radius: 999px;
  background: #11243be8;
  border: 2px solid var(--mint);
  color: var(--mint);
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 2.5px;
  box-shadow: 0 12px 40px #0009, 0 0 30px #4ae3b566;
  pointer-events: none;
  z-index: 4;
  animation: popBanner 1.35s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

@keyframes popBanner {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  75% { opacity: 1; transform: translate(-50%, -55%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -75%) scale(0.92); }
}

#toast {
  position: absolute;
  bottom: 20px;
  left: 24px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 12px;
  max-width: 58%;
  color: #e1ecfa;
  background: #112137d9;
  border: 1px solid #65809955;
  pointer-events: none;
}

.scene-actions {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 8px;
}

.scene-actions button {
  background: #14243bd9;
  font-size: 11px;
}

.console {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 28px;
  padding: 24px 8px;
  align-items: center;
}

.brief p {
  font-size: 14px;
  line-height: 1.5;
  margin: 8px 0 12px;
  color: #c1cde0;
  max-width: 390px;
}

.goal-label {
  font-size: 10px;
  letter-spacing: 1px;
  color: #9caecb;
}

.goal-label b {
  color: var(--gold);
  font-size: 13px;
  margin-left: 8px;
}

.goal-label span {
  margin-left: 18px;
  color: var(--mint);
}

.weapons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  max-width: 360px;
}

.weapons label {
  font-size: 10px;
  color: #bac9de;
  font-weight: 700;
  letter-spacing: 1.3px;
}

.weapons output {
  float: right;
  color: var(--gold);
}

select {
  font-size: 12px;
  width: 100%;
  background: #182740;
  padding: 10px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--mint);
  cursor: pointer;
  margin: 0;
  height: 20px;
}

.fire-box {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.fire {
  min-height: 90px;
  width: 184px;
  color: #132b31;
  background: var(--mint);
  border: 1px solid #b9ffe0;
  border-bottom: 5px solid #4a9685;
  box-shadow: 0 8px 25px #70d9b31c;
  border-radius: 14px;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.fire:hover {
  background: #bbffde;
}

.fire span {
  font-size: 27px;
  font-weight: 900;
  letter-spacing: 3px;
}

.fire small {
  font-size: 9px;
  letter-spacing: 1.4px;
}

.fire-box > div {
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
}

.fire-box > div button {
  font-size: 11px;
  white-space: nowrap;
}

.levels {
  border-top: 1px solid #33415a;
  padding: 22px 0;
  display: flex;
  gap: 25px;
  align-items: center;
}

.levels > div {
  min-width: 0;
}

.tour-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.3px;
  color: var(--muted);
  margin: 10px 0 6px;
}

#tourSelect {
  max-width: 330px;
  min-height: 42px;
  font-size: 13px;
}

#tourDescription {
  color: var(--mint);
  font-size: 12px;
  margin: 8px 0;
}

.levels nav {
  display: flex;
  gap: 9px;
  flex: 1;
  justify-content: flex-end;
}

.levels button {
  width: 64px;
  height: 62px;
  padding: 7px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  border-radius: 12px;
}

.levels button small {
  font-size: 10px;
  color: var(--gold);
  letter-spacing: 1px;
}

.levels button.active {
  background: #294c52;
  border-color: var(--mint);
}

.levels .endless-box {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.levels .endless-box button {
  width: auto;
  height: auto;
  flex: none;
  flex-direction: row;
  gap: 8px;
  font-size: 12px;
  padding: 9px 13px;
  border-radius: 9px;
}

.levels .endless-box button small {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.levels #endless {
  border-color: var(--gold);
  color: var(--gold);
}

.levels #endless.active {
  background: #4a3d22;
}

#endlessBest {
  font-size: 9px;
  letter-spacing: 1.3px;
  color: var(--muted);
}

footer {
  font-size: 9px;
  letter-spacing: 2px;
  color: #91a1bf;
  padding: 8px 0 24px;
  max-width: 1400px;
  margin: auto;
  padding-left: 32px;
  padding-right: 32px;
  display: flex;
  justify-content: space-between;
}

.veil {
  position: absolute;
  inset: 0;
  background: #0a142cc7;
  backdrop-filter: blur(7px);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow: auto;
}

.veil[hidden], #tourPicker[hidden], #resultActions[hidden], #pauseMenu[hidden], .size-up-banner[hidden] {
  display: none;
}

.dialog {
  background: #18263f;
  border: 1px solid #586b86;
  box-shadow: 0 24px 80px #0007;
  border-radius: 20px;
  padding: 28px;
  width: min(510px, 100%);
  text-align: center;
  max-height: 100%;
  overflow: auto;
}

.dialog p {
  font-size: 13px;
  color: #c5d1e5;
  line-height: 1.55;
  text-align: left;
}

#dialogText {
  text-align: center;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  justify-content: center;
  margin-top: 14px;
}

.primary {
  background: var(--mint);
  color: #173439;
  font-weight: bold;
  border-color: var(--mint);
}

#stars {
  font-size: 40px;
  color: var(--gold);
  letter-spacing: 7px;
}

.tour-picker {
  text-align: left;
  border-top: 1px solid #43516b;
  padding-top: 8px;
  margin-top: 16px;
}

#nextTourSelect {
  min-height: 42px;
  font-size: 13px;
  margin-bottom: 12px;
}

.difficulty-picker {
  margin: 14px 0 18px;
  padding: 12px;
  border: 1px solid #375063;
  border-radius: 12px;
  background: #112639;
  text-align: left;
}

.difficulty-picker p {
  font-size: 12px;
  margin: 8px 0 0;
  color: #b5c7d4;
}

.credits {
  font-size: 11px !important;
  text-align: center !important;
}

.mobile-pause-slot {
  display: none;
}

@media (max-width: 860px) {
  header {
    padding: 12px 16px;
    height: 74px;
  }
  .sigil {
    display: none;
  }
  main, footer {
    padding-left: 14px;
    padding-right: 14px;
  }
  .console {
    gap: 16px;
    grid-template-columns: 1fr 1fr;
    padding: 18px 3px;
  }
  .brief {
    grid-column: 1 / -1;
  }
  .levels {
    display: block;
  }
  .levels nav {
    justify-content: space-between;
    margin-top: 14px;
  }
  .levels button {
    flex: 1;
    width: auto;
  }
  .hud {
    left: 14px;
    right: 14px;
    top: 14px;
  }
  h1 {
    font-size: 18px;
  }
  .stats {
    gap: 12px;
    padding: 8px 10px;
  }
  .stats strong {
    font-size: 20px;
  }
  .goal-track {
    top: 82px;
    right: 14px;
    width: 165px;
  }
}

@media (max-width: 640px) {
  header {
    height: auto;
    min-height: 54px;
    padding: 8px 10px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .back {
    font-size: 12px;
  }
  .brand {
    font-size: 12px;
    letter-spacing: 0.8px;
  }
  .brand b {
    font-size: 13px;
  }
  .brand small {
    display: none;
  }
  .tools {
    gap: 4px;
    margin-left: auto;
  }
  .tools button {
    padding: 6px 8px;
    font-size: 10px;
    border-radius: 7px;
  }
  main, footer {
    padding-left: 8px;
    padding-right: 8px;
  }
  .arena {
    height: 63dvh;
    min-height: 430px;
    border-radius: 14px;
  }
  .hud {
    left: 10px;
    right: 10px;
    top: 10px;
    flex-direction: column;
    gap: 6px;
  }
  .hud-left {
    max-width: 100%;
    width: 100%;
    gap: 6px;
  }
  .level-caption {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    flex-wrap: wrap;
  }
  .level-caption span {
    display: none;
  }
  h1 {
    font-size: 15px;
    margin: 0;
  }
  .difficulty-badge {
    margin-top: 0;
    padding: 3px 8px;
    font-size: 9px;
  }
  .goal-card {
    padding: 5px 8px;
    border-radius: 9px;
    width: 100%;
    gap: 4px;
  }
  .goal-card-title {
    display: none;
  }
  .goal-card-list {
    gap: 5px;
  }
  .goal-pill {
    padding: 3px 6px;
    font-size: 10px;
    border-radius: 6px;
    gap: 4px;
  }
  .goal-swatch {
    width: 9px;
    height: 9px;
  }
  .stats {
    width: 100%;
    justify-content: space-between;
    padding: 6px 10px;
    gap: 8px;
    border-radius: 9px;
  }
  .stats small {
    font-size: 7px;
    letter-spacing: 0.8px;
  }
  .stats strong {
    font-size: 15px;
  }
  .goal-track {
    display: none;
  }
  #toast {
    left: 10px;
    right: 10px;
    bottom: 48px;
    max-width: none;
    padding: 6px 10px;
    font-size: 10px;
  }
  .scene-actions {
    bottom: 10px;
    right: 10px;
    gap: 6px;
  }
  .scene-actions button {
    padding: 6px 10px;
    font-size: 10px;
  }
  .console {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px 4px;
  }
  .brief p {
    font-size: 12px;
    margin: 4px 0 8px;
  }
  .weapons {
    max-width: none;
  }
  .fire-box {
    justify-content: stretch;
  }
  .fire {
    flex: 1;
    min-height: 68px;
  }
  .fire span {
    font-size: 22px;
  }
}
