:root {
  color-scheme: dark;
  --panel: rgba(15, 19, 24, 0.86);
  --panel-strong: rgba(11, 14, 18, 0.94);
  --stroke: rgba(255, 255, 255, 0.16);
  --text: #f5f7fa;
  --muted: #aab4c0;
  --blue: #19a7ce;
  --green: #42d37e;
  --amber: #ffb13b;
  --red: #ff4d5c;
  --floor: #202830;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #11161b;
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--floor);
  touch-action: none;
}

.hud {
  position: fixed;
  z-index: 3;
  background: var(--panel);
  border: 1px solid var(--stroke);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(14px);
}

.hud-left {
  left: clamp(8px, 1.4vw, 20px);
  top: clamp(8px, 1.4vw, 20px);
  width: min(320px, calc(100vw - 16px));
  padding: 10px 12px;
  border-radius: 6px;
}

.hud-right {
  right: clamp(8px, 1.4vw, 20px);
  top: clamp(8px, 1.4vw, 20px);
  width: min(280px, calc(100vw - 16px));
  max-height: min(60vh, 560px);
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border-radius: 6px;
}

.brand {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 6px;
  background: #f5f7fa;
  color: #11161b;
  font-weight: 900;
  font-size: 14px;
  line-height: 1;
}

h1 {
  margin: 0;
  font-size: 14px;
  line-height: 1.15;
  letter-spacing: 0;
}

p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.label {
  color: var(--muted);
  display: block;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  margin-bottom: 8px;
  border-radius: 6px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.04);
}

.mode-switch button {
  min-height: 28px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  border-radius: 4px;
}

.mode-switch button:hover {
  transform: none;
  color: var(--text);
}

.mode-switch button[aria-selected="true"] {
  background: color-mix(in srgb, var(--blue), transparent 24%);
  color: #07131a;
}

#modeRemote[aria-selected="true"] {
  background: color-mix(in srgb, var(--amber), transparent 18%);
}

body[data-mode="remote"] #routePanel {
  display: none;
}

#remotePanel[hidden] {
  display: none !important;
}

.remote-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.remote-meta code {
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 10px;
  color: var(--text);
}

.remote-log {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  overflow: auto;
  flex: 1 1 auto;
  font-family: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, monospace;
  font-size: 11px;
  line-height: 1.35;
}

.remote-log li {
  display: grid;
  grid-template-columns: 44px 56px 1fr;
  gap: 6px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.remote-log li.input {
  color: var(--amber);
}

.remote-log li.led {
  color: var(--text);
}

.remote-log li time {
  color: var(--muted);
}

.remote-log li .tag {
  font-weight: 800;
  letter-spacing: 0.5px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.status-grid > div,
.current-pick {
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
}

.status-grid > div {
  min-height: 0;
  padding: 6px 8px;
}

.status-grid strong,
.current-pick strong,
.hud-right strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.current-pick {
  padding: 8px 10px;
  margin-bottom: 8px;
}

#activeSlot {
  font-size: 18px;
  line-height: 1.1;
}

.pick-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.pick-meta span {
  min-width: 0;
}

.pick-meta b {
  color: var(--text);
}

.task-hint {
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.05);
  border-left: 3px solid #6c7480;
  color: var(--text);
  transition: background 180ms, border-left-color 180ms, color 180ms;
}

.task-hint[data-stage="pick"] {
  background: rgba(255, 177, 59, 0.18);
  border-left-color: var(--amber);
}

.task-hint[data-stage="place"] {
  background: rgba(25, 167, 206, 0.20);
  border-left-color: var(--blue);
}

.task-hint[data-stage="confirm"] {
  background: rgba(66, 211, 126, 0.22);
  border-left-color: var(--green);
}

.task-hint[data-stage="done"] {
  background: rgba(66, 211, 126, 0.30);
  border-left-color: var(--green);
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 6px;
}

button {
  min-height: 32px;
  font-size: 12px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.42);
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
}

#startOrder {
  background: color-mix(in srgb, var(--blue), transparent 18%);
}

#togglePush {
  background: color-mix(in srgb, var(--green), transparent 24%);
}

#togglePush.active {
  background: color-mix(in srgb, var(--amber), transparent 18%);
  color: #171717;
  font-weight: 800;
}

.compact button {
  min-height: 28px;
  font-size: 11px;
}

.hud-right header {
  flex: 0 0 auto;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--stroke);
}

