html, body.canvas-body {
  touch-action: none;
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2c3a2b;
  font-family: Helvetica, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}
.d-none { display: none !important; }

#cv-main, #cv-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}
#cv-overlay { touch-action: none; cursor: crosshair; }

.cv-home {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 20;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: rgba(220, 207, 195, 0.92);
  color: #14414f;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
}

.cv-text-input {
  position: fixed;
  z-index: 30;
  background: rgba(0, 0, 0, 0.25);
  border: 1px dashed rgba(255, 255, 255, 0.6);
  border-radius: 6px;
  padding: 2px 8px;
  outline: none;
  font-weight: 700;
  font-family: Helvetica, "Helvetica Neue", Arial, sans-serif;
  min-width: 140px;
  transform: translateY(-50%);
}

/* Palette */
.cv-palette {
  position: fixed;
  z-index: 25;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: rgba(20, 28, 20, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  overflow: auto;
  user-select: none;
  -webkit-user-select: none;
}
.cv-palette.dock-top,
.cv-palette.dock-bottom { flex-direction: row; flex-wrap: wrap; justify-content: center; }
.cv-palette.dock-left,
.cv-palette.dock-right { flex-direction: column; width: 184px; }
.cv-palette[hidden] { display: none; }

.cv-top { display: flex; gap: 6px; align-items: stretch; }
.dock-left .cv-top, .dock-right .cv-top { width: 100%; }
.dock-left .cv-handle, .dock-right .cv-handle { flex: 1; }
.cv-handle {
  display: flex;
  gap: 3px;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
}
.cv-handle span { width: 5px; height: 5px; border-radius: 50%; background: #dccfc3; display: block; }
.dock-left .cv-handle, .dock-right .cv-handle { width: 100%; box-sizing: border-box; }
.dock-top .cv-handle, .dock-bottom .cv-handle { flex-direction: column; padding: 10px 6px; }
.cv-handle.dragging { cursor: grabbing; }

.cv-section { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; justify-content: center; }
.dock-left .cv-section, .dock-right .cv-section { width: 100%; }

.cv-palette button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #dccfc3;
  border-radius: 10px;
  min-width: 42px;
  height: 42px;
  padding: 0 8px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.cv-palette button small { font-size: 0.6rem; opacity: 0.85; }
.cv-palette button.active { background: #dccfc3; color: #14414f; border-color: #dccfc3; }
.cv-palette button:hover:not(.active) { background: rgba(255, 255, 255, 0.16); }

.cv-colors button {
  width: 34px;
  min-width: 34px;
  height: 34px;
  border-radius: 50%;
  padding: 0;
  border: 3px solid transparent;
  background: var(--c);
}
.cv-colors button.active { border-color: #fff; background: var(--c); }
.cv-colors button:hover:not(.active) { background: var(--c); transform: scale(1.08); }

.cv-sizes i { display: block; width: var(--d); height: var(--d); border-radius: 50%; background: currentColor; }

.cv-sub button { font-size: 1.15rem; }
#cv-fill { font-size: 0.7rem; }
#cv-fill[aria-pressed="false"] { opacity: 0.7; }
.cv-stamps button { padding: 4px; min-width: 40px; }
.cv-stamps canvas { display: block; }

@media (max-width: 600px) {
  .cv-palette { padding: 8px; gap: 8px; }
  .cv-palette button { min-width: 38px; height: 38px; }
  .cv-palette.dock-left, .cv-palette.dock-right { width: 164px; }
}
.cv-palette [hidden] { display: none !important; }
.cv-ghost { position: fixed; pointer-events: none; z-index: 15; }

.cv-page-ghost {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  border: 0;
  opacity: 0.2;
  pointer-events: none;
  background: transparent;
  z-index: 5;
}
.cv-page-ghost.off { display: none; }
.cv-scrollbar {
  position: fixed;
  top: 60px;
  bottom: 12px;
  right: 4px;
  width: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  z-index: 12;
  pointer-events: none;
}
.cv-scrollbar i { position: absolute; left: 0; right: 0; border-radius: 3px; background: rgba(220, 207, 195, 0.6); }

.cv-collapse { min-width: 36px !important; height: auto !important; align-self: stretch; }
.cv-palette.collapsed .cv-section { display: none; }
.cv-zoom {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 20;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(20, 28, 20, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.16);
}
.cv-zoom button {
  appearance: none;
  border: 0;
  background: transparent;
  color: #dccfc3;
  min-width: 38px;
  height: 34px;
  border-radius: 999px;
  font-size: 1.15rem;
  cursor: pointer;
}
.cv-zoom button:hover { background: rgba(255, 255, 255, 0.14); }
#cv-zoom-reset { font-size: 0.78rem; min-width: 52px; }
.cv-scrollbar { right: 2px; }

@media (max-width: 700px) {
  .cv-palette { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .cv-palette.dock-top, .cv-palette.dock-bottom {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    width: calc(100vw - 16px);
    box-sizing: border-box;
    scrollbar-width: none;
  }
  .cv-palette.dock-top .cv-section, .cv-palette.dock-bottom .cv-section { flex-wrap: nowrap; flex: 0 0 auto; }
  .cv-palette.dock-top .cv-top, .cv-palette.dock-bottom .cv-top { flex: 0 0 auto; }
  .cv-palette.dock-top::-webkit-scrollbar, .cv-palette.dock-bottom::-webkit-scrollbar { display: none; }
  .cv-palette.collapsed { width: auto; }
  .cv-home { top: 8px; left: 8px; padding: 0.3rem 0.7rem; font-size: 0.85rem; }
  .cv-zoom { top: 8px; right: 8px; }
}

/* Kontextabhängige Palette: nur zeigen, was das Werkzeug braucht */
.cv-palette[data-tool="hand"] .cv-colors,
.cv-palette[data-tool="hand"] .cv-sizes,
.cv-palette[data-tool="erase"] .cv-colors { display: none; }
.cv-palette[data-tool="hand"] .cv-sizes { display: none; }

.cv-top { flex-wrap: wrap; justify-content: center; }
.cv-top .cv-actions { gap: 4px; flex-wrap: nowrap; }
.cv-top .cv-actions button { min-width: 38px; height: 38px; }
.dock-left .cv-handle, .dock-right .cv-handle { flex: 1 0 60%; }
.cv-palette.collapsed .cv-top .cv-actions { display: none; }

@media (max-width: 700px) {
  .cv-palette.dock-top, .cv-palette.dock-bottom {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: 60dvh;
    gap: 6px;
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .cv-palette.dock-top .cv-top, .cv-palette.dock-bottom .cv-top {
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
  }
  .cv-palette.dock-top .cv-handle, .cv-palette.dock-bottom .cv-handle {
    flex-direction: row;
    padding: 8px 10px;
    flex: 0 0 auto;
  }
  .cv-palette.dock-top .cv-top .cv-actions, .cv-palette.dock-bottom .cv-top .cv-actions { flex: 1 1 auto; justify-content: center; }
  .cv-palette.dock-top .cv-top .cv-actions button, .cv-palette.dock-bottom .cv-top .cv-actions button { min-width: 34px; height: 34px; padding: 0 4px; }
  .cv-palette.dock-top .cv-tools, .cv-palette.dock-bottom .cv-tools { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
  .cv-palette.dock-top .cv-tools button, .cv-palette.dock-bottom .cv-tools button { min-width: 0; padding: 0; height: 46px; }
  .cv-palette.dock-top .cv-colors, .cv-palette.dock-bottom .cv-colors,
  .cv-palette.dock-top .cv-sizes, .cv-palette.dock-bottom .cv-sizes { flex-wrap: nowrap; justify-content: space-around; }
  .cv-palette.dock-top .cv-sub, .cv-palette.dock-bottom .cv-sub { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; scrollbar-width: none; }
  .cv-palette.dock-top .cv-sub::-webkit-scrollbar, .cv-palette.dock-bottom .cv-sub::-webkit-scrollbar { display: none; }
  .cv-palette.dock-top .cv-sub button, .cv-palette.dock-bottom .cv-sub button { flex: 0 0 auto; }
  .cv-palette.collapsed.dock-top, .cv-palette.collapsed.dock-bottom { width: auto; }
}
