:root {
  color-scheme: dark;
  --bg: #101014;
  --case: #23242a;
  --bezel: #08090b;
  --amber: #f2b84b;
  --green: #4ef07d;
  --cyan: #56d7ff;
  --paper: #e7dfc8;
  --muted: #8c917f;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(120deg, rgba(78, 240, 125, 0.08), transparent 42%),
    radial-gradient(circle at 80% 15%, rgba(242, 184, 75, 0.1), transparent 28%),
    var(--bg);
  color: var(--paper);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  overflow: hidden;
}

.cockpit {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 280px;
  gap: 18px;
  padding: 18px;
}

.screen-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(145deg, #30313a, var(--case));
  border: 2px solid #454753;
  box-shadow: inset 0 0 0 10px #17181d, 0 24px 60px rgba(0, 0, 0, 0.35);
}

canvas {
  width: min(100%, calc((100vh - 72px) * 1.333));
  max-height: calc(100vh - 72px);
  aspect-ratio: 4 / 3;
  image-rendering: pixelated;
  background: #020403;
  border: 12px solid var(--bezel);
  box-shadow: 0 0 0 2px #555862, inset 0 0 24px rgba(78, 240, 125, 0.15);
}

.panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 18px;
  padding: 18px;
  background: #1c1d22;
  border: 2px solid #383a42;
  overflow: auto;
}

.label {
  margin: 0 0 8px;
  color: var(--amber);
  font-size: 12px;
  letter-spacing: 0;
}

.title-line {
  margin: 0;
  color: var(--green);
  font-size: 15px;
  line-height: 1;
  font-weight: 800;
}

.mission {
  min-height: 144px;
  display: flex;
  align-items: center;
  padding: 14px;
  color: #111;
  background: var(--paper);
  border: 2px solid var(--muted);
  font-size: 15px;
  line-height: 1.45;
}

.help-panel {
  width: 100%;
  text-align: left;
  font: inherit;
  padding: 14px;
  border: 1px solid #3e4745;
  background: #11181a;
  cursor: pointer;
}

.help-panel:hover,
.help-panel:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.help-panel h2 {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 18px;
  line-height: 1.1;
}

.help-panel ol {
  margin: 0;
  padding-left: 22px;
  color: #d6dccb;
  font-size: 13px;
  line-height: 1.45;
}

.help-panel li + li {
  margin-top: 6px;
}

.keys {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 8px 10px;
  align-items: center;
  color: #cfd4c5;
  font-size: 14px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.keys span {
  -webkit-user-select: none;
  user-select: none;
}

.control-key {
  display: inline-grid;
  place-items: center;
  width: 46px;
  min-width: 0;
  height: 30px;
  padding: 0;
  color: var(--cyan);
  background: #090a0d;
  border: 1px solid #444853;
  box-shadow: inset 0 -3px 0 rgba(255, 255, 255, 0.06);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.control-key:active,
.control-key.is-active {
  color: #09100c;
  background: var(--green);
  border-color: var(--green);
}

.control-key:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(2, 4, 3, 0.78);
}

.modal-card {
  width: min(920px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: auto;
  padding: 18px;
  background: #11181a;
  border: 2px solid var(--green);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  color: var(--green);
  font-size: 22px;
}

.modal-head button {
  width: 34px;
  height: 34px;
  color: var(--cyan);
  background: #090a0d;
  border: 1px solid #444853;
  font: inherit;
  font-size: 22px;
  cursor: pointer;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.modal-grid section {
  padding: 12px;
  border: 1px solid #3e4745;
  background: #0b1011;
}

.modal-grid h3 {
  margin: 0 0 10px;
  color: var(--amber);
  font-size: 15px;
}

.modal-grid p,
.modal-foot {
  margin: 0;
  color: #d6dccb;
  font-size: 13px;
  line-height: 1.45;
}

.modal-grid p + p {
  margin-top: 8px;
}

.modal-foot {
  margin-top: 14px;
  color: var(--cyan);
}

@media (max-width: 820px), (pointer: coarse) {
  body {
    overflow: auto;
  }

  .cockpit {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  canvas {
    width: 100%;
    max-height: none;
  }

  .panel {
    min-height: 260px;
  }

  .mission {
    display: none;
  }

  .keys {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .keys span {
    display: none;
  }

  .control-key {
    width: 100%;
    height: 58px;
    font-size: 20px;
  }

  .control-key[data-key="arrowup"] {
    order: 1;
  }

  .control-key[data-key="a"] {
    order: 2;
  }

  .control-key[data-key="arrowdown"] {
    order: 3;
  }

  .control-key[data-key="z"] {
    order: 4;
  }

  .control-key[data-key="arrowleft"] {
    order: 5;
  }

  .control-key[data-key="arrowright"] {
    order: 6;
  }

  .control-key[data-key="f"] {
    order: 7;
  }

  .control-key[data-key="g"] {
    order: 8;
  }

  .control-key[data-key="h"] {
    order: 9;
  }

  .control-key[data-key="r"] {
    order: 10;
  }

  .modal-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px), (pointer: coarse) {
  .panel {
    gap: 12px;
  }

  .help-panel {
    padding: 12px;
  }

  .control-key {
    height: 60px;
  }
}