.route-list {
  margin: 6px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  counter-reset: route;
}

.route-list li {
  counter-increment: route;
  min-height: 36px;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 12px;
}

.route-list li::before {
  content: counter(route);
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-weight: 700;
  font-size: 11px;
}

.route-list li.active {
  color: var(--text);
}

.route-list li.active::before {
  background: var(--amber);
  color: #171717;
}

.route-list li.done {
  color: var(--green);
}

.route-list li .slot {
  font-weight: 800;
  color: inherit;
  font-size: 12px;
}

.route-list li .detail {
  display: block;
  margin-top: 1px;
  font-size: 10px;
  color: var(--muted);
}

.route-list li .qty {
  min-width: 36px;
  text-align: right;
  font-weight: 800;
  color: var(--text);
  font-size: 12px;
}

.route-list li.split {
  min-height: 36px;
  padding-top: 4px;
  padding-bottom: 4px;
  grid-template-columns: 34px 1fr auto;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
}

.route-list li.split::before {
  content: "";
  background: transparent;
}

.route-list li.split .slot-cont {
  display: inline-block;
  margin-right: 6px;
  color: var(--muted);
}

#crosshair {
  position: fixed;
  z-index: 4;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  pointer-events: none;
  display: none;
}

#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  background: rgba(245, 247, 250, 0.85);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.55);
}

#crosshair::before {
  left: 50%;
  top: 0;
  width: 2px;
  height: 100%;
  margin-left: -1px;
}

#crosshair::after {
  top: 50%;
  left: 0;
  height: 2px;
  width: 100%;
  margin-top: -1px;
}

body.pointer-locked #crosshair {
  display: block;
}

.controls {
  position: fixed;
  z-index: 3;
  left: 50%;
  bottom: clamp(8px, 1.4vw, 18px);
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 6px 8px;
  border: 1px solid var(--stroke);
  border-radius: 6px;
  background: var(--panel-strong);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
}

.controls div {
  display: flex;
  gap: 4px;
}

.controls button {
  width: 34px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  font-weight: 900;
  font-size: 12px;
}

.controls span {
  color: var(--muted);
  font-size: 10px;
  max-width: min(540px, calc(100vw - 40px));
  text-align: center;
}

body.pointer-locked .controls {
  opacity: 0.35;
}

.exit-hint {
  position: fixed;
  z-index: 4;
  left: 50%;
  bottom: clamp(232px, 25vh, 260px);
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--amber), transparent 40%);
  background: rgba(11, 14, 18, 0.78);
  backdrop-filter: blur(10px);
  color: var(--amber);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: exit-hint-pulse 1.1s ease-in-out infinite;
}

.exit-hint[hidden] {
  display: none;
}

.interact-hint {
  position: fixed;
  z-index: 4;
  left: 0;
  top: 0;
  transform: translate(-50%, -120%);
  padding: 5px 10px 5px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(11, 14, 18, 0.86);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.interact-hint[hidden] {
  display: none;
}

.interact-hint kbd {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--amber);
  color: #11161b;
  font-family: inherit;
  font-weight: 900;
  font-size: 11px;
  border: none;
}

body.editor-mode .interact-hint {
  display: none;
}

.exit-hint kbd {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 5px;
  background: var(--amber);
  color: #11161b;
  font-family: inherit;
  font-weight: 900;
  font-size: 13px;
  border: none;
}

@keyframes exit-hint-pulse {
  0%, 100% {
    transform: translateX(-50%) scale(1);
    box-shadow: 0 0 0 0 rgba(255, 177, 59, 0.45);
    opacity: 0.92;
  }
  50% {
    transform: translateX(-50%) scale(1.06);
    box-shadow: 0 0 18px 6px rgba(255, 177, 59, 0.0);
    opacity: 1;
  }
}

.bottom-task-hint {
  position: fixed;
  z-index: 4;
  left: 50%;
  bottom: clamp(96px, 11vh, 124px);
  max-width: min(640px, calc(100vw - 32px));
  padding: 9px 22px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(11, 14, 18, 0.86);
  backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  transform-origin: 50% 50%;
  animation: bottom-task-pulse 2.2s ease-in-out infinite;
  transition: color 200ms ease, border-color 200ms ease;
}

.bottom-task-hint[hidden] {
  display: none;
}

.bottom-task-hint[data-stage="idle"] {
  color: var(--muted);
  border-color: rgba(255, 255, 255, 0.12);
}

