:root {
  --panel: rgba(4, 9, 7, 0.82);
  --line: rgba(163, 245, 185, 0.22);
  --text: #e6f7e9;
  --muted: #a1b5a7;
  --green: #9ff09a;
  --yellow: #dfce73;
  --red: #f26b61;
  --cyan: #93f0c2;
  --button: #142018;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  background: #101815;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body::after {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(rgba(160, 255, 190, 0.035) 50%, rgba(0, 0, 0, 0.04) 50%),
    radial-gradient(circle at center, transparent 38%, rgba(0, 0, 0, 0.34) 100%);
  background-size: 100% 4px, 100% 100%;
  mix-blend-mode: screen;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  filter: saturate(0.75) contrast(1.08);
}

.mission-panel,
.data-panel,
.feedback-panel,
.controls {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(8px);
}

.hud-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 8;
  min-width: 62px;
  height: 38px;
  background: rgba(9, 18, 12, 0.88);
}

.hud-hidden .mission-panel,
.hud-hidden .data-panel,
.hud-hidden .feedback-panel {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}

.mission-panel,
.data-panel,
.feedback-panel {
  transition: opacity 180ms ease, transform 180ms ease;
}

.mission-panel {
  top: 14px;
  left: 14px;
  width: min(560px, calc(100vw - 28px));
  padding: 12px;
}

.mission-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.mission-head strong {
  display: block;
  font-size: 16px;
  line-height: 1.15;
}

.mission-head span,
.mission-meta,
.panel-title,
.readout dt,
.metric span:first-child {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

#missionStatus {
  flex: 0 0 auto;
  min-width: 82px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  background: rgba(159, 240, 154, 0.1);
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

#missionStatus[data-state="Complete"] {
  color: var(--green);
  border-color: rgba(159, 240, 154, 0.62);
}

.mission-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
}

.data-panel {
  top: 112px;
  left: 14px;
  width: 292px;
  padding: 12px;
}

.panel-title {
  margin-bottom: 9px;
  font-weight: 850;
  color: #dff4e3;
}

.readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 12px;
}

.readout div {
  min-width: 0;
  padding: 8px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.readout dt,
.readout dd {
  margin: 0;
}

.readout dd {
  margin-top: 3px;
  font-size: 15px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric {
  display: block;
  margin-top: 10px;
}

.metric span:first-child {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}

.bar {
  display: block;
  height: 8px;
  background: rgba(13, 20, 15, 0.95);
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #5fbf84, var(--green));
  transition: width 140ms linear;
}

.bar.goal {
  margin-top: 10px;
  height: 9px;
}

.bar.stress > span {
  background: linear-gradient(90deg, var(--yellow), var(--red));
}

.bar.decay > span {
  background: linear-gradient(90deg, var(--cyan), var(--yellow));
}

.feedback-panel {
  top: 14px;
  right: 90px;
  width: min(360px, calc(100vw - 28px));
  min-height: 64px;
  padding: 12px;
  color: #dff2e1;
  font-size: 14px;
  line-height: 1.35;
}

.controls {
  left: 14px;
  bottom: 14px;
  display: flex;
  gap: 8px;
  padding: 10px;
}

.event-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
}

.event-overlay::before {
  position: absolute;
  inset: 0;
  content: "";
  opacity: 0;
}

.event-overlay::after {
  position: absolute;
  inset: 0;
  content: "";
  opacity: 0;
}

.event-overlay.is-visible {
  animation: overlayFade 760ms ease-out both;
}

.event-overlay.is-reward::before {
  background: radial-gradient(circle at center, rgba(234, 255, 134, 0.28), rgba(30, 120, 42, 0.08) 38%, transparent 68%);
  animation: rewardBloom 760ms ease-out both;
}

.event-overlay.is-punishment::before {
  background: rgba(255, 54, 54, 0.18);
  animation: shockFlash 680ms steps(3, end) both;
}

.event-overlay.is-punishment::after {
  background:
    linear-gradient(105deg, transparent 0 42%, rgba(210, 250, 255, 0.72) 43% 45%, transparent 46% 100%),
    linear-gradient(74deg, transparent 0 52%, rgba(112, 220, 255, 0.44) 53% 55%, transparent 56% 100%);
  animation: shockSlash 680ms ease-out both;
}

.event-overlay.is-complete::before {
  background: radial-gradient(circle at center, rgba(159, 240, 154, 0.3), transparent 62%);
  animation: rewardBloom 1100ms ease-out both;
}

.event-overlay__symbol,
.event-overlay__label {
  position: relative;
  z-index: 1;
  padding: 8px 12px;
  border: 1px solid rgba(230, 255, 226, 0.28);
  background: rgba(5, 12, 8, 0.72);
  color: #f7ffe9;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.event-overlay__symbol {
  min-width: 130px;
  font-size: 20px;
  letter-spacing: 0;
}

.event-overlay__label {
  position: absolute;
  top: calc(50% + 36px);
  font-size: 12px;
  color: #cfead0;
}

.success-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  pointer-events: none;
  opacity: 0;
  z-index: 7;
  transition: opacity 220ms ease;
}

