:root {
  --stealth-offset: 0px;
  --ui-bg: rgba(255, 255, 255, 0.88);
  --ui-bg-solid: #ffffff;
  --ui-bg-hover: rgba(241, 245, 249, 0.95);
  --ui-border: rgba(15, 23, 42, 0.1);
  --ui-border-strong: rgba(15, 23, 42, 0.16);
  --ui-text: #0f172a;
  --ui-muted: #64748b;
  --ui-accent: #2563eb;
  --ui-accent-hover: #1d4ed8;
  --ui-accent-soft: rgba(37, 99, 235, 0.12);
  --ui-accent-border: rgba(37, 99, 235, 0.38);
  --ui-danger: #dc2626;
  --ui-danger-soft: rgba(220, 38, 38, 0.1);
  --ui-chip: rgba(241, 245, 249, 0.9);
  --ui-shadow: 0 8px 28px rgba(15, 23, 42, 0.1), 0 1px 3px rgba(15, 23, 42, 0.06);
  --ui-shadow-sm: 0 3px 12px rgba(15, 23, 42, 0.08);
  --canvas-bg: #ffffff;
}

body.bg-grid {
  --canvas-bg: #fffdf4;
}

body.bg-dark {
  --ui-bg: rgba(30, 35, 45, 0.88);
  --ui-bg-solid: #1e232d;
  --ui-bg-hover: rgba(51, 59, 74, 0.94);
  --ui-border: rgba(255, 255, 255, 0.12);
  --ui-border-strong: rgba(255, 255, 255, 0.22);
  --ui-text: #f1f5f9;
  --ui-muted: #94a3b8;
  --ui-accent: #60a5fa;
  --ui-accent-hover: #3b82f6;
  --ui-accent-soft: rgba(96, 165, 250, 0.18);
  --ui-accent-border: rgba(96, 165, 250, 0.45);
  --ui-danger: #f87171;
  --ui-danger-soft: rgba(248, 113, 113, 0.15);
  --ui-chip: rgba(51, 65, 85, 0.72);
  --ui-shadow: 0 10px 32px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.3);
  --ui-shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.35);
  --canvas-bg: #20242c;
}

body.has-stealth-bar {
  --stealth-offset: 42px;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Inter", "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--canvas-bg);
  color: var(--ui-text);
}

[hidden] {
  display: none !important;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--ui-border);
  background: transparent;
  color: var(--ui-text);
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

button:hover {
  background: var(--ui-bg-hover);
}

button:active {
  transform: scale(0.97);
}

button.primary,
.btn-solid-primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
}

button.primary:hover,
.btn-solid-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

button.danger:hover {
  background: var(--ui-danger-soft);
  border-color: rgba(220, 38, 38, 0.35);
  color: var(--ui-danger);
}

button.toggle.active,
button.active,
.seg button.active {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent-border);
  color: var(--ui-accent);
}

/* ---------- 管理者ステルスバー ---------- */
.stealth-admin-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  min-height: 42px;
  padding: 5px 14px;
  background: linear-gradient(90deg, #0f172a, #1e1b4b);
  color: #f8fafc;
  border-bottom: 1px solid rgba(167, 139, 250, 0.35);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 50;
  font-size: 12px;
}

.stealth-admin-bar[hidden] {
  display: none;
}

.stealth-bar-left,
.stealth-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stealth-icon {
  display: inline-flex;
  color: #c4b5fd;
}

.stealth-status-badge {
  background: rgba(139, 92, 246, 0.25);
  border: 1px solid rgba(167, 139, 250, 0.45);
  color: #ede9fe;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 11px;
}

.stealth-status-badge.can-edit {
  background: rgba(245, 158, 11, 0.25);
  border-color: rgba(251, 191, 36, 0.55);
  color: #fef3c7;
}

.stealth-btn {
  padding: 4px 10px;
  border-radius: 7px;
  font-size: 11px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.stealth-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.stealth-btn.active {
  background: #f59e0b;
  border-color: #f59e0b;
  color: #111827;
}

.stealth-btn-exit {
  border-color: rgba(248, 113, 113, 0.5);
  color: #fecaca;
}

.stealth-author-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#stealthAuthorInput {
  width: 170px;
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(15, 23, 42, 0.7);
  color: #f8fafc;
  font-size: 11px;
  outline: none;
}

#stealthAuthorInput::placeholder {
  color: #94a3b8;
}

/* ---------- キャンバスステージ ---------- */
#canvasWrap {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--canvas-bg);
}

#stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  background: var(--canvas-bg);
  cursor: crosshair;
}