.bottom-task-hint[data-stage="pick"] {
  color: var(--amber);
  border-color: color-mix(in srgb, var(--amber), transparent 35%);
}

.bottom-task-hint[data-stage="place"] {
  color: var(--blue);
  border-color: color-mix(in srgb, var(--blue), transparent 35%);
}

.bottom-task-hint[data-stage="confirm"] {
  color: var(--green);
  border-color: color-mix(in srgb, var(--green), transparent 35%);
}

.bottom-task-hint[data-stage="done"] {
  color: var(--green);
  border-color: color-mix(in srgb, var(--green), transparent 25%);
}

body.editor-mode .bottom-task-hint {
  display: none;
}

@keyframes bottom-task-pulse {
  0%, 100% {
    transform: translateX(-50%) scale(1);
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  }
  50% {
    transform: translateX(-50%) scale(1.025);
    box-shadow: 0 0 22px 4px rgba(255, 255, 255, 0.06);
  }
}

#toast {
  position: fixed;
  z-index: 4;
  left: 50%;
  bottom: clamp(168px, 18vh, 196px);
  transform: translateX(-50%) translateY(14px);
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--stroke);
  background: var(--panel-strong);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  text-align: center;
}

#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#toggleEditor {
  background: rgba(123, 102, 230, 0.32);
  border-color: rgba(155, 124, 255, 0.55);
}

#toggleEditor.active {
  background: color-mix(in srgb, #9b7cff, transparent 18%);
  color: #11161b;
  font-weight: 800;
}

.editor-panel {
  left: clamp(8px, 1.4vw, 20px);
  top: clamp(8px, 1.4vw, 20px);
  width: min(360px, calc(100vw - 16px));
  max-height: calc(100vh - 24px);
  padding: 10px 12px 12px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  z-index: 5;
}

.editor-panel[hidden],
.editor-section[hidden] {
  display: none;
}

body.editor-mode .hud-left,
body.editor-mode .hud-right,
body.editor-mode .controls,
body.editor-mode #crosshair,
body.editor-mode .exit-hint {
  display: none;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--stroke);
}

.editor-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.editor-close {
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.editor-section {
  border: 1px solid var(--stroke);
  border-radius: 6px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor-section h3 {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--muted);
  text-transform: uppercase;
}

.editor-section select,
.editor-section input[type="text"],
.editor-section input[type="number"] {
  width: 100%;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.32);
  color: var(--text);
  font-size: 12px;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.editor-actions button {
  flex: 1 1 auto;
  min-height: 28px;
  font-size: 11px;
  padding: 0 8px;
}

.editor-bottom {
  margin-top: 4px;
}

.editor-primary {
  background: color-mix(in srgb, var(--green), transparent 24%) !important;
  color: #0c1018;
  font-weight: 800;
}

.editor-field,
.editor-field-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}

.editor-field {
  flex-direction: column;
  align-items: stretch;
}

.editor-field-inline {
  flex: 1 1 calc(50% - 4px);
}

.editor-fieldset {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  padding: 6px 8px 8px;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.editor-fieldset legend {
  padding: 0 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
}

.editor-level-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.editor-level-row {
  display: grid;
  grid-template-columns: 28px 1fr 28px 28px 28px;
  align-items: center;
  gap: 4px;
}

.editor-level-tag {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 800;
  font-size: 12px;
}

.editor-level-row input {
  width: 100%;
  height: 28px;
  text-align: center;
  font-weight: 700;
}

.editor-level-row button {
  min-height: 28px;
  height: 28px;
  width: 28px;
  padding: 0;
  font-size: 12px;
}

.editor-add-level {
  width: 100%;
  min-height: 28px;
  font-size: 11px;
  margin-top: 4px;
}

.editor-hint {
  margin: 4px 0 0;
  font-size: 10px;
  line-height: 1.4;
  color: var(--muted);
}

@media (max-width: 860px) {
  .hud-left {
    width: calc(100vw - 24px);
    padding: 14px;
  }

  .hud-right {
    top: auto;
    right: 12px;
    left: 12px;
    bottom: 128px;
    width: auto;
    max-height: 28vh;
    padding: 12px;
  }

  .status-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .status-grid > div {
    min-height: 58px;
    padding: 9px;
  }

  .status-grid strong {
    font-size: 12px;
  }

  .current-pick {
    padding: 11px;
  }

  .button-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud-right {
    display: none;
  }

  .controls {
    width: calc(100vw - 24px);
  }
}
