:root {
  color-scheme: dark;
  --bg: #050607;
  --panel: #11171c;
  --panel-2: #182027;
  --text: #f4f7fb;
  --muted: #9aa7b4;
  --line: #2a333c;
  --accent: #34b3a0;
  --shadow: rgba(0, 0, 0, 0.48);
  --app-width: 100vw;
  --app-height: 100vh;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: var(--app-width);
  height: var(--app-height);
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button {
  font: inherit;
}

.app-shell,
.stage {
  width: var(--app-width);
  height: var(--app-height);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.app-shell {
  position: fixed;
  inset: 0;
  isolation: isolate;
}

.stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #000;
}

.amiga-frame {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.menu-button {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(17, 23, 28, 0.78);
  box-shadow: 0 8px 24px var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
}

.menu-button span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 0;
  background: var(--text);
  border-radius: 2px;
}

.menu-button:hover,
.menu-button:focus-visible,
.menu-item:hover,
.menu-item:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.status-chip {
  position: fixed;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(520px, calc(100vw - 126px));
  margin: 0;
  padding: 7px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: rgba(17, 23, 28, 0.72);
  box-shadow: 0 8px 24px var(--shadow);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  pointer-events: none;
}

.drive-leds {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 21;
  display: grid;
  gap: 4px;
  width: max-content;
  padding: 7px 8px 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: rgba(17, 23, 28, 0.72);
  box-shadow: 0 8px 24px var(--shadow);
  pointer-events: none;
}

.led-strip {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 6ch;
  justify-self: center;
  font-family: Consolas, "Courier New", monospace;
  font-size: 10px;
}

.led-bar {
  display: block;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  opacity: 0.18;
  transition: opacity 120ms ease, box-shadow 120ms ease;
}

.led-power {
  background: #d73a31;
}

.led-drive {
  background: #42c56e;
}

.led-drive.mounted {
  opacity: 0.58;
}

.led-bar.active {
  opacity: 1;
}

.led-power.active {
  box-shadow: 0 0 10px rgba(215, 58, 49, 0.88);
}

.led-drive.active {
  box-shadow: 0 0 10px rgba(66, 197, 110, 0.9);
}

.track-readout {
  display: block;
  width: 6ch;
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
}

.drive-leds.track-hidden .track-readout {
  display: none;
}

.mouse-buttons {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 32;
  display: flex;
  flex-direction: row;
  gap: 4px;
  pointer-events: auto;
}

.mouse-buttons.side-left {
  right: auto;
  left: max(10px, env(safe-area-inset-left));
}

.mouse-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 54px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(17, 23, 28, 0.82);
  box-shadow: 0 8px 24px var(--shadow);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#mouseButtonLeft {
  order: 1;
}

#mouseButtonRight {
  order: 2;
}

.mouse-button:first-child {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

.mouse-button:last-child {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

.mouse-button.pressed,
.mouse-button:active {
  border-color: var(--accent);
  background: rgba(52, 179, 160, 0.76);
  color: #03100e;
}

body.mouse-buttons-on-right .drive-leds {
  right: auto;
  left: max(10px, env(safe-area-inset-left));
}

body.mouse-buttons-on-left .drive-leds {
  right: max(10px, env(safe-area-inset-right));
  left: auto;
}

@media (orientation: landscape) {
  .mouse-buttons {
    flex-direction: column;
  }

  .mouse-button:first-child {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: 4px;
  }

  .mouse-button:last-child {
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    border-bottom-left-radius: 8px;
  }
}

body.viewport-portrait .mouse-buttons {
  flex-direction: row;
}

body.viewport-landscape .mouse-buttons {
  flex-direction: column;
}

body.viewport-portrait .mouse-button:first-child {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 8px;
}

body.viewport-portrait .mouse-button:last-child {
  border-top-left-radius: 4px;
  border-top-right-radius: 8px;
  border-bottom-left-radius: 4px;
}

body.viewport-landscape .mouse-button:first-child {
  border-top-right-radius: 8px;
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 4px;
}

body.viewport-landscape .mouse-button:last-child {
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
  border-bottom-left-radius: 8px;
}

.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: transparent;
}

.menu-panel {
  position: fixed;
  top: max(60px, calc(env(safe-area-inset-top) + 58px));
  right: max(10px, env(safe-area-inset-right));
  z-index: 90;
  width: min(320px, calc(100vw - 20px));
  max-height: calc(100vh - 80px - env(safe-area-inset-bottom));
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 23, 28, 0.96);
  box-shadow: 0 20px 54px var(--shadow);
}

