:root {
  --bg: #05070c;
  --panel: rgba(8, 14, 24, 0.86);
  --panel-strong: rgba(11, 18, 31, 0.96);
  --line: rgba(125, 249, 255, 0.24);
  --line-hot: rgba(255, 57, 95, 0.42);
  --text: #f4fbff;
  --muted: #a6b6c8;
  --cyan: #49f2ff;
  --green: #7cffb2;
  --red: #ff395f;
  --yellow: #ffd166;
  --violet: #a575ff;
  --shadow-cyan: 0 0 26px rgba(73, 242, 255, 0.28);
  --shadow-red: 0 0 26px rgba(255, 57, 95, 0.22);
  font-family: "Heebo", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 57, 95, 0.16), transparent 24rem),
    radial-gradient(circle at 84% 18%, rgba(73, 242, 255, 0.13), transparent 25rem),
    linear-gradient(145deg, #030509 0%, #07101d 48%, #08050d 100%);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.ambient-grid,
.noise-layer,
.code-rain {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.ambient-grid {
  background:
    linear-gradient(rgba(73, 242, 255, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(73, 242, 255, 0.055) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.95), transparent 92%);
}

.noise-layer {
  opacity: 0.12;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 2px, rgba(255, 255, 255, 0.12) 3px),
    repeating-linear-gradient(90deg, transparent 0 7px, rgba(255, 255, 255, 0.05) 8px);
  mix-blend-mode: screen;
}

.code-rain {
  z-index: 0;
  overflow: hidden;
  opacity: 0.18;
  color: rgba(73, 242, 255, 0.62);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.78rem;
  direction: ltr;
}

.code-rain span {
  position: absolute;
  top: -12vh;
  display: block;
  min-width: 240px;
  text-shadow: 0 0 12px rgba(73, 242, 255, 0.35);
  animation: codeFall 19s linear infinite;
}

.code-rain span:nth-child(1) { left: 5%; animation-delay: -2s; animation-duration: 21s; }
.code-rain span:nth-child(2) { left: 17%; animation-delay: -11s; animation-duration: 17s; }
.code-rain span:nth-child(3) { left: 29%; animation-delay: -5s; animation-duration: 24s; }
.code-rain span:nth-child(4) { left: 41%; animation-delay: -15s; animation-duration: 20s; }
.code-rain span:nth-child(5) { left: 53%; animation-delay: -8s; animation-duration: 18s; }
.code-rain span:nth-child(6) { left: 65%; animation-delay: -13s; animation-duration: 23s; }
.code-rain span:nth-child(7) { left: 76%; animation-delay: -4s; animation-duration: 19s; }
.code-rain span:nth-child(8) { left: 86%; animation-delay: -17s; animation-duration: 22s; }
.code-rain span:nth-child(9) { left: 12%; animation-delay: -18s; animation-duration: 26s; }
.code-rain span:nth-child(10) { left: 70%; animation-delay: -1s; animation-duration: 16s; }

@keyframes codeFall {
  from { transform: translate3d(0, -14vh, 0); }
  to { transform: translate3d(0, 124vh, 0); }
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0;
}

.screen {
  display: grid;
  gap: 18px;
  align-content: center;
}

.intro-screen {
  grid-template-columns: minmax(0, 800px);
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 36px);
}

.intro-copy,
.dashboard-head,
.puzzle-stage,
.end-panel,
.mission-bar {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow-cyan);
  backdrop-filter: blur(14px);
}

.intro-copy,
.dashboard-head,
.puzzle-stage,
.end-panel {
  border-radius: 8px;
  padding: clamp(18px, 2.4vw, 30px);
}

.intro-copy {
  border-color: var(--line-hot);
  box-shadow: var(--shadow-red);
  width: 100%;
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.15;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2.35rem, 5.4vw, 4.8rem);
  text-shadow: 2px 0 rgba(73, 242, 255, 0.8), -2px 0 rgba(255, 57, 95, 0.75);
}

h2 {
  font-size: clamp(1.55rem, 3vw, 2.7rem);
}

h3 {
  font-size: 1.25rem;
}

p {
  color: var(--muted);
  line-height: 1.7;
}

