.host-app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  white-space: nowrap;
}

.join-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.code-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.code-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.code-value {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.qr-box {
  width: 56px;
  height: 56px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.qr-box canvas, .qr-box img { width: 100%; height: 100%; }

.participant-count {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

/* ---------- People panel (left of the board) ---------- */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

.people-panel {
  flex: 0 0 200px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px 16px;
}

.people-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 8px;
}

.people-summary {
  text-transform: none;
  letter-spacing: 0;
}

#participantList {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
}

#participantList li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  overflow-wrap: anywhere;
}

#participantList li.empty { color: var(--muted); }

#participantList .dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2e9e4e;
  transform: translateY(-1px);
}

#participantList li.offline { color: var(--muted); }
#participantList li.offline .dot { background: #b8b5ad; }

#participantList .status {
  font-size: 0.72rem;
  font-style: italic;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .people-panel { display: none; }
}

/* Hidden picker used by the colour button on text tiles. */
.tile-color-picker {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--ink);
  white-space: nowrap;
}

.switch-label input { width: 16px; height: 16px; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 0.85rem;
  color: var(--muted);
}

.ghost-btn:hover { border-color: #d64545; color: #d64545; }

.ghost-btn.small { padding: 6px 14px; font-size: 0.8rem; }

/* ---------- Secondary toolbar: zoom, host tools, background ---------- */
.host-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn.small {
  width: 30px;
  height: 30px;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink);
}

.icon-btn.small:hover { border-color: var(--accent); color: var(--accent); }

.zoom-label {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 40px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.bg-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.bg-select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  background: #fff;
  color: var(--ink);
}

.bg-color {
  width: 32px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  background: #fff;
}

.board-wrap {
  flex: 1;
  overflow: auto;
  /* Distinct from the board's own default background so its true edges are
     always visible — otherwise the empty workspace around it blends in and
     the board looks like it extends further than it actually does. */
  background: #e4e1d8;
}

/* Margin leaves room for a tile's corner buttons to sit just outside the
   board when the tile is near an edge. Tiles are clamped to the board. */
.board-frame {
  position: relative;
  margin: 28px auto;
  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;
  touch-action: none;
  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: -24px;
  background: var(--ink);
  color: #fff;
  font-size: 0.6rem;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
}

.drawing-item .remove-btn {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #d64545;
  color: #fff;
  border: 2px solid #fff;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.35;
  /* Counter-scale against the board's zoom so it renders at a constant
     on-screen size instead of shrinking along with the rest of the board. */
  transform: scale(calc(1 / var(--board-scale, 1)));
  transform-origin: bottom left; /* grow away from the tile */
}

.drawing-item:hover .remove-btn { opacity: 1; }

.drawing-item .color-btn {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 22px;
  height: 22px;
  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;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.55;
  transform: scale(calc(1 / var(--board-scale, 1)));
  transform-origin: bottom right; /* grow away from the tile */
}

.drawing-item:hover .color-btn { opacity: 1; }

.drawing-item .resize-handle {
  position: absolute;
  right: -10px;
  bottom: -10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  touch-action: none;
  transform: scale(calc(1 / var(--board-scale, 1)));
  transform-origin: top left; /* grow away from the tile */
}

.drawing-item.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  z-index: 999;
}

.empty-hint {
  position: absolute;
  top: 40px;
  left: 40px;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 280px;
}

/* ---------- Host sketch modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-panel {
  width: min(640px, 92vw);
  height: min(640px, 86vh);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
}

.modal-canvas-wrap {
  flex: 1;
  background: #fff;
  touch-action: none;
  min-height: 0;
}

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

.modal-toolbar {
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.swatches {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex: 0 0 auto;
}

.swatch.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px #fff inset;
}

.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: 7px 14px;
  font-size: 0.82rem;
  white-space: nowrap;
}

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