#board.hand { cursor: grab; }
#board.selecting { cursor: default; }
#board.panning { cursor: grabbing; }
#board.eyedropper { cursor: crosshair; }
#board.laser { cursor: crosshair; }
#board.eraser { cursor: cell; }

/* ---------- フローティングトップヘッダー ---------- */
.top-header {
  position: fixed;
  top: calc(10px + var(--stealth-offset));
  left: 12px;
  right: 12px;
  min-height: 46px;
  padding: 5px 10px;
  border-radius: 14px;
  background: var(--ui-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 30;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.icon-btn {
  padding: 6px 9px;
  min-height: 32px;
  border-radius: 9px;
  background: var(--ui-chip);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.icon-btn:hover {
  background: var(--ui-bg-hover);
}

.icon-btn-sm {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid transparent;
}

.icon-btn-sm:hover {
  background: var(--ui-bg-hover);
  border-color: var(--ui-border);
}

.btn-primary-pill {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
  border-radius: 9px;
  padding: 6px 12px;
  min-height: 32px;
  font-weight: 600;
}

.btn-primary-pill:hover {
  background: #1d4ed8;
}

.header-undo-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* 左上インライン編集ボードタイトル */
.board-title-wrap {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: 240px;
  flex: 0 1 auto;
}

.board-title-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  min-width: 0;
  max-width: 100%;
  font-size: 13px;
  font-weight: 600;
  color: var(--ui-text);
}

.board-title-btn:hover {
  background: var(--ui-bg-hover);
  border-color: var(--ui-border);
}

.board-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-title-text.is-empty {
  color: var(--ui-muted);
  font-weight: 500;
}

.board-title-edit-icon {
  color: var(--ui-muted);
  flex: 0 0 auto;
  opacity: 0.75;
}

.board-title-btn:hover .board-title-edit-icon {
  opacity: 1;
  color: var(--ui-accent);
}

body.view-only .board-title-edit-icon,
body.locked .board-title-edit-icon {
  display: none;
}

body.view-only .board-title-btn,
body.locked .board-title-btn {
  cursor: default;
}

.board-title-input {
  width: 200px;
  max-width: 100%;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  border: 1.5px solid var(--ui-accent);
  background: var(--ui-bg-solid);
  color: var(--ui-text);
  outline: none;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--ui-muted);
  white-space: nowrap;
  flex: 0 0 auto;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  flex: 0 0 auto;
}

.dot.on {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.roombox {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.roombox code {
  background: var(--ui-accent-soft);
  border: 1px solid var(--ui-accent-border);
  color: var(--ui-accent);
  padding: 3px 7px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--ui-chip);
  border: 1px solid var(--ui-border);
  color: var(--ui-muted);
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
  flex: 0 0 auto;
}

.badge[hidden] {
  display: none;
}

.lock-badge {
  color: #b45309;
  background: rgba(254, 243, 199, 0.9);
  border-color: #fde68a;
}

.lock-badge.is-unlocked {
  color: #047857;
  background: rgba(209, 250, 229, 0.9);
  border-color: #a7f3d0;
}

.view-badge {
  color: #0369a1;
  background: rgba(224, 242, 254, 0.9);
  border-color: #bae6fd;
}

.peers-btn {
  padding: 3px 8px;
  min-height: 32px;
  border-radius: 999px;
  background: var(--ui-chip);
  border: 1px solid var(--ui-border);
  gap: 5px;
}

.peers-avatars {
  display: inline-flex;
  align-items: center;
}

.avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #ffffff;
  font-size: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  border: 2px solid var(--ui-bg-solid);
  margin-left: -5px;
}

.avatar:first-child {
  margin-left: 0;
}

.avatar.readonly {
  opacity: 0.6;
}

.peers-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-muted);
}

.role-badge-btn {
  cursor: pointer;
  border: 1px solid var(--ui-border);
  transition: transform 0.1s ease, filter 0.15s ease;
}

.role-badge-btn:hover {
  filter: brightness(0.96);
}

.role-badge-btn.role-manager {
  color: #6d28d9;
  background: rgba(237, 233, 254, 0.92);
  border-color: #c4b5fd;
}

.role-badge-btn.role-editor {
  color: #1d4ed8;
  background: rgba(219, 234, 254, 0.92);
  border-color: #93c5fd;
}

.role-badge-btn.role-viewer {
  color: #b45309;
  background: rgba(254, 243, 199, 0.92);
  border-color: #fde68a;
}

