:root {
  --gap: 10px;
  --bg: #0f1115;
  --panel: #161a22;
  --text: #e8eaf0;
  --accent: #4da3ff;
  --muted: #9fb4d9;
  --err: #ff6b6b;

  --key-bg: #ffffff;
  --key-border: #000000;
  --key-text: #000000;

  --blue-3d: #2f5997;
  --grey-view: #777777;
  --red-help: #e15c5c;
  --black-main: #111111;

  --key-gap: 6px;
  --key-radius: 6px;
  --key-font:
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font:
    14px/1.4 system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial,
    sans-serif;
}

.wrap {
  display: flex;
  height: 100dvh;
  gap: var(--gap);
  padding: var(--gap);
  box-sizing: border-box;
  overflow: hidden;
}

.col {
  background: var(--panel);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.col.video {
  flex: 1 1 auto;
  position: relative;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #0c1017;
  border-bottom: 1px solid #222838;
}

header h1 {
  font-size: 14px;
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.toolbar {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  background: #1e2633;
  color: #d9e6ff;
  border: 1px solid #2c384d;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
}

#btnShare {
  display: none;
}

.video-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

#pilotVideo {
  width: 100%;
  height: 100%;
  background: #000;
  /* background: linear-gradient(
    45deg,
    red,
    orange,
    yellow,
    green,
    blue,
    indigo,
    violet,
    red
  ); */

  object-fit: fill;
}

#cvOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#recStatus {
  font-size: 12px;
  color: #9fb4d9;
  margin-left: 8px;
}

.footer {
  padding: 8px 12px;
  background: #0c1017;
  border-top: 1px solid #222838;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hint {
  font-size: 12px;
  opacity: 0.75;
}

.status {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 10px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #1e2633;
  border: 1px solid #2c384d;
  font-size: 12px;
  display: none;
  z-index: 80;
}

.status.show {
  display: block;
}

.status.err {
  color: var(--err);
}

.kbd {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid #2c384d;
  border-radius: 6px;
  background: #0c1017;
  margin: 0 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 55%);
  display: none;
  z-index: 90;
}

.modal {
  position: fixed;
  inset: auto;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(1000px, calc(100vw - 32px));
  max-height: 80vh;
  overflow-x: visible;
  overflow-y: auto;
  background: #101522;
  border: 1px solid #2c384d;
  border-radius: 12px;
  padding: 16px 16px 10px;
  display: none;
  z-index: 91;
}

.modal-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal.show,
.modal-backdrop.show {
  display: block;
}

.modal h2 {
  margin: 0 0 10px;
  font-size: 16px;
  color: #d9e6ff;
}

.key-blue {
  background-color: var(--blue-3d);
}

.key-red {
  background-color: var(--red-help);
}

.key-grey {
  background-color: var(--grey-view);
}

.key-black {
  background-color: var(--black-main);
}

.table-container {
  width: 700px;
  max-width: 100%;
  margin: 0 auto;
}

ul.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

ul.grid li {
  background: #0f1420;
  border: 1px solid #223049;
  border-radius: 8px;
  padding: 8px;
}

