*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: #ffffff; }
body {
  font-family: 'Inter', sans-serif;
  color: #2D2D2D;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

/* ── TOP BAR ── */
#top-bar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 20px;
  border-bottom: 0.5px solid #eee;
  flex-shrink: 0;
  background: #ffffff;
  z-index: 50;
}
#back-link {
  font-size: 12px;
  color: #aaa;
  text-decoration: none;
  white-space: nowrap;
}
#back-link:hover { color: #555; }
#wall-question {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(11px, 2vw, 14px);
  color: #888;
  font-style: normal;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
  pointer-events: none;
}

/* ── WALL VIEWPORT ── */
#wall {
  position: fixed;
  top: 52px;
  bottom: 116px;
  left: 0;
  right: 0;
  background: #f0f0f0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}
#wall.panning { cursor: grabbing; }

/* ── WALL SURFACE (zoom/pan target) ── */
/* Entries live here. pointer-events:none so clicks pass through to entries. */
#wall-surface {
  position: absolute;
  width: 800%;
  height: 800%;
  top: -350%;
  left: -350%;
  background: #ffffff;
  transform-origin: center center;
  will-change: transform;
  pointer-events: none;
}

/* ── WALL ENTRIES ── */
.wall-entry {
  position: absolute;
  user-select: none;
  white-space: nowrap;
  transform-origin: center center;
  z-index: 1;
  line-height: 1.1;
  pointer-events: all;
}
.wall-entry.own { z-index: 2; cursor: move; }
.wall-entry.dragging { opacity: 0.85; }
.wall-entry.drawing {
  pointer-events: none;
  z-index: 1;
}
/* Own drawings are clickable within the session for deletion */
.wall-entry.drawing.own {
  pointer-events: all;
  cursor: pointer;
}
/* Hide rotate/scale handles when a drawing is selected */
#sel-box.drawing-selected .sel-rotate,
#sel-box.drawing-selected .sel-rotate-line,
#sel-box.drawing-selected .sel-handle,
#sel-box.drawing-selected .sel-hint {
  display: none;
}

/* ── DRAW CANVAS (direct child of #wall, viewport-sized) ── */
#draw-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: none;
  z-index: 3;
  touch-action: none;
}
#draw-canvas.active {
  display: block;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23333' d='M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 0 0 0-1.41l-2.34-2.34a1 1 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z'/%3E%3C/svg%3E") 0 24, crosshair;
}

/* ── SELECTION OVERLAY (direct child of #wall, not affected by surface transform) ── */
#sel-box {
  position: absolute;
  border: 1.5px dashed #555;
  border-radius: 3px;
  display: none;
  z-index: 100;
  pointer-events: none;
}
#sel-box.visible { display: block; }
.sel-handle {
  position: absolute;
  width: 12px; height: 12px;
  background: #fff;
  border: 2px solid #333;
  border-radius: 3px;
  pointer-events: all;
  z-index: 101;
  box-sizing: border-box;
}
.sel-handle.tl { top: -6px; left: -6px; cursor: nwse-resize; }
.sel-handle.tr { top: -6px; right: -6px; cursor: nesw-resize; }
.sel-handle.bl { bottom: -6px; left: -6px; cursor: nesw-resize; }
.sel-handle.br { bottom: -6px; right: -6px; cursor: nwse-resize; }
.sel-rotate {
  position: absolute;
  width: 16px; height: 16px;
  background: #232424;
  border-radius: 50%;
  pointer-events: all;
  cursor: grab;
  z-index: 101;
  left: 50%;
  top: -30px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.sel-rotate svg { width: 10px; height: 10px; }
.sel-rotate-line {
  position: absolute;
  left: 50%;
  top: -18px;
  width: 1px;
  height: 12px;
  background: #555;
  z-index: 100;
  pointer-events: none;
}
.sel-hint {
  position: absolute;
  left: 50%;
  bottom: -22px;
  transform: translateX(-50%);
  font-size: 10px;
  color: #777;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  font-family: 'Inter', sans-serif;
}

/* ── PAUSED MESSAGE ── */
.paused-msg {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  color: #888;
  font-family: 'Caveat', cursive;
  text-align: center;
  pointer-events: none;
  z-index: 10;
}

/* ── LOADING MESSAGE ── */
#wall-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 20px;
  color: #ccc;
  font-family: 'Caveat', cursive;
  pointer-events: none;
  z-index: 10;
  transition: opacity 0.4s ease;
}
#wall-loading.hidden { opacity: 0; }