.my-profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 5px;
  min-height: 32px;
  border-radius: 999px;
  background: var(--ui-chip);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  font-size: 12px;
  font-weight: 600;
  max-width: 150px;
}

.my-profile-btn:hover {
  background: var(--ui-bg-hover);
}

.my-profile-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #2563eb;
  border: 2px solid var(--ui-bg-solid);
  flex: 0 0 auto;
}

.my-profile-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.no-board-manage .board-title-edit-icon {
  display: none;
}

body.no-board-manage .board-title-btn {
  cursor: default;
}

.is-role-disabled {
  opacity: 0.45 !important;
  cursor: not-allowed !important;
}

/* ---------- 閲覧専用 / ロック時 / 集中モード ---------- */
body.view-only #nameInput,
body.view-only #passBtn,
body.view-only .edit-only,
body.locked .edit-only {
  display: none !important;
}

body.focus-mode #topHeader,
body.focus-mode #toolbar,
body.focus-mode #stylePanel,
body.focus-mode #selectionContextBar {
  display: none !important;
}

.focus-exit {
  position: fixed;
  top: calc(12px + var(--stealth-offset));
  right: 12px;
  z-index: 40;
  background: var(--ui-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--ui-border-strong);
  box-shadow: var(--ui-shadow);
  padding: 7px 12px;
  border-radius: 999px;
  font-weight: 600;
}

.focus-exit[hidden] {
  display: none;
}

/* ---------- ツールドック (PC: 上部中央フローティング) ---------- */
.tool-dock {
  position: fixed;
  top: calc(64px + var(--stealth-offset));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px 7px;
  max-width: calc(100vw - 24px);
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--ui-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  box-shadow: var(--ui-shadow);
  z-index: 28;
}

.tool-dock::-webkit-scrollbar {
  display: none;
}

.tool-dock button {
  flex-direction: column;
  gap: 2px;
  padding: 5px 8px;
  min-width: 44px;
  min-height: 42px;
  border-radius: 10px;
  border-color: transparent;
}

.tool-dock button:hover {
  background: var(--ui-bg-hover);
}

.tool-dock button.active {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent-border);
  color: var(--ui-accent);
}

.tool-dock .tlabel {
  font-size: 10px;
  line-height: 1;
  font-weight: 600;
}

.dock-sep {
  width: 1px;
  height: 26px;
  background: var(--ui-border);
  margin: 0 3px;
  flex: 0 0 auto;
}

.shape-group-wrap {
  display: contents;
}

.shape-group-trigger {
  display: none;
}

.shape-tools {
  display: contents;
}

.mobile-only-btn {
  display: none;
}

.style-color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px var(--ui-border-strong);
  background: #111827;
}

/* ---------- 左フローティングスタイルパネル (PC) ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 60;
}

.sheet-backdrop[hidden] {
  display: none;
}

.style-panel {
  position: fixed;
  top: calc(126px + var(--stealth-offset));
  left: 12px;
  width: 224px;
  padding: 10px 11px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--ui-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  box-shadow: var(--ui-shadow);
  z-index: 26;
}

.style-sheet-head {
  display: none;
}

.style-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-top: 7px;
  border-top: 1px solid var(--ui-border);
}

.style-row:first-of-type,
.style-colors-row {
  border-top: none;
  padding-top: 0;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px var(--ui-border-strong);
  justify-self: center;
}

.swatch.active {
  box-shadow: 0 0 0 2.5px var(--ui-accent);
  transform: scale(1.08);
}

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

.color-picker-wrap {
  display: inline-flex;
  align-items: center;
}

input[type="color"] {
  width: 30px;
  height: 28px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 8px;
  padding: 2px;
  background: var(--ui-bg-solid);
  cursor: pointer;
}

.style-pill-btn {
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 11px;
  background: var(--ui-chip);
}

.style-slider-line {
  display: flex;
  align-items: center;
  gap: 7px;
}

.style-lbl {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-muted);
  min-width: 44px;
}

.style-slider-line input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--ui-accent);
}

.hint {
  font-size: 11px;
  color: var(--ui-muted);
  min-width: 34px;
  text-align: right;
}

.style-seg-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.seg {
  display: inline-flex;
  align-items: center;
  background: var(--ui-chip);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.seg button {
  padding: 4px 7px;
  font-size: 11px;
  border: 1px solid transparent;
  border-radius: 6px;
}

.style-mobile-extra-tools {
  display: none;
}

/* ---------- 選択中コンテキストバー ---------- */
.selection-bar {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 380px);
  overflow-x: auto;
  scrollbar-width: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--ui-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  box-shadow: var(--ui-shadow);
  z-index: 27;
}