.success-modal::before {
  position: absolute;
  inset: 0;
  content: "";
  background:
    radial-gradient(circle at 50% 36%, rgba(239, 218, 103, 0.28), transparent 34%),
    rgba(1, 6, 4, 0.66);
  backdrop-filter: blur(6px);
}

.success-modal.is-visible {
  pointer-events: auto;
  opacity: 1;
}

.success-card {
  position: relative;
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 18px;
  width: min(620px, calc(100vw - 28px));
  padding: 18px;
  border: 1px solid rgba(241, 213, 104, 0.44);
  background: rgba(5, 12, 8, 0.9);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
}

.success-art {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 156px;
  overflow: hidden;
  background: radial-gradient(circle, rgba(241, 213, 104, 0.16), rgba(159, 240, 154, 0.05) 55%, transparent 70%);
}

.success-rays {
  position: absolute;
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(255, 234, 120, 0.26) 0 8deg, transparent 8deg 18deg);
  animation: successSpin 9s linear infinite;
}

.success-cheese {
  position: relative;
  z-index: 1;
  width: 116px;
  height: 86px;
  transform: rotate(-7deg);
  background: linear-gradient(145deg, #ffe57a, #e6b935 58%, #9c711e);
  clip-path: polygon(0 20%, 100% 0, 72% 100%, 8% 82%);
  border: 4px solid #735217;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.34);
}

.success-cheese span {
  position: absolute;
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #9b741c;
}

.success-cheese span:nth-child(1) {
  left: 30px;
  top: 34px;
}

.success-cheese span:nth-child(2) {
  right: 26px;
  top: 24px;
  width: 20px;
  height: 20px;
}

.success-cheese span:nth-child(3) {
  right: 44px;
  bottom: 16px;
  width: 13px;
  height: 13px;
}

.success-copy {
  align-self: center;
  min-width: 0;
}

.success-kicker {
  display: inline-block;
  margin-bottom: 6px;
  color: #f5de6f;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.success-copy h2 {
  margin: 0;
  font-size: 34px;
  line-height: 1;
}

.success-copy p {
  margin: 10px 0 0;
  color: #cfe1cf;
  font-size: 14px;
  line-height: 1.4;
}

.success-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.success-actions button:first-child {
  color: #11170f;
  background: #f1d568;
  border-color: #f1d568;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 94px;
  height: 42px;
  color: var(--text);
  background: var(--button);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: rgba(218, 255, 220, 0.5);
  background: #1d2c22;
}

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

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

.icon {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  line-height: 1;
}

@media (max-width: 760px) {
  .mission-panel,
  .feedback-panel,
  .data-panel {
    left: 10px;
    right: 10px;
    width: auto;
  }

  .feedback-panel {
    top: auto;
    bottom: 76px;
    min-height: auto;
    font-size: 12px;
  }

  .hud-toggle {
    top: 10px;
    right: 10px;
    min-width: 58px;
    height: 36px;
  }

  .data-panel {
    top: 104px;
    padding: 10px;
  }

  .readout {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .readout div {
    padding: 6px;
  }

  .readout dd {
    font-size: 12px;
  }

  .controls {
    right: 10px;
    left: 10px;
    bottom: 10px;
    justify-content: space-between;
    gap: 6px;
    padding: 8px;
  }

  button {
    min-width: 0;
    flex: 1;
    height: 42px;
    padding: 0 6px;
    font-size: 12px;
  }

  .success-card {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 14px;
  }

  .success-art {
    min-height: 132px;
  }

  .success-copy h2 {
    font-size: 28px;
  }

  .success-actions {
    flex-direction: column;
  }
}

@media (max-height: 620px) and (max-width: 760px) {
  .data-panel {
    display: none;
  }
}

@keyframes overlayFade {
  0% {
    opacity: 0;
  }

  14% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@keyframes rewardBloom {
  0% {
    opacity: 0;
    transform: scale(0.72);
  }

  28% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: scale(1.18);
  }
}

@keyframes shockFlash {
  0% {
    opacity: 0;
  }

  18% {
    opacity: 1;
  }

  36% {
    opacity: 0.2;
  }

  58% {
    opacity: 0.9;
  }

  100% {
    opacity: 0;
  }
}

@keyframes shockSlash {
  0% {
    opacity: 0;
    transform: translateX(-6vw);
  }

  30% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translateX(6vw);
  }
}

@keyframes successSpin {
  to {
    transform: rotate(360deg);
  }
}