.lead {
  color: #d9e8f6;
  font-size: clamp(1.05rem, 2vw, 1.28rem);
}

.story {
  margin: 16px 0 20px;
}

.intro-copy .story,
.intro-copy .primary-button {
  visibility: hidden;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  animation: revealMission 0.7s ease forwards;
}

.intro-copy .story {
  animation-delay: 4.8s;
}

.intro-copy .primary-button {
  animation-delay: 5.35s;
}

.nexus-chat {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid rgba(255, 57, 95, 0.26);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  text-align: right;
}

.chat-message {
  width: fit-content;
  max-width: min(100%, 560px);
  min-height: 32px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 8px;
  opacity: 0;
  transform: translateY(8px);
  animation: chatIn 0.48s ease forwards;
}

.chat-user {
  justify-self: start;
  color: #d9e8f6;
  background: rgba(255, 255, 255, 0.07);
  animation-delay: 0.35s;
}

.chat-nexus {
  justify-self: end;
  color: #ffdce4;
  border-color: rgba(255, 57, 95, 0.36);
  background: rgba(255, 57, 95, 0.11);
  box-shadow: 0 0 16px rgba(255, 57, 95, 0.12);
}

.chat-nexus:nth-child(2) { animation-delay: 1.2s; }
.chat-nexus:nth-child(3) { animation-delay: 2.15s; }
.chat-nexus:nth-child(4) { animation-delay: 3.15s; }