.selection-bar[hidden] {
  display: none;
}

.sel-context-info {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-muted);
  white-space: nowrap;
  padding: 0 6px 0 2px;
}

.selection-bar::-webkit-scrollbar {
  display: none;
}

.sel-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.sel-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-muted);
}

.sel-rot-readout {
  min-width: 38px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 3px 6px;
  border-radius: 6px;
  background: var(--ui-chip);
  color: var(--ui-text);
}

.sel-btn {
  padding: 4px 7px;
  min-height: 28px;
  font-size: 11px;
  border-radius: 7px;
}

.sel-slider {
  width: 78px;
  accent-color: var(--ui-accent);
}

.sel-slider-sm {
  width: 58px;
  accent-color: var(--ui-accent);
}

.sel-val {
  font-size: 11px;
  color: var(--ui-muted);
  min-width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sel-sep {
  width: 1px;
  height: 20px;
  background: var(--ui-border);
  flex: 0 0 auto;
}

.angle-badge {
  position: fixed;
  z-index: 35;
  pointer-events: none;
  padding: 3px 8px;
  border-radius: 999px;
  background: #0f172a;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transform: translate(12px, -28px);
}

.angle-badge[hidden] {
  display: none;
}

.touch-mode-chip {
  position: fixed;
  left: 12px;
  bottom: 14px;
  z-index: 25;
}

.touch-mode-chip[hidden] {
  display: none;
}

.touch-mode-btn {
  background: var(--ui-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--ui-border-strong);
  box-shadow: var(--ui-shadow-sm);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
}

.touch-mode-btn.marquee-on {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #ffffff;
}

/* ---------- 右下ズーム & ミニマップ ---------- */
.bottom-right-controls {
  position: fixed;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 24;
  pointer-events: none;
}

.bottom-right-controls > * {
  pointer-events: auto;
}

.minimap-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.minimap-toggle {
  background: var(--ui-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow-sm);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
}

.minimap-card {
  background: var(--ui-bg-solid);
  border: 1px solid var(--ui-border-strong);
  border-radius: 10px;
  box-shadow: var(--ui-shadow);
  overflow: hidden;
  padding: 3px;
}

.minimap-wrap.collapsed .minimap-card {
  display: none;
}

#minimap {
  width: 176px;
  height: 120px;
  display: block;
  border-radius: 7px;
  cursor: pointer;
  touch-action: none;
}

.zoom-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 6px;
  background: var(--ui-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--ui-border);
  border-radius: 12px;
  box-shadow: var(--ui-shadow);
}

.zoom-pill button {
  padding: 5px 7px;
  min-width: 28px;
  min-height: 28px;
  border-radius: 8px;
  border-color: transparent;
}

#zoomLabel {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-muted);
  min-width: 40px;
  text-align: center;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

/* ---------- パネル・モーダル ---------- */
.panel {
  position: fixed;
  top: calc(64px + var(--stealth-offset));
  right: 12px;
  width: 340px;
  max-width: calc(100vw - 24px);
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  background: var(--ui-bg-solid);
  border: 1px solid var(--ui-border-strong);
  border-radius: 14px;
  box-shadow: var(--ui-shadow);
  z-index: 65;
}

.panel[hidden] {
  display: none;
}

.menu-panel {
  width: 326px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--ui-border);
  font-weight: 700;
  font-size: 13px;
}

.menu-body {
  padding: 12px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.menu-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ui-muted);
}

.menu-field span {
  white-space: nowrap;
}

#nameInput {
  flex: 1;
  min-width: 0;
  padding: 6px 9px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 8px;
  background: var(--ui-chip);
  color: var(--ui-text);
  font-size: 13px;
}

.menu-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.menu-meta:empty {
  display: none;
}

.menu-section {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-top: 8px;
  border-top: 1px solid var(--ui-border);
}

.menu-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ui-muted);
}

.menu-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.menu-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ui-text);
  cursor: pointer;
}

.stealth-menu-btn {
  border-color: rgba(139, 92, 246, 0.45);
  color: #7c3aed;
  background: rgba(139, 92, 246, 0.08);
}

.share-links-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 10px;
  background: var(--ui-chip);
  border: 1px solid var(--ui-border);
}

#qrCanvas {
  width: 156px;
  height: 156px;
  background: #ffffff;
  border-radius: 8px;
  padding: 6px;
  object-fit: contain;
}

.qr-url-text {
  font-size: 11px;
  color: var(--ui-muted);
  word-break: break-all;
  text-align: center;
  max-width: 100%;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 11px;
}

