:root {
  --bg: #071113;
  --panel: rgba(8, 22, 24, 0.88);
  --line: rgba(176, 236, 220, 0.18);
  --text: #eaf9f3;
  --muted: #94afa8;
  --mint: #7cf4cd;
  --cyan: #62d9ed;
  --amber: #f4ca73;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.46);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select {
  font: inherit;
}

.experiment,
#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

.experiment {
  min-width: 320px;
  isolation: isolate;
}

#scene {
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.panel {
  position: fixed;
  z-index: 2;
  top: 16px;
  left: 16px;
  width: min(348px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.title-row,
.actions,
.stats {
  display: flex;
  align-items: center;
}

.title-row {
  justify-content: space-between;
  gap: 16px;
}

.back-link {
  color: var(--cyan);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
}

.back-link:hover {
  color: var(--mint);
}

h1 {
  margin: 3px 0 0;
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.035em;
}

.premise {
  margin: 13px 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

button,
select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
}

button {
  padding: 0 12px;
  font-weight: 750;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

button:hover {
  border-color: rgba(124, 244, 205, 0.5);
  background: rgba(124, 244, 205, 0.1);
  transform: translateY(-1px);
}

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

.pulse-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border-color: rgba(124, 244, 205, 0.44);
  color: var(--mint);
}

.pulse-icon {
  position: relative;
  width: 18px;
  height: 18px;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.pulse-icon::after {
  position: absolute;
  inset: 4px;
  border: 1px solid currentColor;
  border-radius: inherit;
  content: "";
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 10px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stats span {
  display: grid;
  gap: 3px;
  padding: 0 8px;
  border-left: 1px solid var(--line);
}

.stats span:first-child {
  padding-left: 0;
  border-left: 0;
}

.stats small {
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.stats strong {
  overflow: hidden;
  color: var(--amber);
  font-family: var(--mono);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  gap: 8px;
  margin-top: 12px;
}

.actions label {
  flex: 1;
}

select {
  width: 100%;
  padding: 0 28px 0 10px;
}

.movement {
  display: none;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(2, 42px);
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}

.movement button {
  min-height: 42px;
  padding: 0;
  font-size: 20px;
}

.movement button[data-direction="north"] {
  grid-column: 2;
}

.movement button[data-direction="west"] {
  grid-column: 1;
  grid-row: 2;
}

.movement button[data-direction="south"] {
  grid-column: 2;
  grid-row: 2;
}

.movement button[data-direction="east"] {
  grid-column: 3;
  grid-row: 2;
}

.hint {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
  text-align: center;
}

kbd {
  color: var(--text);
  font-family: var(--mono);
}

.victory {
  position: fixed;
  z-index: 3;
  top: 50%;
  left: calc(50% + 174px);
  display: grid;
  width: min(310px, calc(100vw - 32px));
  gap: 10px;
  padding: 20px;
  border: 1px solid rgba(124, 244, 205, 0.45);
  border-radius: 12px;
  background: rgba(8, 22, 24, 0.95);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, -45%);
  transition: opacity 180ms ease, transform 180ms ease;
}

.victory.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

.victory .eyebrow {
  color: var(--mint);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.victory strong {
  font-size: 25px;
}

.victory button {
  border-color: rgba(124, 244, 205, 0.52);
  background: var(--mint);
  color: #09201a;
}

.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;
}

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(98, 217, 237, 0.4);
  outline-offset: 2px;
}

@media (hover: none), (pointer: coarse) {
  .movement {
    display: grid;
  }
}

@media (max-width: 760px) {
  .panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 12px 12px 0 0;
  }

  h1 {
    font-size: 23px;
  }

  .premise,
  .hint {
    display: none;
  }

  .stats {
    margin-top: 10px;
    padding: 8px 0;
  }

  .actions {
    margin-top: 9px;
  }

  .movement {
    position: absolute;
    right: 14px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(3, 39px);
    grid-template-rows: repeat(2, 35px);
    margin: 0;
  }

  .movement button {
    min-height: 35px;
    font-size: 17px;
  }

  .actions {
    width: calc(100% - 137px);
    height: 76px;
    align-items: flex-end;
  }

  .victory {
    top: 34%;
    left: 50%;
  }
}

@media (max-height: 560px) and (min-width: 761px) {
  .premise,
  .hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