.menu-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 4px 4px 12px;
  border-bottom: 1px solid var(--line);
}

.menu-head img {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
}

.menu-head h1,
.menu-head p {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-head h1 {
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}

.menu-head p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.menu-group {
  display: grid;
  gap: 7px;
  padding-top: 12px;
}

.menu-item,
.primary-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
}

.menu-item {
  width: 100%;
  padding: 0 12px;
  background: var(--panel-2);
  text-align: left;
}

.menu-item:disabled {
  cursor: default;
  opacity: 0.55;
}

.menu-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.menu-toggle:hover,
.menu-toggle:focus-within {
  border-color: var(--accent);
}

.menu-toggle input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.menu-field {
  display: grid;
  gap: 6px;
  min-height: 38px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
}

.menu-field span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.1;
}

.menu-field input,
.menu-field select {
  width: 100%;
  min-width: 0;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 0;
  background: #182027;
  color: var(--text);
  color-scheme: dark;
  font: inherit;
  font-size: 13px;
  line-height: 1.3;
  outline: none;
}

.menu-field select {
  padding: 2px 0;
}

.menu-field option {
  background: #182027;
  color: var(--text);
}

.menu-field:focus-within {
  border-color: var(--accent);
}

.menu-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.menu-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.menu-actions .menu-item {
  min-height: 34px;
  padding: 0 9px;
  font-size: 12px;
  line-height: 1.15;
}

.menu-actions .menu-item:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.menu-field textarea {
  width: 100%;
  min-width: 0;
  height: 94px;
  resize: vertical;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  background: rgba(5, 6, 7, 0.45);
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
  line-height: 1.35;
  outline: none;
}

.help-block {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(24, 32, 39, 0.78);
}

.help-block summary {
  min-height: 38px;
  padding: 10px 12px;
  cursor: pointer;
}

.help-content {
  padding: 0 12px 12px;
}

.help-block h2 {
  margin: 12px 0 4px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.2;
  letter-spacing: 0;
}

.help-block h2:first-child {
  margin-top: 0;
}

.help-block p,
.help-block li {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.help-block ul {
  margin: 6px 0 0;
  padding-left: 17px;
}

.help-block li + li {
  margin-top: 5px;
}

.primary-button {
  margin-top: 10px;
  padding: 0 14px;
  background: var(--accent);
  border-color: transparent;
  color: #03100e;
  font-weight: 700;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 6, 7, 0.62);
  pointer-events: none;
}

.overlay.hidden {
  display: none;
}

.overlay-panel {
  width: min(380px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 23, 28, 0.96);
  box-shadow: 0 18px 48px var(--shadow);
  pointer-events: auto;
}

.overlay-panel strong,
.overlay-panel .overlay-message,
.overlay-detail {
  display: block;
}

.overlay-panel strong {
  margin-bottom: 8px;
  font-size: 16px;
}

.boot-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 22px;
}

.boot-spinner {
  display: none;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border: 2px solid rgba(244, 247, 251, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: boot-spin 900ms linear infinite;
}

.overlay.is-busy .boot-spinner {
  display: block;
}

.overlay-message {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.overlay-detail {
  margin-top: 8px;
  color: #c4ccd4;
  font-size: 12px;
  line-height: 1.4;
}

@keyframes boot-spin {
  to {
    transform: rotate(360deg);
  }
}

.hidden {
  display: none !important;
}

@media (max-width: 520px) {
  .menu-button {
    width: 40px;
    height: 40px;
  }

  .menu-panel {
    top: max(56px, calc(env(safe-area-inset-top) + 54px));
  }

  .status-chip {
    max-width: calc(100vw - 116px);
  }

  .drive-leds {
    padding-right: 7px;
    padding-left: 7px;
  }
}