.btn-block {
  width: 100%;
  padding: 9px 12px;
}

.panel-list {
  overflow-y: auto;
  padding: 6px 0;
}

.align-actions {
  padding: 12px 14px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.log-item {
  padding: 6px 14px;
  font-size: 12px;
  line-height: 1.45;
  border-bottom: 1px solid var(--ui-border);
}

.log-item:last-child {
  border-bottom: none;
}

.log-item time {
  color: var(--ui-muted);
  margin-right: 6px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.recent-item {
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.recent-item:hover {
  background: var(--ui-bg-hover);
}

.recent-item .rcode {
  font-family: ui-monospace, monospace;
  color: var(--ui-muted);
  font-size: 11px;
}

.recent-item .rdate {
  color: var(--ui-muted);
  font-size: 11px;
}

.peer-row {
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--ui-border);
}

.peer-row:last-child {
  border-bottom: none;
}

.peer-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.peer-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.peer-name {
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.peer-role {
  font-size: 10px;
  color: var(--ui-muted);
}

.peer-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.peer-role-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  margin-left: 5px;
  vertical-align: middle;
}

.peer-role-badge.is-manager {
  color: #6d28d9;
  background: rgba(237, 233, 254, 0.92);
}

.peer-role-badge.is-editor {
  color: #1d4ed8;
  background: rgba(219, 234, 254, 0.92);
}

.peer-role-badge.is-viewer {
  color: #b45309;
  background: rgba(254, 243, 199, 0.92);
}

.peer-manage-controls {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 5px;
}

.peer-role-select {
  padding: 3px 6px;
  border-radius: 7px;
  border: 1px solid var(--ui-border-strong);
  background: var(--ui-chip);
  color: var(--ui-text);
  font-size: 11px;
}

.peer-kick-btn {
  padding: 3px 7px;
  font-size: 11px;
  border-radius: 7px;
}

/* ---------- 共有・アクセス設定 / プロフィール / ゲートモーダル ---------- */
.share-modal {
  z-index: 90;
}

.share-card {
  max-width: 540px;
  max-height: 88vh;
}

.share-modal-body {
  gap: 14px;
}

.share-role-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--ui-chip);
  border: 1px solid var(--ui-border);
  flex-wrap: wrap;
}

.share-role-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.share-manager-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--ui-border-strong);
  background: rgba(37, 99, 235, 0.03);
}

.share-manager-section[hidden] {
  display: none;
}

.share-block {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.share-select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--ui-border-strong);
  background: var(--ui-bg-solid);
  color: var(--ui-text);
  font-size: 13px;
}

.share-helper-text {
  margin: 0;
  font-size: 11px;
  color: var(--ui-muted);
  line-height: 1.45;
}

.share-check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ui-text);
  cursor: pointer;
  margin-top: 4px;
}

.share-pass-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.share-pass-row {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg-solid);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.share-pass-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.share-pass-name {
  font-size: 12px;
  font-weight: 600;
}

.share-pass-status {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--ui-chip);
  color: var(--ui-muted);
  border: 1px solid var(--ui-border);
}

.share-pass-status.is-set {
  background: rgba(209, 250, 229, 0.9);
  color: #047857;
  border-color: #a7f3d0;
}

.share-pass-inputs {
  display: flex;
  gap: 6px;
  align-items: center;
}

.share-pass-inputs input {
  flex: 1;
  min-width: 0;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid var(--ui-border-strong);
  background: var(--ui-chip);
  color: var(--ui-text);
  font-size: 12px;
}

.share-invite-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.share-invite-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.share-invite-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-muted);
}

.share-invite-row {
  display: flex;
  gap: 5px;
  align-items: center;
}

.share-invite-input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--ui-border);
  background: var(--ui-chip);
  color: var(--ui-muted);
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.welcome-modal {
  z-index: 120;
}

.welcome-modal.is-blocking {
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(18px);
}

.profile-color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 0;
}

.profile-color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  cursor: pointer;
}

.profile-color-swatch.active {
  outline: 2.5px solid var(--ui-accent);
  outline-offset: 2px;
  transform: scale(1.08);
}

.access-gate-modal {
  z-index: 110;
  background: rgba(15, 23, 42, 0.86);
  backdrop-filter: blur(20px);
}

.gate-card {
  max-width: 420px;
  overflow: hidden;
}

.gate-header {
  padding: 22px 20px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.gate-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.gate-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.gate-header p {
  margin: 0;
  font-size: 12px;
  color: var(--ui-muted);
  line-height: 1.55;
}

.gate-error {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #dc2626;
  font-size: 12px;
  font-weight: 600;
}

.gate-error[hidden] {
  display: none;
}

.gate-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.gate-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--ui-border-strong);
  color: var(--ui-text);
  background: var(--ui-chip);
}

