body,
html {
  overscroll-behavior: contain;
  overflow: hidden;
}

main {
  position: relative;
  height: calc(100vh - var(--navbar-height));
}

.view {
  display: none;
  height: 100%;
  overflow: auto;
}

.view-active {
  display: block;
}

#canvasView {
  overflow: hidden;
}

:is(.flex, .flex-end) {
  display: flex;
  align-content: center;
}

.flex-end {
  justify-content: flex-end;
}

/* ----- Toolbar -----
   NOTE: do not set `backdrop-filter`, `filter`, `transform`, `perspective` or
   `will-change` on .toolbar or any of its ancestors of the dropdown popups.
   These properties make the element a containing block for `position: fixed`
   descendants, which would trap the dropdown panels inside the toolbar's
   overflow box (causing them to render behind the canvas and force scrolling).
*/
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: rgb(17, 24, 39);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: thin;
  min-height: var(--toolbar-height);
  position: relative;
  z-index: 50;
}

.toolbar::-webkit-scrollbar {
  height: 6px;
}

.toolbar-section {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

/* Inner wrapper of edit-settings: keep a flat row, no nested toolbar bg */
.toolbar .edit-settings {
  background: transparent;
  border: none;
  padding: 0;
  gap: var(--space-2);
  flex: 1;
}

.toolbar .edit-settings .toolbar-section,
.toolbar .edit-settings > * {
  background: rgba(255, 255, 255, 0.02);
}

/* ----- Side panel ----- */
.side-panel {
  position: fixed;
  top: var(--navbar-height);
  right: 0;
  width: 360px;
  max-width: 90vw;
  height: calc(100vh - var(--navbar-height));
  padding: var(--space-5);
  background: var(--color-panel-background);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  z-index: 900;
  transform: translateX(100%);
  opacity: 0;
  visibility: hidden;
  transition:
    transform var(--transition-base),
    opacity var(--transition-base),
    visibility 0s linear var(--transition-base);
}

.side-panel.open {
  transform: translateX(0);
  opacity: 1;
  visibility: visible;
  transition:
    transform var(--transition-base),
    opacity var(--transition-base),
    visibility 0s linear 0s;
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--space-4);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.side-panel-title {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--color-text);
}

.icon-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: var(--radius-md);
}

/* ----- Mobile ----- */
@media (max-width: 700px) {
  .side-panel {
    width: 88vw;
  }

  /* Top toolbar: shapes only, horizontally scrollable */
  .toolbar {
    padding: var(--space-2);
    gap: var(--space-2);
  }

  /* Bottom toolbar: edit settings (font, color, size, actions).
     IMPORTANT: keep this free of backdrop-filter / transform — otherwise
     the dropdowns rendered inside (which use position: fixed) get trapped
     inside this element and render behind the canvas. */
  .toolbar .edit-settings {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    min-height: var(--toolbar-height);
    padding: var(--space-2) var(--space-3);
    padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
    background: rgb(17, 24, 39);
    border-top: 1px solid var(--color-border);
    z-index: 50;
    overflow-x: auto;
    overflow-y: visible;
    flex-wrap: nowrap;
    justify-content: flex-start;
    scrollbar-width: thin;
  }

  .toolbar .edit-settings::-webkit-scrollbar {
    height: 6px;
  }

  /* Leave room for the fixed bottom toolbar so the canvas isn't hidden behind it */
  .container {
    padding-bottom: calc(var(--toolbar-height) + env(safe-area-inset-bottom, 0px));
  }
}
