:root {
  --bg: #0b0d12;
  --panel: #151922;
  --edge: #262c39;
  --text: #e6e9f0;
  --dim: #8b93a7;
  --panel-w: 340px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overscroll-behavior: none;
}

#app {
  height: 100%;
}

.layout {
  position: relative;
  height: 100%;
  width: 100%;
  /* The panel parks off-screen when closed, which would otherwise add a
     horizontal scrollbar. */
  overflow: hidden;
}

/* ---------------------------------------------------------------- art canvas */

.art-host {
  position: absolute;
  inset: 0;
  overflow: hidden;
  transition:
    right 0.22s ease,
    bottom 0.22s ease;
}

.art-host canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* --------------------------------------------------------------- control panel */

.panel-host {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  max-width: 100%;
  padding: 10px 10px calc(24px + var(--safe-b));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  border-left: 1px solid var(--edge);
  transition: transform 0.22s ease;
}

.layout.panel-open .panel-host {
  transform: translateX(0);
}
.layout.panel-closed .panel-host {
  transform: translateX(100%);
}

.panel-grab {
  position: absolute;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--edge);
  cursor: pointer;
  touch-action: none;
}

.panel-grab-bar {
  width: 14px;
  height: 2px;
  background: var(--dim);
  border-radius: 2px;
}

/* Wide screens: the art gives up room instead of being covered, so the whole
   sketch stays visible while you tweak it. */
@media (min-width: 900px) {
  .layout.panel-open .art-host {
    right: var(--panel-w);
  }

  .panel-grab {
    top: 50%;
    right: var(--panel-w);
    transform: translateY(-50%);
    border-radius: 8px 0 0 8px;
    border-right: none;
  }
  .layout.panel-closed .panel-grab {
    right: 0;
    border-right: 1px solid var(--edge);
    border-radius: 8px 0 0 8px;
  }
  .panel-grab-bar {
    display: none;
  }
}

/* Narrow screens: a handle along the bottom, sheet slides up over the art.
   The sheet is capped so the art stays partly visible behind it. */
@media (max-width: 899px) {
  .layout.panel-open .art-host {
    bottom: 30vh;
  }

  .panel-host {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 72vh;
    padding-bottom: calc(16px + var(--safe-b));
    border-left: none;
    border-top: 1px solid var(--edge);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -12px 40px rgb(0 0 0 / 55%);
  }
  .layout.panel-open .panel-host {
    transform: translateY(0);
  }
  .layout.panel-closed .panel-host {
    transform: translateY(100%);
  }
  .panel-grab {
    left: 50%;
    bottom: calc(10px + var(--safe-b));
    transform: translateX(-50%);
    flex-direction: column;
    gap: 4px;
    border-radius: 999px;
    padding: 8px 18px;
  }
  .layout.panel-closed .panel-grab {
    bottom: calc(10px + var(--safe-b));
  }
}

/* A wider panel on big screens, where there is room for it. */
@media (min-width: 1500px) {
  :root {
    --panel-w: 380px;
  }
}

/* TweakPane sits on a dark panel, so let it inherit our colours. */
.panel-host .tp-dfwv {
  width: 100%;
  max-width: none;
  position: static;
}