.panel-empty {
  padding: 12px 14px;
  font-size: 12px;
  color: var(--ui-muted);
  line-height: 1.5;
}

/* ---------- モーダル ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 85;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  background: var(--ui-bg-solid);
  color: var(--ui-text);
  border: 1px solid var(--ui-border-strong);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 84vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.dialog-card {
  max-width: 420px;
}

.lobby-card {
  max-width: 440px;
}

.modal-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-message {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ui-text);
  white-space: pre-wrap;
}

.dialog-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ui-muted);
}

.dialog-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dialog-input,
#lobbyCodeInput {
  flex: 1;
  min-width: 0;
  padding: 8px 11px;
  border-radius: 9px;
  border: 1px solid var(--ui-border-strong);
  background: var(--ui-chip);
  color: var(--ui-text);
  font-size: 14px;
  outline: none;
}

.dialog-input:focus,
#lobbyCodeInput:focus {
  border-color: var(--ui-accent);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.lobby-section {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.lobby-join-row {
  display: flex;
  gap: 7px;
}

.lobby-recent-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  max-height: 200px;
  overflow-y: auto;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0 12px;
}

.help-table td {
  padding: 7px 14px;
  font-size: 12px;
  vertical-align: top;
  border-bottom: 1px solid var(--ui-border);
}

.help-table tr:last-child td {
  border-bottom: none;
}

.help-table td:first-child {
  white-space: nowrap;
}

kbd {
  background: var(--ui-chip);
  border: 1px solid var(--ui-border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  font: 11px ui-monospace, monospace;
}

/* ---------- ブロック通知オーバーレイ ---------- */
.blocked-overlay {
  position: absolute;
  inset: 0;
  z-index: 75;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.blocked-overlay[hidden] {
  display: none;
}

.blocked-card {
  background: var(--ui-bg-solid);
  color: var(--ui-text);
  border: 1px solid var(--ui-border-strong);
  border-radius: 18px;
  padding: 28px 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.blocked-icon {
  color: var(--ui-danger);
  margin-bottom: 10px;
}

.blocked-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.blocked-card p {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--ui-muted);
  line-height: 1.6;
}

.blocked-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.blocked-actions a,
.blocked-actions button {
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
}

.blocked-actions [hidden] {
  display: none;
}

.btn-outline {
  border: 1px solid var(--ui-border-strong);
  color: var(--ui-text);
}

/* ---------- トースト通知 ---------- */
.toast-container {
  position: fixed;
  top: calc(64px + var(--stealth-offset));
  right: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
  z-index: 130;
  pointer-events: none;
  max-width: min(340px, calc(100vw - 24px));
}

.toast {
  pointer-events: auto;
  padding: 8px 13px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.12);
  animation: toastIn 0.18s ease-out;
}

.toast.toast-success {
  background: rgba(6, 78, 59, 0.95);
  border-color: rgba(52, 211, 153, 0.4);
}

.toast.toast-error {
  background: rgba(127, 29, 29, 0.96);
  border-color: rgba(248, 113, 113, 0.45);
}