@keyframes chatIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes revealMission {
  to {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .code-rain span,
  .chat-message,
  .intro-copy .story,
  .intro-copy .primary-button,
  .personal-message,
  .typing-message.is-typing::after {
    animation: none;
  }

  .chat-message,
  .intro-copy .story,
  .intro-copy .primary-button,
  .personal-message {
    visibility: visible;
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

  .typing-message.is-typing::after {
    display: none;
  }
}

.primary-button,
.danger-button,
.ghost-button,
.soft-button,
.choice-button,
.canvas-item {
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.primary-button,
.danger-button {
  min-height: 42px;
  padding: 9px 18px;
  font-weight: 800;
}

.primary-button {
  border-color: rgba(124, 255, 178, 0.42);
  background: linear-gradient(135deg, rgba(124, 255, 178, 0.2), rgba(73, 242, 255, 0.13));
  box-shadow: 0 0 20px rgba(124, 255, 178, 0.18);
}

.danger-button {
  border-color: rgba(255, 57, 95, 0.55);
  background: linear-gradient(135deg, rgba(255, 57, 95, 0.24), rgba(165, 117, 255, 0.16));
  box-shadow: var(--shadow-red);
}

.ghost-button,
.soft-button {
  min-height: 34px;
  padding: 7px 12px;
  border-color: var(--line);
}

.ghost-button:hover,
.soft-button:hover,
.primary-button:hover,
.danger-button:hover,
.choice-button:hover,
.canvas-item:hover {
  transform: translateY(-1px);
  border-color: rgba(73, 242, 255, 0.72);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.mission-bar {
  position: sticky;
  top: 12px;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 8px;
}

.timer {
  color: var(--yellow);
  font-size: clamp(1.15rem, 2.2vw, 1.65rem);
  font-variant-numeric: tabular-nums;
}

.progress {
  color: var(--green);
  font-size: clamp(1.05rem, 1.7vw, 1.4rem);
}

.dashboard {
  align-content: start;
}

.dashboard-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: end;
  border-radius: 8px;
}

.code-strip {
  display: grid;
  grid-template-columns: repeat(6, 44px);
  gap: 8px;
  direction: ltr;
}

.code-cell {
  display: grid;
  place-items: center;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--cyan);
  background: rgba(0, 0, 0, 0.25);
  font-weight: 900;
  font-size: 1.35rem;
  box-shadow: inset 0 0 18px rgba(73, 242, 255, 0.08);
}

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

.puzzle-card {
  min-height: 158px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(73, 242, 255, 0.08), rgba(255, 57, 95, 0.04)),
    rgba(8, 14, 24, 0.82);
}

.puzzle-card.solved {
  border-color: rgba(124, 255, 178, 0.56);
  box-shadow: 0 0 22px rgba(124, 255, 178, 0.14);
}

.dashboard-actions {
  margin-top: 12px;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.status-pill {
  display: inline-grid;
  place-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: var(--muted);
}

.status-pill.solved {
  color: var(--green);
  border-color: rgba(124, 255, 178, 0.5);
}

.puzzle-layout {
  align-content: start;
}

.puzzle-stage {
  display: grid;
  gap: 16px;
  border-radius: 8px;
}

.puzzle-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
}

.puzzle-number {
  color: var(--yellow);
  font-weight: 900;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.content-grid > :only-child {
  grid-column: 1 / -1;
}

.code-block,
.hidden-zone,
.table-wrap,
.mini-canvas,
.answer-panel,
.visual-card,
.variant-table {
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
}

.code-block {
  direction: ltr;
  padding: 18px;
  overflow-x: auto;
  color: #eafff4;
  font-weight: 800;
  line-height: 1.8;
}

.answer-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.solved-panel {
  justify-items: center;
  text-align: center;
  border-color: rgba(124, 255, 178, 0.5);
  background:
    linear-gradient(135deg, rgba(124, 255, 178, 0.12), rgba(73, 242, 255, 0.08)),
    rgba(0, 0, 0, 0.25);
}

.solved-letter {
  display: grid;
  place-items: center;
  width: min(180px, 52vw);
  aspect-ratio: 1;
  border: 1px solid rgba(124, 255, 178, 0.68);
  border-radius: 8px;
  color: var(--green);
  background: rgba(3, 12, 12, 0.72);
  box-shadow: 0 0 32px rgba(124, 255, 178, 0.24), inset 0 0 22px rgba(124, 255, 178, 0.08);
  font-size: clamp(4.5rem, 13vw, 8.5rem);
  font-weight: 900;
  line-height: 1;
  direction: ltr;
}

.solution-explanation {
  max-width: 760px;
  margin: 0;
  color: #d9e8f6;
  font-size: 1.02rem;
}

.answer-panel input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(4, 8, 14, 0.8);
}

.answer-panel input:focus,
button:focus-visible,
.canvas-item:focus-visible,
.variant-table button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.feedback {
  min-height: 28px;
  margin: 0;
  color: var(--yellow);
  font-weight: 700;
}

.feedback.success {
  color: var(--green);
}

.feedback.error {
  color: #ff8ba2;
}

.hidden-zone {
  min-height: 220px;
  padding: 8px 0;
  border-color: transparent;
  background: transparent;
}

.secret-text,
.secret-link {
  color: transparent;
  user-select: text;
}

.hidden-zone ::selection {
  color: var(--text);
  background: rgba(73, 242, 255, 0.42);
}

.secret-link {
  display: inline-block;
  margin-bottom: 14px;
  text-decoration: none;
  cursor: default;
}

.revealed-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

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

.choice-button {
  min-height: 46px;
  padding: 10px;
}

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

.visual-card {
  display: grid;
  gap: 6px;
  min-height: 220px;
  padding: 10px;
}

.buildings .visual-card {
  text-align: center;
  justify-items: center;
}

.building-image {
  align-self: end;
  justify-self: center;
  width: min(150px, 72%);
  height: 148px;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 0 18px rgba(73, 242, 255, 0.2));
}

.variant-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

.variant-table th,
.variant-table td {
  padding: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-align: right;
}

.variant-row {
  width: 100%;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: right;
}

.variant-demo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 112px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 800;
}

.variant-demo-filled {
  border: 1px solid rgba(73, 242, 255, 0.58);
  color: #041017;
  background: var(--cyan);
  box-shadow: 0 0 16px rgba(73, 242, 255, 0.22);
}

.variant-demo-outline {
  border: 1px solid rgba(73, 242, 255, 0.72);
  color: var(--cyan);
  background: transparent;
}

.variant-demo-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid currentColor;
  border-radius: 50%;
  line-height: 1;
}

.variant-table tr:hover {
  background: rgba(73, 242, 255, 0.08);
}

.mini-canvas {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
}

.canvas-item {
  display: grid;
  place-items: center;
  min-height: 46px;
  padding: 8px;
  text-align: center;
}

.canvas-item.selected {
  border-color: rgba(73, 242, 255, 0.72);
  box-shadow: 0 0 20px rgba(73, 242, 255, 0.22);
}

