.draw-app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.draw-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.whoami {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 92px;
}

.tab-switch {
  display: flex;
  background: var(--bg);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  flex: 0 0 auto;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--ink);
  color: #fff;
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
}

.tab-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  margin-left: 8px;
}

.canvas-wrap {
  flex: 1;
  position: relative;
  background: #fff;
  touch-action: none;
}

#drawCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.draw-toolbar {
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.swatches {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 4px 6px; /* room for the selected swatch's ring */
}

.swatch {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex: 0 0 auto;
  transition: transform 0.1s ease, opacity 0.1s ease;
}

/* Selected colour: larger, ringed and ticked, so it's clear at a glance. */
.swatch.active {
  transform: scale(1.18);
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--ink);
}

.swatch.active::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.6);
}

.swatch.active[data-light="1"]::after {
  color: var(--ink);
  text-shadow: none;
}

/* While the eraser is on, no colour is the current one. */
.swatches.eraser-on .swatch {
  opacity: 0.4;
  transform: none;
}

.size-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.size-row input[type="range"] { flex: 1; }

.tool-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.tool-toggle.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.big-btn.wide { width: 100%; padding: 14px; font-size: 1rem; }

.text-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.text-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 16px;
  font-weight: 700; /* matches how text looks on the board */
}

/* ---------- Board tab (view + move/resize own drawings) ---------- */
.mini-board-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle, #d8d6cf 1px, transparent 1px) 0 0 / 22px 22px,
    var(--bg);
}

/* Margin leaves room for a tile's corner buttons (24px) to sit just outside
   the board when the tile is near an edge. Tiles are clamped to the board,
   so nothing else can overflow; the wrap clips instead of scrolling. */
.board-frame {
  position: relative;
  flex: 0 0 auto;
  margin: 24px;
  box-sizing: content-box; /* the border sits outside the board, not over its edge */
  border: 2px solid #1c1c1e;
}

.board {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
}

.drawing-item {
  position: absolute;
  border-radius: 8px;
}

.drawing-item img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}

.drawing-item .text-content {
  width: 100%;
  height: 100%;
  display: block; /* font size and vertical centring are set by fitText() */
  text-align: center;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-weight: 700;
  line-height: 1.2;
  padding: 4px;
}

.drawing-item .name-tag {
  position: absolute;
  left: 4px;
  bottom: -20px;
  background: var(--ink);
  color: #fff;
  font-size: 0.56rem;
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
}

.drawing-item.mine {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  touch-action: none;
}

.drawing-item.readonly {
  opacity: 0.9;
  pointer-events: none;
}

.resize-handle {
  display: none;
  position: absolute;
  right: -10px;
  bottom: -10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  touch-action: none;
  /* Counter-scale against the board's zoom so the handle renders at a
     constant on-screen size regardless of how small the board is scaled
     down to fit a phone (it sits inside the scaled ancestor, so dividing
     by that same factor exactly cancels it out). */
  transform: scale(calc(1 / var(--board-scale, 1)));
  /* Grow away from the tile so the corner buttons sit outside a small tile
     instead of piling on top of each other. */
  transform-origin: top left;
}

.drawing-item.mine .resize-handle {
  display: block;
}

.remove-btn {
  display: none;
  position: absolute;
  top: -10px;
  right: -10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #d64545;
  color: #fff;
  border: 2px solid #fff;
  font-size: 12px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  touch-action: none;
  transform: scale(calc(1 / var(--board-scale, 1)));
  transform-origin: bottom left;
}

.drawing-item.mine .remove-btn {
  display: flex;
}

.edit-btn {
  display: none;
  position: absolute;
  top: -10px;
  left: -10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #2b6cd4;
  color: #fff;
  border: 2px solid #fff;
  font-size: 12px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  touch-action: none;
  transform: scale(calc(1 / var(--board-scale, 1)));
  transform-origin: bottom right;
}

.drawing-item.mine .edit-btn {
  display: flex;
}

.palette-btn {
  display: none;
  position: absolute;
  bottom: -10px;
  left: -10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  font-size: 12px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  touch-action: none;
  transform: scale(calc(1 / var(--board-scale, 1)));
  transform-origin: top right;
}

.drawing-item.mine .palette-btn {
  display: flex;
}

.color-popover {
  position: fixed;
  z-index: 200;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
}

.color-popover-title {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 8px;
  white-space: nowrap;
}

.color-popover-title span {
  color: var(--ink);
  font-weight: 700;
}

.color-popover-swatches {
  display: grid;
  grid-template-columns: repeat(4, 34px);
  gap: 8px;
}

.color-popover-swatches .swatch {
  width: 34px;
  height: 34px;
}

.board-hint {
  margin: 0;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  font-size: 0.76rem;
  color: var(--muted);
  text-align: center;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