.toast.toast-warning {
  background: rgba(120, 53, 15, 0.96);
  border-color: rgba(251, 191, 36, 0.45);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- リモートカーソル ---------- */
.remote-cursor {
  position: absolute;
  pointer-events: none;
  z-index: 12;
  transform: translate(-2px, -2px);
  transition: left 0.08s linear, top 0.08s linear;
}

.remote-cursor .pin {
  width: 12px;
  height: 12px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.remote-cursor .label {
  margin-left: 12px;
  margin-top: -6px;
  font-size: 11px;
  color: #ffffff;
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- テキスト・付箋エディタオーバーレイ ---------- */
.editor-overlay {
  position: fixed;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: calc(100vw - 16px);
}

#textEditor {
  font-family: "Inter", "Noto Sans JP", system-ui, sans-serif;
  padding: 6px 8px;
  border: 1.5px dashed var(--ui-accent);
  border-radius: 8px;
  outline: none;
  resize: none;
  background: rgba(255, 255, 255, 0.96);
  color: #111827;
  width: 240px;
  min-width: 170px;
  max-width: calc(100vw - 24px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

#stickyEditor {
  font-family: "Inter", "Noto Sans JP", system-ui, sans-serif;
  line-height: 1.35;
  padding: 10px;
  border-radius: 8px;
  outline: none;
  resize: none;
  max-width: calc(100vw - 24px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
  color: #111827;
}

.editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.editor-btn {
  padding: 6px 12px;
  min-height: 34px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--ui-bg-solid);
  border: 1px solid var(--ui-border-strong);
  box-shadow: var(--ui-shadow-sm);
}

/* ---------- レスポンシブ: 中幅デスクトップ衝突回避 ---------- */
@media (max-width: 1180px) {
  .selection-bar {
    left: 12px;
    right: 224px;
    transform: none;
    max-width: none;
  }
}

@media (max-width: 960px) {
  .hide-md {
    display: none;
  }
}

/* ---------- レスポンシブ: スマートフォン / タブレット (<= 768px) ---------- */
@media (max-width: 768px) {
  body.has-stealth-bar {
    --stealth-offset: 68px;
  }

  .stealth-admin-bar {
    padding: 5px 8px;
    gap: 6px;
  }

  #stealthAuthorInput {
    width: 150px;
    font-size: 16px;
    min-height: 36px;
  }

  #nameInput {
    font-size: 16px;
    min-height: 38px;
  }

  .menu-check {
    min-height: 38px;
  }

  .menu-check input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
  }

  .editor-btn {
    min-height: 40px;
    padding: 8px 16px;
    font-size: 13px;
  }

  .hide-sm {
    display: none;
  }

  .top-header {
    top: calc(8px + var(--stealth-offset));
    left: 8px;
    right: 8px;
    min-height: 44px;
    padding: 4px 7px;
    border-radius: 12px;
    gap: 5px;
  }

  .header-left {
    gap: 5px;
  }

  .board-title-wrap {
    max-width: 150px;
  }

  .board-title-btn {
    padding: 4px 6px;
    font-size: 12px;
  }

  .board-title-input {
    width: 150px;
    font-size: 16px;
  }

  .roombox code {
    padding: 2px 5px;
    font-size: 10px;
  }

  .peers-btn {
    padding: 3px 6px;
    min-height: 32px;
  }

  .peers-avatars {
    display: none;
  }

  .role-badge-btn {
    padding: 4px 8px;
    font-size: 11px;
    min-height: 28px;
  }

  .my-profile-btn {
    padding: 4px;
    min-height: 32px;
  }

  .modal {
    padding: 10px;
    align-items: flex-end;
  }

  .modal-card,
  .share-card {
    max-width: none;
    max-height: 88vh;
    max-height: 88dvh;
    border-radius: 16px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .welcome-modal,
  .access-gate-modal {
    align-items: center;
  }

  .share-select,
  .share-pass-inputs input,
  .dialog-input,
  #lobbyCodeInput,
  .peer-role-select {
    font-size: 16px;
    min-height: 40px;
  }

  .share-invite-input {
    font-size: 13px;
    min-height: 38px;
  }

  .share-pass-inputs,
  .share-invite-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .share-pass-inputs input,
  .share-invite-input {
    flex: 1 1 100%;
  }

  .share-pass-inputs button,
  .share-invite-row button,
  #shareUpgradeBtn,
  .share-links-grid button,
  .dialog-actions button,
  .gate-actions button,
  .gate-actions a {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 12px;
  }

  .share-check-label {
    min-height: 40px;
    font-size: 12px;
  }

  .share-check-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
  }

  .peer-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 14px;
  }

  .peer-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .peer-actions button,
  .peer-kick-btn {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 12px;
  }

  .peer-manage-controls {
    width: 100%;
    flex-wrap: wrap;
  }

  .peer-role-select {
    flex: 1 1 auto;
    min-height: 36px;
  }

  .btn-primary-pill {
    padding: 6px 10px;
    min-height: 32px;
    font-size: 11px;
  }

  /* 下部サムドック */
  .tool-dock {
    top: auto;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    right: 8px;
    transform: none;
    max-width: none;
    padding: 5px 6px;
    gap: 4px;
    border-radius: 16px;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
  }

  .tool-dock button {
    min-width: 46px;
    min-height: 46px;
    padding: 5px 6px;
  }

  .hide-sm-dock {
    display: none !important;
  }

  .mobile-only-btn {
    display: inline-flex;
  }

  .shape-group-wrap {
    display: inline-flex;
    position: relative;
    flex: 0 0 auto;
  }

  .shape-group-trigger {
    display: inline-flex;
  }

  .shape-tools {
    display: none;
    position: fixed;
    left: 12px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    background: var(--ui-bg-solid);
    border: 1px solid var(--ui-border-strong);
    border-radius: 14px;
    box-shadow: var(--ui-shadow);
    padding: 6px;
    gap: 4px;
    z-index: 75;
  }

  .shape-tools.open,
  .shape-tools.is-portal.open {
    display: flex;
    align-items: center;
  }

  .shape-tools.is-portal button {
    flex-direction: column;
    gap: 2px;
    min-width: 46px;
    min-height: 46px;
    padding: 5px 6px;
    border-radius: 10px;
    border-color: transparent;
  }

  .shape-tools.is-portal button:hover {
    background: var(--ui-bg-hover);
  }

  .shape-tools.is-portal button.active {
    background: var(--ui-accent-soft);
    border-color: var(--ui-accent-border);
    color: var(--ui-accent);
  }

  .shape-tools.is-portal .tlabel {
    font-size: 10px;
    line-height: 1;
    font-weight: 600;
  }

  /* スタイルパネル -> モバイルボトムシート */
  .style-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 75vh;
    overflow-y: auto;
    border-radius: 18px 18px 0 0;
    padding: 12px 16px calc(18px + env(safe-area-inset-bottom));
    z-index: 68;
    transform: translateY(105%);
    transition: transform 0.2s ease-out;
  }

  .style-panel.open {
    transform: translateY(0);
  }

  .style-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 700;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--ui-border);
  }

  .swatches {
    gap: 8px;
  }

  .swatch {
    width: 30px;
    height: 30px;
  }

  .style-mobile-extra-tools {
    display: flex;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--ui-border);
  }

  .style-mobile-extra-tools button {
    flex: 1;
    min-height: 40px;
  }

  /* 選択コンテキストバー -> 下部ドック直上 */
  .selection-bar {
    left: 8px;
    right: 8px;
    bottom: calc(70px + env(safe-area-inset-bottom));
    transform: none;
    max-width: none;
    padding: 6px 8px;
    border-radius: 12px;
    z-index: 29;
    -webkit-overflow-scrolling: touch;
  }

  .sel-btn {
    min-height: 38px;
    padding: 6px 10px;
  }

  /* ズーム＆ミニマップ -> ドック上右側 */
  .bottom-right-controls {
    right: 8px;
    bottom: calc(70px + env(safe-area-inset-bottom));
  }

  body.has-selection .bottom-right-controls {
    bottom: calc(126px + env(safe-area-inset-bottom));
  }

  .touch-mode-chip {
    left: 8px;
    bottom: calc(70px + env(safe-area-inset-bottom));
  }

  body.has-selection .touch-mode-chip {
    bottom: calc(126px + env(safe-area-inset-bottom));
  }

  body.shape-menu-open .bottom-right-controls,
  body.shape-menu-open .touch-mode-chip {
    bottom: calc(136px + env(safe-area-inset-bottom));
  }

  body.has-selection.shape-menu-open .bottom-right-controls,
  body.has-selection.shape-menu-open .touch-mode-chip {
    bottom: calc(190px + env(safe-area-inset-bottom));
  }

  .zoom-pill .tlabel,
  .minimap-toggle-label {
    display: none;
  }

  #minimap {
    width: 126px;
    height: 86px;
  }

  .panel {
    top: auto;
    bottom: calc(70px + env(safe-area-inset-bottom));
    left: 8px;
    right: 8px;
    width: auto;
    max-height: 62vh;
  }

  .toast-container {
    top: calc(58px + var(--stealth-offset));
    right: 8px;
    left: 8px;
    align-items: center;
    max-width: none;
  }
}

@media (max-width: 640px) {
  body.has-stealth-bar {
    --stealth-offset: 78px;
  }

  .top-header {
    flex-wrap: wrap;
    row-gap: 4px;
    padding: 5px 8px;
  }

  .header-left {
    flex: 1 1 100%;
    flex-wrap: wrap;
    gap: 5px;
  }

  .header-right {
    flex: 1 1 100%;
    justify-content: flex-end;
  }

  .board-title-wrap {
    max-width: calc(100vw - 170px);
  }

  .share-links-grid {
    grid-template-columns: 1fr;
  }

  .toast-container {
    top: calc(92px + var(--stealth-offset));
  }
}

@media (max-width: 440px) {
  .hide-xs {
    display: none;
  }

  .board-title-wrap {
    max-width: 140px;
  }

  .gate-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .touch-mode-btn {
    padding: 6px 10px;
    font-size: 11px;
    min-height: 34px;
  }

  .zoom-pill {
    padding: 3px 4px;
  }

  #zoomLabel {
    min-width: 34px;
    font-size: 11px;
  }
}
