:root {
  --panel: rgba(255,255,255,0.92);
  --accent: #ff6b6b;
  --text: #222;
  --muted: #666;
  --border: rgba(0,0,0,0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: transparent;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: transparent;
  overflow: hidden;
}
body.tools-open {
  height: auto;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none; /* Firefox */
}
body.tools-open::-webkit-scrollbar {
  display: none; /* Chrome, Safari */
}

/* Same soft gradient as handstandstudio.de – used when page bg can't show through */
.gradient-bg,
html:fullscreen,
html:-webkit-full-screen,
body:fullscreen,
body:-webkit-full-screen,
html.immersive,
body.immersive {
  background: linear-gradient(180deg, #f8c4e0 0%, #ffe8c8 45%, #f0f5c8 100%) !important;
}

html.immersive,
body.immersive {
  width: 100%;
  height: 100%;
  position: fixed;
  inset: 0;
  z-index: 9999;
}

/* ===== Top bar ===== */
.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: transparent;
  z-index: 30;
  position: relative;
}

.logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  background: rgba(255,255,255,0.88);
  border-radius: 10px;
  padding: 4px 8px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
}

.logo-link img {
  height: 28px;
  width: auto;
  display: block;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.menu-wrap { position: relative; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: rgba(255,255,255,0.9);
  box-shadow: 0 1px 6px rgba(0,0,0,0.1);
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-btn:active { transform: scale(0.95); }

.icon-btn .icon-img {
  width: 26px;
  height: 26px;
  display: block;
  border-radius: 6px;
}

.dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 44px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.15);
  min-width: 180px;
  overflow: hidden;
  z-index: 50;
}

.dropdown.open { display: block; }

.dropdown button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: none;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  color: var(--text);
}

.dropdown button:active { background: #f7f3eb; }
.dropdown button.danger { color: #c0392b; }

/* ===== Main ===== */
.main-row {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
  background: transparent;
  overflow: hidden;
}

.sidebar {
  flex-shrink: 0;
  width: 0;
  overflow: hidden;
  background: var(--panel);
  border-right: 1px solid var(--border);
  transition: width 0.25s ease;
  z-index: 20;
  display: flex;
  flex-direction: column;
}

.sidebar.open { width: 100px; }

.sidebar-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-align: center;
  padding: 8px 4px 4px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.thumbs {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.thumb {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  border: 3px solid transparent;
  overflow: hidden;
  cursor: pointer;
  background: #f0f0f0;
  position: relative;
  flex-shrink: 0;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb.active { border-color: var(--accent); }

.thumb .badge {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid white;
}

.thumb span {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.55);
  color: white;
  font-size: 0.55rem;
  text-align: center;
  padding: 1px 0;
}

/* Stage */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: transparent;
  overflow: hidden;
}

/* tools open: handled in JS – canvas height locked, tools expand below */

.canvas-area {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: transparent;
  touch-action: none;
}
/* Image keeps flex space; page/iframe grows when tools open */
body.tools-open {
  height: auto;
  min-height: 100dvh;
  overflow: visible;
}
body.tools-open .main-row,
body.tools-open .stage {
  overflow: visible;
  min-height: 0;
}

.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#canvas {
  display: block;
  box-shadow: 0 2px 20px rgba(0,0,0,0.12);
  background: white;
  cursor: crosshair;
}

.loading {
  position: absolute;
  inset: 0;
  background: rgba(240,235,227,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  z-index: 10;
}

.loading.hidden { display: none; }

/* ===== Bottom bar – always under the image ===== */
.bottom-bar {
  position: relative;
  flex: 0 0 auto;
  min-height: 52px;
  background: transparent;
  border-top: none;
  z-index: 25;
}

.zoom-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 4px 8px 6px;
  background: transparent;
}

.zbtn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 1px 6px rgba(0,0,0,0.1);
  font-size: 1.2rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.zbtn:active { transform: scale(0.95); }

.zoom-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 48px;
  text-align: center;
  background: rgba(255,255,255,0.9);
  border-radius: 8px;
  padding: 6px 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.btn-ausmalen {
  margin-left: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
  box-shadow: 0 2px 10px rgba(255,107,107,0.35);
  cursor: pointer;
}

.btn-ausmalen:active { transform: scale(0.96); }

/* Tools panel */
.tools-panel {
  background: transparent;
  border-top: none;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.tools-panel.open {
  max-height: 220px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
}

.tools-inner {
  padding: 10px 12px 14px;
  background: transparent;
}
.tools-inner .tool-btn,
.tools-inner .pattern-btn {
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

.tools-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.tool-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  background: #f3efe7;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool-btn.active {
  background: var(--accent);
  color: white;
}

/* Undo right-aligned in the tool row */
.tool-undo {
  margin-left: auto;
  background: #fff;
  border: 1px solid #e0d8c8;
}

.size-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.size-control input[type=range] { width: 90px; }
.size-label { font-size: 0.75rem; color: var(--muted); min-width: 20px; }

.pattern-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.pattern-label { font-size: 0.75rem; color: var(--muted); margin-right: 2px; }

.pattern-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 2px solid #ddd;
  cursor: pointer;
  background: #fff;
  overflow: hidden;
}

.pattern-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255,107,107,0.25);
}

.palette {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.color {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.color.active {
  border-color: #333;
  transform: scale(1.12);
}

.color.white { border: 2px solid #ccc; }

#toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.open { display: flex; }

.modal-content {
  background: white;
  border-radius: 16px;
  max-width: 420px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}

.modal-content h2 { margin-bottom: 10px; font-size: 1.1rem; }
.modal-content h3 { margin: 12px 0 4px; font-size: 0.9rem; }
.modal-content p, .modal-content li { font-size: 0.85rem; line-height: 1.45; color: #444; }
.modal-content ul { padding-left: 18px; margin-bottom: 6px; }

.modal-close {
  float: right;
  background: #eee;
  border: none;
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  font-weight: 600;
}

@media (min-width: 768px) {
  .logo-link img { height: 38px; }
  .sidebar.open { width: 120px; }
  .thumb { width: 88px; height: 88px; }
  .tools-panel.open { max-height: 240px; }
}

/* Pan tool */
.canvas-area.pan-mode #canvas {
  cursor: grab;
}
.canvas-area.pan-mode.panning #canvas {
  cursor: grabbing;
}