.takeoff {
  background-color: #b3b3b3;
  color: #0f1420;
  border: 1px solid #223049;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}

.takeoff .kbd {
  background: #0c1017;
  color: #f6f6f6;
}

.modal .foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.modal .foot label {
  margin-right: auto;
  font-size: 12px;
  opacity: 0.8;
}

.keyboard-container {
  display: flex;
  justify-content: center;
  width: 100%;
}

.keyboard {
  display: inline-flex;
  align-items: flex-end;
  padding: 16px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgb(0 0 0 / 60%);
  box-sizing: border-box;
  overflow: hidden;
}

.keyboard .main-keys {
  display: inline-block;
}

.keyboard .row {
  display: flex;
  margin-bottom: var(--key-gap);
}

.keyboard .row:last-child {
  margin-bottom: 0;
}

.keyboard .key {
  border: 2px solid var(--key-border);
  border-radius: var(--key-radius);
  background: var(--key-bg);
  color: var(--key-text);
  min-width: 35px;
  padding: 12px 6px;
  margin-right: var(--key-gap);
  text-align: center;
  font-size: 11px;
  line-height: 1;
  user-select: none;
  white-space: nowrap;
  font-family: var(--key-font);
}

.keyboard .key:last-child {
  margin-right: 0;
}

.keyboard .w-15 {
  flex: 1.5;
}

.keyboard .w-175 {
  flex: 1.75;
}

.keyboard .w-2 {
  flex: 2;
}

.keyboard .w-225 {
  flex: 2.25;
}

.keyboard .w-25 {
  flex: 2.5;
}

.keyboard .w-125 {
  flex: 1.25;
}

.keyboard .space {
  flex: 9;
}

.keyboard .key-3d,
.keyboard .arrow-3d {
  background: var(--blue-3d);
  color: #fff;
  border-color: var(--blue-3d);
}

.keyboard .key-view {
  background: var(--grey-view);
  color: #fff;
  border-color: var(--grey-view);
}

.keyboard .key-help {
  background: var(--red-help);
  color: #fff;
  border-color: var(--red-help);
}

.keyboard .key-main {
  background: var(--black-main);
  color: #fff;
  border-color: var(--black-main);
}

.keyboard .arrow-cluster {
  margin-left: 24px;
  display: grid;
  grid-template-columns: repeat(3, 38px);
  grid-template-rows: repeat(2, 38px);
  gap: var(--key-gap);
  justify-items: center;
  align-items: center;
}

.keyboard .arrow-key {
  border-radius: var(--key-radius);
  border: 2px solid var(--blue-3d);
  background: var(--blue-3d);
  color: #fff;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  user-select: none;
  font-family: var(--key-font);
}

.keyboard-caption {
  font-size: 13px;
  opacity: 0.8;
  color: #d9e6ff;
  text-align: center;
}

.pilot-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}

.pilot-overlay.hidden {
  display: none;
}

.overlay-panel,
.overlay-wheel {
  pointer-events: auto;
}

.overlay-panel {
  background: rgba(175, 175, 175, 0.2);
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(5px);
}

.overlay-top-left {
  position: absolute;
  top: 22px;
  left: 16px;
  display: flex;
  gap: 10px;
  padding: 14px 16px;
}

.overlay-mini,
.overlay-stack-btn,
.overlay-rail-key {
  border: 0;
  border-radius: 6px;
  background: rgb(230 230 230 / 65%);
  color: rgb(29 29 29 / 55%);
  font-weight: 700;
  font-size: 24px;
  line-height: 1;
  width: 40px;
  height: 40px;
  padding: 0;
}

.overlay-mini {
  font-size: 24px;
}

.overlay-left-rail {
  position: absolute;
  top: 110px;
  left: 18px;
  width: 40px;
  height: 430px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px;
}

.overlay-rail-key {
  width: 40px;
  height: 40px;
  background: transparent;
  color: rgb(230 230 230 / 65%);
}

.overlay-rail-track {
  position: relative;
  margin: 10px 0;
  width: 16px;
  flex: 1;
  border-radius: 999px;
  background: rgb(0 0 0 / 20%);
}

.overlay-rail-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 10px;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  background: rgb(232 232 232 / 75%);
  transition:
    transform 80ms linear,
    background-color 80ms ease;
}

.overlay-right-stack {
  position: absolute;
  top: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
}

.overlay-stack-btn {
  width: 40px;
  height: 40px;
  font-size: 24px;
}

.overlay-wheel {
  position: absolute;
  width: clamp(180px, 16vw, 300px);
  height: clamp(180px, 16vw, 300px);
  border-radius: 50%;
  overflow: hidden;
  background: rgba(175, 175, 175, 0.3);

  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.859);
  touch-action: none;
}

.overlay-wheel::before,
.overlay-wheel::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 150%;
  /* background: rgb(34 34 34 / 54%); */
  background: rgba(255, 255, 255, 0.4);

  transform-origin: center;
  pointer-events: none;
}