.search-mock {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.08);
}

.simple-link {
  color: var(--cyan);
}

.end-panel {
  max-width: 760px;
  width: min(760px, 100%);
  margin: auto;
}

.final-success {
  border-color: rgba(124, 255, 178, 0.62);
  box-shadow: 0 0 44px rgba(124, 255, 178, 0.25);
}

.personal-message {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  margin: 18px 0 16px;
  padding: 12px;
  border: 1px solid rgba(124, 255, 178, 0.34);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translateY(12px);
  animation: personalMessageIn 0.7s ease 2s forwards;
  text-align: right;
}

.profile-photo {
  width: 78px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(124, 255, 178, 0.58);
  object-fit: cover;
  box-shadow: 0 0 22px rgba(124, 255, 178, 0.2);
}

.personal-copy {
  width: 100%;
  min-width: 0;
}

.message-from {
  margin: 0 0 8px;
  color: var(--green);
  font-weight: 900;
}

.typing-message-shell {
  display: grid;
  position: relative;
  margin: 0;
  color: #d9e8f6;
  line-height: 1.55;
  direction: rtl;
  unicode-bidi: plaintext;
  white-space: pre-wrap;
  text-align: right;
}

.typing-message-reserve,
.typing-message {
  grid-area: 1 / 1;
  max-width: 100%;
  white-space: pre-wrap;
}

.typing-message-reserve {
  visibility: hidden;
  pointer-events: none;
}

.typing-message.is-typing::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1.1em;
  margin-inline-start: 5px;
  background: var(--green);
  vertical-align: -0.18em;
  animation: cursorBlink 0.8s step-end infinite;
}

@keyframes personalMessageIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cursorBlink {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

@media (min-width: 861px) and (max-height: 760px) {
  .app-shell {
    width: min(1160px, calc(100% - 24px));
    padding: 10px 0;
  }

  .intro-screen {
    min-height: calc(100vh - 20px);
  }

  .intro-copy,
  .dashboard-head,
  .puzzle-stage,
  .end-panel {
    padding: 16px 20px;
  }

  h1 {
    font-size: clamp(2.2rem, 4.8vw, 4rem);
  }

  h2 {
    font-size: clamp(1.45rem, 2.6vw, 2.25rem);
  }

  p {
    line-height: 1.55;
  }

  .lead {
    font-size: 1rem;
  }

  .story {
    margin: 12px 0 16px;
  }

  .mission-bar {
    top: 6px;
    margin-bottom: 8px;
    padding: 8px 10px;
  }

  .dashboard-head {
    align-items: center;
  }

  .puzzle-card {
    min-height: 138px;
    padding: 12px;
  }

  .puzzle-card p {
    margin: 8px 0 0;
  }

  .visual-card {
    min-height: 192px;
  }

  .building-image {
    height: 124px;
  }

  .hidden-zone {
    min-height: 180px;
  }

  .solved-letter {
    width: 132px;
    font-size: 5.4rem;
  }

  .personal-message {
    grid-template-columns: 64px minmax(0, 1fr);
    margin: 12px 0;
    padding: 10px;
  }

  .profile-photo {
    width: 64px;
  }
}

.final-failure,
.time-failure {
  border-color: rgba(255, 57, 95, 0.72);
  box-shadow: 0 0 44px rgba(255, 57, 95, 0.28);
}

.reset-zone {
  margin-top: 30px;
  text-align: center;
}

.reset-zone button {
  opacity: 0.42;
  font-size: 0.82rem;
}

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

@media (max-width: 860px) {
  .intro-screen,
  .content-grid,
  .dashboard-head {
    grid-template-columns: 1fr;
  }

  .puzzle-grid,
  .buildings,
  .mini-canvas {
    grid-template-columns: 1fr;
  }

  .mission-bar {
    grid-template-columns: 1fr 1fr;
  }

  .mission-bar .ghost-button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .intro-copy,
  .dashboard-head,
  .puzzle-stage,
  .end-panel {
    padding: 18px;
  }

  .personal-message {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .code-strip {
    grid-template-columns: repeat(6, minmax(34px, 1fr));
  }
}