/* ── DELETE BUTTON ── */
#sel-delete-btn {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 10px;
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  background: #fff;
  color: #cc3333;
  border: 1px solid #cc3333;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
  z-index: 102;
  pointer-events: all;
}
#sel-delete-btn:hover { background: #cc3333; color: #fff; }

/* ── BOTTOM BAR ── */
.bottombar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #ffffff;
  border-top: 1px solid rgba(0,0,0,0.06);
  padding: 10px 16px 12px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.text-input {
  flex: 1 1 200px;
  max-width: 360px;
  height: 36px;
  border: 1px solid #d4d4d4;
  border-radius: 3px;
  padding: 0 12px;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  color: #2D2D2D;
  background: #fff;
  outline: none;
}
.text-input:focus { border-color: #232424; }
#place-btn {
  height: 36px;
  padding: 8px 16px;
  background: #232424;
  color: #fff;
  border: none;
  border-radius: 3px;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  letter-spacing: 0.02em;
}
#place-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#place-btn:not(:disabled) { opacity: 1; cursor: pointer; }
#place-btn:not(:disabled):hover { background: #000; }
#undo-btn {
  padding: 7px 12px;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  background: transparent;
  color: #555;
  border: 0.5px solid #ccc;
  border-radius: 3px;
  cursor: pointer;
}
#undo-btn:hover { background: #f5f5f5; }
#undo-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.draw-hint {
  font-size: 12px;
  color: #888;
  text-align: center;
  flex: 1;
}
.mode-toggle {
  display: inline-flex;
  border: 1px solid #d4d4d4;
  border-radius: 3px;
  overflow: hidden;
}
.mode-toggle button {
  background: #fff;
  border: none;
  padding: 7px 14px;
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  color: #2D2D2D;
  letter-spacing: 0.02em;
}
.mode-toggle button.active { background: #232424; color: #fff; }
.sub-toggle {
  border-color: #bbb;
}
.sub-toggle button {
  padding: 5px 11px;
  font-size: 11px;
  color: #555;
}
.sub-toggle button.active { background: #555; color: #fff; }
.swatches { display: inline-flex; gap: 6px; }
.swatch {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch.active { border-color: #232424; }
.font-select {
  height: 32px;
  padding: 0 10px;
  border: 1px solid #d4d4d4;
  border-radius: 3px;
  background: #fff;
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  color: #2D2D2D;
  cursor: pointer;
}
.size-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #555;
}
.size-slider { width: 110px; }
.size-readout { min-width: 26px; text-align: right; }
.bottombar.hidden { display: none; }

/* ── ENTRY FADE-IN ── */
@keyframes entry-appear {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.wall-entry.appearing {
  animation: entry-appear 0.5s ease forwards;
}

/* ── ZOOM CONTROLS ── */
#zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
#zoom-controls button {
  width: 28px;
  height: 28px;
  border: 0.5px solid #ddd;
  border-radius: 4px;
  background: #fff;
  color: #555;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Inter', sans-serif;
  padding: 0;
}
#zoom-controls button:hover { background: #f5f5f5; color: #232424; }
#zoom-reset { font-size: 11px !important; }

/* ── MINIMAP ── */
#wall-minimap {
  position: absolute;
  bottom: 10px;
  left: 10px;
  width: 72px;
  height: 72px;
  background: rgba(255,255,255,0.92);
  border: 0.5px solid #ccc;
  border-radius: 4px;
  overflow: hidden;
  z-index: 50;
  cursor: pointer;
}
#minimap-surface {
  position: absolute;
  inset: 3px;
  background: #fff;
  border: 0.5px solid #eee;
  overflow: hidden;
}
#minimap-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}
#minimap-viewport {
  position: absolute;
  background: rgba(35,36,36,0.1);
  border: 1.5px solid #232424;
  border-radius: 2px;
  pointer-events: none;
  z-index: 51;
}

/* ── RESPONSIVE ── */
@media (max-width: 640px) {
  #top-bar { padding: 0 14px; }
  .text-input { flex: 1 1 100%; max-width: none; }
  .row { gap: 6px; }
  .font-select { font-size: 11px; }
  .size-slider { width: 80px; }
  .swatch { width: 22px; height: 22px; }
}