.overlay-wheel::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.overlay-wheel::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.overlay-wheel-left {
  left: clamp(120px, 15vw, 280px);
  bottom: clamp(24px, 8vh, 72px);
}

.overlay-wheel-right {
  right: clamp(120px, 15vw, 280px);
  bottom: clamp(24px, 8vh, 72px);
}

.wheel-segment {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(184, 175, 175, 0.1);
  /* color: rgba(243, 0, 0, 0.74); */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 4px;
  font-weight: 700;
  z-index: 1;
  transition:
    transform 80ms ease,
    background-color 80ms ease,
    color 80ms ease;
}

.wheel-main {
  font-size: clamp(24px, 1.7vw, 34px);
  line-height: 1;
  color: rgb(232 232 232 / 95%);
  text-shadow: 0 1px 0 rgb(0 0 0 / 25%);
  position: relative;
  z-index: 2;
}

.wheel-sub {
  font-size: clamp(11px, 0.9vw, 16px);
  line-height: 1;
  color: rgb(224 224 224 / 70%);
  position: relative;
  z-index: 2;
}

.wheel-top {
  clip-path: polygon(50% 50%, 0 0, 100% 0);
  justify-content: flex-start;
  padding-top: 11%;
}

.wheel-right {
  clip-path: polygon(50% 50%, 100% 0, 100% 100%);
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10%;
}

.wheel-bottom {
  clip-path: polygon(50% 50%, 100% 100%, 0 100%);
  justify-content: flex-end;
  padding-bottom: 10%;
}

.wheel-left {
  clip-path: polygon(50% 50%, 0 100%, 0 0);
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  padding-left: 10%;
}

.wheel-center-mark {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 50px;
  color: rgb(220 220 220 / 55%);
  font-weight: 700;
  font-size: clamp(18px, 1.8vw, 34px);
  pointer-events: none;
  opacity: 1;
  z-index: 3;
}

.pilot-overlay .is-active.key-3d,
.pilot-overlay .is-active.key-blue {
  background: rgba(66, 109, 175, 0.65) !important;
  color: #fff !important;
}

.pilot-overlay .is-active.key-view,
.pilot-overlay .is-active.key-grey {
  background: rgb(119 119 119 / 50%) !important;
  color: #fff !important;
}

.pilot-overlay .is-active.key-main,
.pilot-overlay .is-active.key-black {
  background: rgba(17, 17, 17, 0.2) !important;
  color: #fff !important;
}

.pilot-overlay .is-active.key-help,
.pilot-overlay .is-active.key-red {
  background: rgba(0, 0, 0, 0.1);
  color: #fff !important;
}

#overlayBtnT.is-active,
#overlayBtnL.is-active,
#overlayBtnR.is-active {
  background: rgb(17 17 17 / 92%) !important;
  color: #fff !important;
}

.overlay-rail-key.is-active {
  transform: translateY(-6px);
}

#overlayKeyS.is-active {
  transform: translateY(6px);
}

.overlay-rail-thumb.is-up {
  transform: translate(-50%, calc(-50% - 40%));
  background: rgb(119 119 119 / 95%);
}

.overlay-rail-thumb.is-down {
  transform: translate(-50%, calc(-50% + 40%));
  background: rgb(119 119 119 / 95%);
}

.overlay-mini.is-active,
.overlay-stack-btn.is-active,
.overlay-rail-key.is-active {
  background: rgb(230 230 230 / 95%);
  color: rgb(22 22 22 / 85%);
}

@media (max-width: 960px) {
  .modal {
    width: min(680px, calc(100vw - 32px));
  }

  .table-container {
    width: 100%;
  }

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

  .pilot-overlay {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }

  .overlay-center {
    grid-column: 1 / -1;
    order: 3;
  }

  .overlay-stick {
    width: min(32vw, 150px);
  }

  .overlay-actions {
    width: min(420px, 90vw);
  }
}

@media (max-width: 620px) {
  header {
    flex-direction: column;
    align-items: flex-start;
  }

  .toolbar {
    width: 100%;
  }

  .overlay-gimbal {
    height: 140px;
  }

  .overlay-actions {
    grid-template-columns: 1fr;
  }
}
