:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  height: 100%;
  background: #101521;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  display: grid;
  place-items: center;
  background: #101521;
  color: #f4f7fb;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mobile-controls-enabled,
.mobile-controls-enabled body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.shell {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: min(100vw, calc((100dvh - 72px) * 16 / 9), 1080px);
  height: 100dvh;
  padding: 20px;
  overflow: hidden;
}

canvas {
  width: 100%;
  align-self: end;
  aspect-ratio: 16 / 9;
  display: block;
  border: 1px solid #2d3b55;
  border-radius: 16px;
  background: #1d2638;
  box-shadow: 0 20px 60px rgb(0 0 0 / 35%);
}

.panel {
  margin-top: 12px;
  color: #b8c4d9;
  min-height: 40px;
}

.panel h1 {
  margin: 0 0 4px;
  font-size: 18px;
  color: #f4f7fb;
}

.panel p {
  margin: 0;
  font-size: 14px;
}

.panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.command-button,
.settings-button {
  margin-top: 8px;
  cursor: pointer;
  color: #dbe7ff;
  border: 1px solid #3f587d;
  border-radius: 6px;
  padding: 5px 9px;
  background: #172339;
  font: inherit;
  font-size: 13px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.command-button:hover,
.command-button:focus-visible,
.settings-button:hover,
.settings-button:focus-visible {
  border-color: #6d8fc1;
  color: #ffffff;
}

.settings-button {
  display: none;
}

.command-dialog,
.settings-dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: min(82dvh, 620px);
  overflow: auto;
  border: 1px solid #405a83;
  border-radius: 8px;
  padding: 16px;
  background: #121c2f;
  color: #dbe7ff;
  box-shadow: 0 24px 80px rgb(0 0 0 / 55%);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.command-dialog::backdrop,
.settings-dialog::backdrop {
  background: rgb(5 10 20 / 65%);
}

.command-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.command-dialog h2,
.settings-dialog h2 {
  margin: 0;
  font-size: 18px;
  color: #f4f7fb;
}

.command-dialog h3 {
  margin: 14px 0 8px;
  font-size: 14px;
  color: #f4f7fb;
}

.command-dialog h3:first-of-type {
  margin-top: 0;
}

.command-dialog__close {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  cursor: pointer;
  border: 1px solid #405a83;
  border-radius: 6px;
  background: #182640;
  color: #f4f7fb;
  font: inherit;
  font-size: 20px;
  line-height: 1;
}

.command-dialog dl {
  display: grid;
  gap: 8px;
  margin: 0 0 4px;
}

.command-dialog div {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 12px;
  align-items: baseline;
}

.command-dialog dt {
  color: #f4f7fb;
  font-weight: 700;
}

.command-dialog dd {
  margin: 0;
}

.settings-dialog fieldset {
  min-width: 0;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

.settings-dialog legend {
  margin-bottom: 8px;
  color: #f4f7fb;
  font-size: 14px;
  font-weight: 700;
}

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

.segmented-control button {
  min-height: 36px;
  cursor: pointer;
  border: 1px solid #405a83;
  border-radius: 6px;
  background: #172339;
  color: #dbe7ff;
  font: inherit;
  font-size: 13px;
}

.segmented-control button.is-selected {
  border-color: #8bb4ec;
  background: #28456f;
  color: #ffffff;
}

.touch-controls,
.orientation-hint {
  display: none;
}

.mobile-controls-enabled .touch-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 10px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.touch-stick,
.touch-actions {
  display: grid;
  gap: 8px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.touch-stick {
  align-content: center;
  width: var(--stick-size, 92px);
}

.touch-stick__gate {
  position: relative;
  width: var(--stick-size, 92px);
  height: var(--stick-size, 92px);
  border: 1px solid #506b96;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgb(80 107 150 / 20%) 0 28%, transparent 29%),
    #101a2c;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.touch-stick__gate::before,
.touch-stick__gate::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  background: rgb(219 231 255 / 18%);
  transform: translate(-50%, -50%);
}

.touch-stick__gate::before {
  width: 78%;
  height: 1px;
}

.touch-stick__gate::after {
  width: 1px;
  height: 78%;
}

.touch-stick__knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--stick-knob-size, 38px);
  height: var(--stick-knob-size, 38px);
  border: 1px solid #8bb4ec;
  border-radius: 50%;
  background: #28456f;
  transform: translate(-50%, -50%);
  box-shadow: 0 8px 18px rgb(0 0 0 / 35%);
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.touch-actions {
  justify-content: end;
  grid-template-columns: repeat(2, 64px);
}

.touch-controls button {
  min-height: 48px;
  border: 1px solid #506b96;
  border-radius: 8px;
  background: #172339;
  color: #f4f7fb;
  font: inherit;
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.touch-controls button:active,
.touch-controls button.is-pressed {
  background: #28456f;
  border-color: #8bb4ec;
}

@media (orientation: portrait) {
  .mobile-controls-enabled .orientation-hint {
    display: grid;
    position: fixed;
    inset: 0;
    z-index: 20;
    place-items: center;
    padding: 24px;
    background: rgb(8 13 24 / 92%);
    color: #f4f7fb;
    font-size: 18px;
    text-align: center;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .mobile-controls-enabled body {
    position: fixed;
    inset: 0;
    place-items: stretch;
  }

  .mobile-controls-enabled .shell {
    position: relative;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
    padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .mobile-controls-enabled canvas {
    width: min(100%, calc((100dvh - 88px) * 16 / 9));
    max-height: calc(100dvh - 88px);
    margin: 0 auto;
  }

  .mobile-controls-enabled .panel {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
  }

  .mobile-controls-enabled .panel h1,
  .mobile-controls-enabled .panel p {
    display: none;
  }

  .mobile-controls-enabled .command-button {
    position: static;
    margin: 0;
  }

  .mobile-controls-enabled .settings-button {
    display: block;
    margin: 0;
  }

  .mobile-controls-enabled .panel-actions {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    z-index: 12;
    margin: 0;
  }

  .mobile-controls-enabled .touch-controls {
    position: fixed;
    inset: auto 10px 8px var(--stick-left, 10px);
    z-index: 10;
    pointer-events: none;
  }

  .mobile-controls-enabled .touch-stick,
  .mobile-controls-enabled .touch-actions {
    pointer-events: auto;
  }
}
