:root{
  --app-height:100vh;
  --app-top:0px;
}

@supports (height: 100dvh){
  :root{
    --app-height:100dvh;
  }
}

body{ margin:0; overflow:hidden; background:#fff; font-family:system-ui,sans-serif; }

.scene-canvas{
  position:fixed;
  inset:0;
  z-index:0;
  display:block;
  touch-action:none;
  user-select:none;
  -webkit-user-select:none;
  -webkit-touch-callout:none;
}

#ui{
  position:fixed;
  top:16px;
  left:16px;
  width:260px;
  max-height:calc(100vh - 48px);
  overflow:auto;
  touch-action:pan-y;
  -webkit-overflow-scrolling:touch;
  pointer-events:auto;
  background:rgba(255,255,255,.88);
  backdrop-filter:blur(8px);
  padding:14px;
  border-radius:12px;
  box-shadow:0 2px 12px rgba(0,0,0,.08);
  z-index:10;
}

body.ui-collapsed #ui{
  display:none;
}

.hidden{
  display:none !important;
}

.bottom-controls{
  position:fixed;
  right:14px;
  bottom:14px;
  z-index:20;
  display:flex;
  gap:10px;
  align-items:center;
}

.panel-toggle,
.quick-boot,
.preset-toggle{
  width:auto;
  min-width:96px;
  border:1px solid #222;
  border-radius:0;
  background:#fff;
  color:#111;
  padding:10px 14px;
  font-size:13px;
  box-shadow:0 2px 12px rgba(0,0,0,.10);
  user-select:none;
  -webkit-user-select:none;
  -webkit-touch-callout:none;
  -webkit-tap-highlight-color:transparent;
  touch-action:none;
}

.quick-boot:disabled{
  opacity:.55;
}

.quick-boot.is-blowing{
  background:#e9e9e9;
  color:#111;
}

.preset-panel{
  position:fixed;
  right:14px;
  bottom:70px;
  width:260px;
  max-height:calc(100vh - 110px);
  overflow:auto;
  z-index:19;
  padding:14px;
  border:1px solid rgba(0,0,0,.18);
  border-radius:12px;
  background:rgba(255,255,255,.94);
  box-shadow:0 2px 16px rgba(0,0,0,.12);
  backdrop-filter:blur(8px);
}

.preset-title{
  margin-bottom:10px;
  font-size:13px;
  font-weight:600;
}

.preset-save-row{
  display:grid;
  grid-template-columns:1fr 74px;
  gap:8px;
}

.preset-save-row input{
  min-width:0;
  border:1px solid #222;
  border-radius:0;
  padding:7px 10px;
  font-size:12px;
  color:#111;
}

.preset-save-row button{
  padding:7px 10px;
}

.preset-message{
  min-height:16px;
  margin:8px 0;
  font-size:11px;
  color:#777;
}

.preset-list{
  display:grid;
  gap:6px;
}

.preset-item{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  width:100%;
  border:1px solid rgba(0,0,0,.18);
  border-radius:0;
  background:#fff;
  padding:8px 10px;
  color:#111;
  text-align:left;
}

.preset-item span{
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.preset-date{
  flex:0 0 auto;
  color:#777;
  font-size:10px;
}

.readout{
  position:fixed;
  top:12px;
  right:12px;
  z-index:8;
  padding:8px 10px;
  background:rgba(255,255,255,.72);
  color:#111;
  font-size:10px;
  line-height:1.45;
  text-align:right;
  pointer-events:none;
  font-variant-numeric:tabular-nums;
}

#ui h2{ margin:0 0 14px 0; font-size:13px; font-weight:600; }

.section{
  margin:14px 0 8px 0;
  padding-top:8px;
  border-top:1px solid rgba(0,0,0,.08);
  font-size:10px;
  color:#777;
  letter-spacing:.08em;
  text-transform:uppercase;
}

.control{ margin-bottom:12px; }

.row{
  display:flex;
  justify-content:space-between;
  font-size:11px;
  margin-bottom:4px;
}

.name{ color:#444; }
.value{ color:#888; font-variant-numeric:tabular-nums; }

select{
  width:100%;
  border:0;
  border-bottom:1px solid #222;
  background:transparent;
  padding:3px 0;
  font-size:12px;
}

input[type=range]{
  -webkit-appearance:none;
  appearance:none;
  width:100%;
  height:28px;
  background:transparent;
  touch-action:none;
}

input[type=range]::-webkit-slider-runnable-track{
  height:1px;
  background:#222;
}

input[type=range]::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:12px;
  height:12px;
  border-radius:50%;
  background:#111;
  margin-top:-5.5px;
}

@media (max-width: 640px){
  #ui{
    top:calc(var(--app-top, 0px) + 10px + env(safe-area-inset-top));
    left:10px;
    width:min(280px, calc(100vw - 20px));
    max-height:calc(var(--app-height, 100dvh) - 112px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding:12px 12px 20px;
    background:transparent;
    backdrop-filter:none;
    box-shadow:none;
  }

  .mobile-hide{
    display:none !important;
  }

  .bottom-controls{
    left:12px;
    right:12px;
    bottom:calc(12px + env(safe-area-inset-bottom));
    display:grid;
    grid-template-columns:minmax(0, 1.15fr) minmax(0, .82fr) minmax(0, 1fr);
    gap:8px;
  }

  .panel-toggle,
  .quick-boot{
    min-width:0;
    width:100%;
    padding:12px 8px;
    font-size:15px;
  }

  .preset-toggle{
    min-width:0;
    width:100%;
    padding:12px 8px;
    font-size:14px;
  }

  .preset-panel{
    left:12px;
    right:12px;
    bottom:calc(70px + env(safe-area-inset-bottom));
    width:auto;
    max-height:min(260px, calc(var(--app-height, 100dvh) - 120px - env(safe-area-inset-bottom)));
    padding:12px;
    border-radius:10px;
  }

  .preset-title{
    margin-bottom:8px;
    font-size:15px;
  }

  .preset-save-row{
    grid-template-columns:1fr;
    gap:6px;
  }

  .preset-save-row input{
    width:100%;
    box-sizing:border-box;
    padding:9px 12px;
    font-size:16px;
  }

  .preset-save-row button{
    width:100%;
    padding:9px 12px;
  }

  .preset-message{
    margin:6px 0;
  }

  .preset-list{
    gap:5px;
  }

  .preset-item{
    padding:7px 9px;
    font-size:13px;
    border-radius:7px;
  }

  .readout{
    top:calc(var(--app-top, 0px) + 8px + env(safe-area-inset-top));
    right:8px;
    padding:5px 6px;
    background:rgba(255,255,255,.52);
    font-size:7.5px;
    line-height:1.3;
  }

  input[type=range]::-webkit-slider-thumb{
    width:18px;
    height:18px;
    margin-top:-8.5px;
  }
}

button{
  width:100%;
  border:1px solid #222;
  border-radius:0;
  background:#fff;
  color:#111;
  padding:7px 10px;
  font-size:12px;
  cursor:pointer;
  user-select:none;
  -webkit-user-select:none;
  -webkit-touch-callout:none;
  -webkit-tap-highlight-color:transparent;
}

button:hover{ background:#f3f3f3; }

button.panel-toggle,
button.quick-boot,
button.preset-toggle{
  width:auto;
}

#status{
  margin-top:10px;
  font-size:11px;
  color:#777;
}
