:root {
  --bg: #05060a;
  --panel: rgba(10, 12, 20, 0.86);
  --panel-border: rgba(255, 255, 255, 0.1);
  --text: rgba(255, 255, 255, 0.9);
  --muted: rgba(255, 255, 255, 0.65);
  --accent: #5ef7ff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji";
  overflow: hidden;
  overscroll-behavior: none;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: block;
  touch-action: none;
}

.wall {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.07), transparent 40%),
    radial-gradient(circle at 80% 10%, rgba(255, 255, 255, 0.05), transparent 35%),
    linear-gradient(0deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 64px 64px, 64px 64px;
  mix-blend-mode: screen;
  opacity: 0.35;
}

.grid-lines {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  pointer-events: none;
  opacity: 0.55;
  transition: opacity 0.2s ease;
}

.grid-lines--dim {
  opacity: 0.12;
}

.focus-frame {
  position: fixed;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 0 18px rgba(94, 247, 255, 0.35), 0 0 36px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.hud {
  position: fixed;
  left: 12px;
  top: 10px;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  backdrop-filter: blur(6px);
  color: var(--muted);
  font-size: 12px;
  user-select: none;
  pointer-events: none;
  white-space: pre;
}

.toggle-panel {
  position: fixed;
  right: max(12px, calc(var(--safe-right) + 8px));
  top: max(10px, calc(var(--safe-top) + 8px));
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  cursor: pointer;
  min-height: 40px;
  min-width: 44px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.panel {
  position: fixed;
  right: max(12px, calc(var(--safe-right) + 8px));
  top: calc(max(52px, calc(var(--safe-top) + 48px)));
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 64px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.panel__handle {
  display: none;
}

.panel__header {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.panel__status {
  padding: 6px 12px 0;
  color: var(--muted);
  font-size: 12px;
}

.panel__subtitle {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel__title {
  font-weight: 650;
  letter-spacing: 0.2px;
}

.panel__close {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.panel__section {
  padding: 12px;
  display: grid;
  gap: 12px;
}

.panel__row {
  display: flex;
  gap: 10px;
}

.panel button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  min-height: 40px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.panel button:hover,
.toggle-panel:hover {
  border-color: rgba(255, 255, 255, 0.22);
}

.panel button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.field__label {
  color: var(--text);
}

.field__value {
  color: var(--muted);
  min-width: 58px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.field input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
}

.field select {
  width: 160px;
  border-radius: 8px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
}

.panel__help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.panel__footer {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(180deg, rgba(10, 12, 20, 0), rgba(10, 12, 20, 0.92) 24%);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}

.panel__footer button {
  flex: 1;
}

.panel__preview-btn {
  display: none;
}

@media (max-width: 900px), (pointer: coarse) {
  .wall {
    opacity: 0.18;
    background-size: 100% 100%, 100% 100%, 80px 80px, 80px 80px;
  }

  .toggle-panel {
    top: auto;
    bottom: max(10px, calc(var(--safe-bottom) + 8px));
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
  }

  .panel {
    left: max(8px, calc(var(--safe-left) + 4px));
    right: max(8px, calc(var(--safe-right) + 4px));
    top: auto;
    bottom: calc(max(58px, calc(var(--safe-bottom) + 54px)));
    width: auto;
    max-height: none;
    height: var(--sheet-height, min(74dvh, calc(100dvh - var(--safe-top) - var(--safe-bottom) - 72px)));
    background: rgba(8, 10, 16, 0.62);
    transition:
      height 0.22s ease,
      opacity 0.18s ease,
      transform 0.18s ease,
      background-color 0.18s ease;
    border-radius: 14px;
    overflow: auto;
  }

  .panel.panel--mobile.panel--dragging {
    transition: none;
  }

  .panel.panel--mobile.panel--peek {
    overflow: hidden;
  }

  .panel.panel--mobile.panel--peek:not(.panel--scrubbing) .panel__status,
  .panel.panel--mobile.panel--peek:not(.panel--scrubbing) .panel__section {
    display: none;
  }

  .panel.panel--mobile.panel--scrubbing .panel__section {
    opacity: 0.24;
  }

  .panel.panel--mobile.panel--previewing {
    opacity: 0.02;
    transform: translateY(14px);
  }

  .panel__handle {
    display: block;
    width: 52px;
    height: 16px;
    margin: 4px auto 0;
    border: 0;
    background: transparent;
    border-radius: 999px;
    position: relative;
    cursor: grab;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }

  .panel__handle::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 38px;
    height: 4px;
    transform: translate(-50%, -50%);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.34);
  }

  .panel.panel--mobile.panel--dragging .panel__handle {
    cursor: grabbing;
  }

  .panel__header {
    padding: 12px;
  }

  .panel__section {
    padding: 12px;
    gap: 10px;
  }

  .panel__row {
    flex-wrap: wrap;
  }

  .panel__row button {
    flex: 1 1 140px;
  }

  .panel__footer {
    padding: 10px 12px calc(10px + var(--safe-bottom));
    background: linear-gradient(180deg, rgba(8, 10, 16, 0), rgba(8, 10, 16, 0.86) 24%);
  }

  .panel__preview-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .field {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .field__value {
    min-width: 0;
    text-align: left;
  }

  .field select {
    width: 100%;
    min-height: 40px;
  }
}
