/* ---- Fonts (self-hosted Marmelad) ---- */
/* cyrillic-ext */
@font-face {
  font-family: 'Marmelad';
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url('/fonts/marmelad-cyrillic-ext.woff2') format('woff2');
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
/* cyrillic */
@font-face {
  font-family: 'Marmelad';
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url('/fonts/marmelad-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* vietnamese */
@font-face {
  font-family: 'Marmelad';
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url('/fonts/marmelad-vietnamese.woff2') format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
  font-family: 'Marmelad';
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url('/fonts/marmelad-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Marmelad';
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url('/fonts/marmelad-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---- Reset ---- */
* { margin: 0; padding: 0; box-sizing: border-box; }

/* ---- CSS Custom Properties (Light/Dark) ---- */
:root,
[data-theme="light"] {
  --bg: #f8f9fa;
  --surface: #fff;
  --surface-hover: #f1f3f5;
  --surface-active: #e7f5ff;
  --text: #495057;
  --text-muted: #868e96;
  --text-accent: #1971c2;
  --border: #dee2e6;
  --border-active: #1971c2;
  --shadow: rgba(0,0,0,.1);
  --shadow-lg: rgba(0,0,0,.05);
  --swatch-border: transparent;
  --key-color: #adb5bd;
  --disabled-opacity: .3;
  --overlay-bg: rgba(0,0,0,.4);
  --dialog-bg: #fff;
  --mobile-rail-width: 48px;
  --mobile-dock-height: 56px;
}

[data-theme="dark"] {
  --bg: #1e1e1e;
  --surface: #2d2d2d;
  --surface-hover: #3a3a3a;
  --surface-active: #1a3a5c;
  --text: #ced4da;
  --text-muted: #868e96;
  --text-accent: #74b6ff;
  --border: #444;
  --border-active: #74b6ff;
  --shadow: rgba(0,0,0,.3);
  --shadow-lg: rgba(0,0,0,.2);
  --swatch-border: #555;
  --key-color: #666;
  --disabled-opacity: .25;
  --overlay-bg: rgba(0,0,0,.6);
  --dialog-bg: #2d2d2d;
}

body {
  overflow: hidden;
  background: var(--bg);
  font-family: system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  color: var(--text);
}

#canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  touch-action: none;
}

/* ---- Hamburger Menu ---- */
#menu-bar {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
}

/* ---- Canvas title chip (own pill, JS-positioned left of centered toolbar) ---- */
#canvas-title {
  position: fixed;
  top: 12px;
  /* left/right computed by JS; fallback puts chip near upper-left edge */
  right: calc(50% + 240px);
  height: 36px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  max-width: 240px;
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  box-shadow: 0 1px 4px var(--shadow), 0 4px 12px var(--shadow-lg);
  font-size: 13px;
  cursor: text;
  z-index: 10;
  transition: background .15s;
}
#canvas-title:hover { background: var(--surface-hover); }
#canvas-title:focus-visible {
  outline: 2px solid var(--text-accent, currentColor);
  outline-offset: 2px;
}
#canvas-title .ct-label {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}
#canvas-title .ct-input {
  width: 100%;
  min-width: 160px;
  height: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0;
  margin: 0;
}

/* ---- Dropdown (shared for menu & context menu) ---- */
.dropdown {
  position: absolute;
  min-width: 200px;
  padding: 4px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 4px 16px var(--shadow), 0 1px 4px var(--shadow);
  z-index: 30;
}
#menu-dropdown { top: 42px; left: 0; }
.hidden { display: none !important; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none; border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background .1s;
}
.menu-item:hover { background: var(--surface-hover); }
.menu-item svg { flex-shrink: 0; color: var(--text-muted); }
.menu-arrow { margin-left: auto; color: var(--text-muted); font-size: 10px; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 8px; }
.shortcut { margin-left: auto; font-size: 11px; color: var(--text-muted); }

.submenu {
  position: absolute;
  left: 100%; top: 0;
  min-width: 120px;
  padding: 8px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 4px 16px var(--shadow);
}
.canvas-bg-colors { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Context Menu ---- */
#context-menu { position: fixed; }

/* ---- Toolbar ---- */
#toolbar {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 1px 4px var(--shadow), 0 4px 12px var(--shadow-lg);
  z-index: 10;
}

.tool, .action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: none; border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tool {
  position: relative;
  flex-direction: column;
  gap: 0;
  height: 42px;
  padding-top: 4px;
}
.tool-key {
  font-size: 9px; font-weight: 600;
  line-height: 1;
  color: var(--key-color);
  pointer-events: none;
}
.tool.active .tool-key { color: var(--text-accent); }
.tool:hover, .action:hover:not(:disabled) { background: var(--surface-hover); }
.tool.active { background: var(--surface-active); color: var(--text-accent); }
.action:disabled { opacity: var(--disabled-opacity); cursor: default; }
.divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

#toolbar-hint {
  position: fixed;
  top: 69px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--key-color);
  pointer-events: none;
  z-index: 9;
  white-space: nowrap;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  gap: 4px;
  align-items: center;
}
#toolbar-hint kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  line-height: 1.4;
  box-shadow: 0 1px 0 var(--shadow);
}
#toolbar-hint .hint-sep { opacity: .5; margin: 0 4px; }

#app-version {
  margin-left: 6px;
  padding: 2px 6px;
  font-size: 11px;
  color: var(--key-color);
  opacity: .9;
  user-select: none;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-decoration: underline;
  border-radius: 3px;
  transition: opacity .15s;
}
#app-version:hover { opacity: 1; }

/* ---- Top-right group (help, about, sync, version) — no background ---- */
#top-right-group {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  z-index: 10;
}
body.is-mobile #top-right-group { display: none !important; }

/* ---- Properties Panel ---- */
#props {
  position: fixed;
  top: 70px; left: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 1px 4px var(--shadow), 0 4px 12px var(--shadow-lg);
  z-index: 10;
  min-width: 152px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}
.prop-label {
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}
.color-row { display: flex; gap: 6px; flex-wrap: wrap; }
.color-swatch {
  width: 24px; height: 24px;
  border-radius: 6px;
  border: 2.5px solid var(--swatch-border);
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: var(--border-active); }
.color-swatch.transparent-swatch {
  background: var(--surface);
  border: 2.5px dashed var(--border);
  position: relative;
}
.color-swatch.transparent-swatch::after {
  content: '';
  position: absolute;
  top: 2px; left: 50%;
  width: 1.5px;
  height: calc(100% - 4px);
  background: #e03131;
  transform: rotate(45deg);
  transform-origin: top center;
}
.color-swatch.transparent-swatch.active { border-color: var(--border-active); border-style: solid; }

.width-row { display: flex; gap: 6px; }
.width-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 28px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.width-btn:hover { background: var(--surface-hover); }
.width-btn.active { border-color: var(--border-active); background: var(--surface-active); }
.width-line { background: var(--text); border-radius: 2px; }

/* ---- Style controls ---- */
.style-row { display: flex; gap: 6px; flex-wrap: wrap; }
.style-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px; min-width: 36px;
  padding: 0 8px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 11px; font-weight: 600;
  color: var(--text);
  transition: border-color .15s, background .15s;
}
.style-btn:hover { background: var(--surface-hover); }
.style-btn.active { border-color: var(--border-active); background: var(--surface-active); color: var(--text-accent); }
.style-btn svg { display: block; }

/* ---- Opacity ---- */
.opacity-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
#opacity-slider {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
#opacity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text-accent);
  cursor: pointer;
}
#opacity-slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text-accent);
  border: none;
  cursor: pointer;
}
#opacity-val {
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
}

/* ---- Text Input ---- */
#text-input {
  display: none;
  position: fixed;
  z-index: 20;
  font-family: 'Marmelad', sans-serif;
  background: transparent;
  border: none; outline: none;
  resize: none; overflow: hidden;
  padding: 0; margin: 0;
  color: transparent;
  caret-color: var(--text);
  line-height: 1.25;
  min-width: 60px;
  white-space: pre;
}
#text-input::selection { color: transparent; background: rgba(25, 113, 194, .3); }
#text-input::-moz-selection { color: transparent; background: rgba(25, 113, 194, .3); }

/* ---- Zoom ---- */
#zoom-controls {
  position: fixed;
  bottom: 12px; left: 12px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 1px 4px var(--shadow);
  z-index: 10;
}
#zoom-controls button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: none; border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  font-weight: bold;
}
#zoom-controls button:hover { background: var(--surface-hover); }
#zoom-level {
  font-size: 12px;
  color: var(--text);
  min-width: 40px;
  text-align: center;
  font-weight: 500;
}

/* ---- Sync status ---- */
#sync-status {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #868e96;
  margin: 0 4px;
  align-self: center;
  flex-shrink: 0;
  transition: background .3s;
}
#sync-status.saved { background: #2f9e44; }
#sync-status.saving { background: #f08c00; }
#sync-status.error { background: #e03131; }
#sync-status.offline { background: #868e96; }

/* ---- Toast ---- */
#toast {
  position: fixed;
  bottom: 48px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 8px 16px;
  background: #1e1e1e;
  color: #fff;
  border-radius: 8px;
  font-size: 13px; font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 30;
}
[data-theme="dark"] #toast { background: #f8f9fa; color: #1e1e1e; }
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Help dialog ---- */
.overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: var(--overlay-bg);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dialog {
  background: var(--dialog-bg);
  border-radius: 12px;
  box-shadow: 0 8px 32px var(--shadow);
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.dialog-header h3 { font-size: 16px; font-weight: 600; color: var(--text); }
.dialog-close {
  width: 28px; height: 28px;
  border: none; border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dialog-close:hover { background: var(--surface-hover); }
.dialog-body { padding: 20px; }

.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 24px;
}
.sc-section h4 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.sc-row {
  font-size: 13px;
  color: var(--text);
  padding: 3px 0;
}
kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-hover);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  margin-right: 2px;
}

/* ---- Scrollbar for props panel ---- */
#props::-webkit-scrollbar { width: 4px; }
#props::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
#props.collapsed .prop-group.extra { display: none; }
#props-toggle {
  background: none;
  border: none;
  padding: 2px 0;
  margin-top: -4px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  align-self: flex-start;
}
#props-toggle:hover { color: var(--text); }
#props-toggle .props-toggle-arrow { display: inline-block; margin-left: 2px; }
#props:not(.collapsed) #props-toggle .props-toggle-arrow { transform: rotate(180deg); }

/* ---- Mobile: bottom dock (portrait + landscape, unified) ----
   Activated via body classes set by client/src/mobile-mode.js.
   Detection lives in JS (matchMedia), CSS only reacts to classes.
*/

/* Hide secondary controls on mobile — moved to overflow menu / floating bars */
body.is-mobile #menu-bar,
body.is-mobile #menu-btn,
body.is-mobile #btn-advanced,
body.is-mobile #btn-lock,
body.is-mobile #toolbar [data-tool="diamond"],
body.is-mobile #toolbar [data-tool="ellipse"],
body.is-mobile #toolbar [data-tool="eraser"],
body.is-mobile #toolbar [data-tool="laser"],
body.is-mobile #toolbar [data-tool="numbered"],
body.is-mobile #btn-undo,
body.is-mobile #btn-redo,
body.is-mobile #btn-canvases,
body.is-mobile #btn-clear,
body.is-mobile #btn-help,
body.is-mobile #btn-about,
body.is-mobile #sync-status,
body.is-mobile #app-version,
body.is-mobile #toolbar .divider {
  display: none !important;
}

/* Overflow button — only visible on mobile */
#toolbar-overflow { display: none; }
body.is-mobile #toolbar-overflow { display: flex; order: 99; }

/* Compact tool sizing on mobile (no keyboard hints) */
body.is-mobile .tool,
body.is-mobile .action {
  width: 40px; height: 40px;
}
body.is-mobile .tool {
  padding-top: 0;
  height: 40px;
}
body.is-mobile .tool-key { display: none; }

/* Canvas-title chip — top center on mobile, compact */
body.is-mobile #canvas-title {
  position: fixed;
  top: 8px;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  max-width: calc(100vw - 96px);
  height: 32px;
  font-size: 12px;
  padding: 0 10px;
  z-index: 12;
}

/* ---- Tool order in the dock: hand → select → arrow → rectangle → freedraw → text → image ---- */
body.is-mobile #toolbar [data-tool="hand"]      { order: 1; }
body.is-mobile #toolbar [data-tool="select"]    { order: 2; }
body.is-mobile #toolbar [data-tool="arrow"]     { order: 3; }
body.is-mobile #toolbar [data-tool="rectangle"] { order: 4; }
body.is-mobile #toolbar [data-tool="freedraw"]  { order: 5; }
body.is-mobile #toolbar [data-tool="text"]      { order: 6; }
body.is-mobile #btn-image                       { order: 7; }
body.is-mobile #btn-share                       { order: 8; display: flex; }

/* ---- Bottom dock (both portrait + landscape) ---- */
body.is-mobile #toolbar {
  position: fixed;
  top: auto;
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  left: 8px;
  right: 8px;
  transform: none;
  width: auto;
  height: var(--mobile-dock-height);
  flex-direction: row;
  align-items: center;
  justify-content: space-around;
  padding: 6px 8px;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
body.is-mobile #toolbar::-webkit-scrollbar { display: none; }

/* Toolbar hint sits above the floating row (which sits above dock) */
body.is-mobile #toolbar-hint {
  top: auto;
  bottom: calc(var(--mobile-dock-height) + 64px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  background: var(--surface);
  padding: 4px 10px;
  border-radius: 12px;
  box-shadow: 0 1px 4px var(--shadow);
  max-width: calc(100vw - 32px);
}

/* ---- Mobile floating bars: shape-picker (left) + actions (right), above dock ---- */
#mobile-shape-picker,
#mobile-actions {
  display: none;
}

body.is-mobile #mobile-actions {
  display: flex;
  position: fixed;
  bottom: calc(var(--mobile-dock-height) + 14px + env(safe-area-inset-bottom, 0px));
  right: 8px;
  flex-direction: row;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 1px 4px var(--shadow);
  z-index: 14;
}

body.is-mobile #mobile-actions .action {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}
body.is-mobile #mobile-actions .action:hover:not(:disabled) {
  background: var(--surface-hover);
}
body.is-mobile #mobile-actions .action:disabled {
  opacity: var(--disabled-opacity);
  cursor: default;
}

/* Delete button: only when something is actually selected (not during drawing). */
body.is-mobile #mobile-actions #mobile-delete { display: none; }
body.is-mobile.has-mobile-selection #mobile-actions #mobile-delete { display: flex; }

/* Shape picker — only when shape tool active */
body.is-mobile.has-shape-tool #mobile-shape-picker {
  display: flex;
  position: fixed;
  bottom: calc(var(--mobile-dock-height) + 14px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  flex-direction: row;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 1px 4px var(--shadow);
  z-index: 14;
}
body.is-mobile #mobile-shape-picker .tool {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}
body.is-mobile #mobile-shape-picker .tool:hover {
  background: var(--surface-hover);
}
body.is-mobile #mobile-shape-picker .tool.active {
  background: var(--surface-active);
  color: var(--text-accent);
}

/* ---- Toolbar overflow menu (replaces hamburger on mobile) ---- */
#toolbar-overflow-menu {
  position: fixed;
  z-index: 25;
  min-width: 220px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 4px 16px var(--shadow), 0 1px 4px var(--shadow);
}
#toolbar-overflow-menu .overflow-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  padding: 6px 10px 2px;
}
#toolbar-overflow-menu .menu-item {
  width: 100%;
}
#toolbar-overflow-menu .overflow-bg-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 10px 8px;
}
#toolbar-overflow-menu .overflow-bg-row.hidden { display: none; }
body.is-mobile #toolbar-overflow-menu {
  right: 12px;
  bottom: calc(var(--mobile-dock-height) + 60px + env(safe-area-inset-bottom, 0px));
}

/* ---- Mobile «Доп.» button + compact props popover ----
   Replaces the big bottom-sheet: button shows when relevant (selection or
   drawing tool active), tap toggles a small popover above-left with three
   controls (Обводка / Толщина / Стиль). Picking any value auto-closes.
*/
#mobile-props-btn { display: none; }
body.is-mobile.has-selection-sheet #mobile-props-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  position: fixed;
  bottom: calc(var(--mobile-dock-height) + 22px + env(safe-area-inset-bottom, 0px));
  left: 8px;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: none;
  border-radius: 8px;
  box-shadow: 0 1px 4px var(--shadow);
  cursor: pointer;
  z-index: 14;
}
body.is-mobile.has-selection-sheet #mobile-props-btn:hover {
  background: var(--surface-hover);
}
body.is-mobile.has-mobile-props-open #mobile-props-btn {
  background: var(--surface-active);
  color: var(--text-accent);
}
.mobile-props-arrow {
  font-size: 9px;
  transition: transform .15s;
}
body.is-mobile.has-mobile-props-open .mobile-props-arrow {
  transform: rotate(180deg);
}

/* #props on mobile — hidden by default, popover when «Доп.» open. */
body.is-mobile #props {
  display: none;
}
body.is-mobile.has-mobile-props-open #props {
  display: flex !important;
  position: fixed;
  top: auto;
  bottom: calc(var(--mobile-dock-height) + 64px + env(safe-area-inset-bottom, 0px));
  left: 8px;
  right: auto;
  margin: 0;
  width: auto;
  max-width: calc(100vw - 16px);
  min-width: 0;
  max-height: 60vh;
  border-radius: 12px;
  padding: 10px 12px;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 10px;
  z-index: 31;
  overflow-y: auto;
  background: var(--surface);
  box-shadow: 0 4px 16px var(--shadow);
}
/* Inside the popover: only show the 3 marked groups, hide everything else
   (incl. prop-label headers? — keep them, they label each row).
   Important: properties.js sets inline display:none on hidden-by-type groups,
   so we need !important to force-show our 3 groups regardless of element type. */
body.is-mobile.has-mobile-props-open #props .prop-group {
  display: none !important;
  flex: 0 0 auto;
}
body.is-mobile.has-mobile-props-open #props .prop-group[data-mobile-prop] {
  display: flex !important;
  flex-direction: column;
  gap: 4px;
}
body.is-mobile.has-mobile-props-open #props #props-toggle {
  display: none;
}

/* Zoom controls — hidden on mobile (dock + floating row occupy bottom) */
body.is-mobile #zoom-controls {
  display: none;
}
body.is-mobile #zoom-controls button { width: 24px; height: 24px; font-size: 14px; }
body.is-mobile #zoom-level { font-size: 11px; min-width: 32px; }

/* ---- Canvases dropdown (Мои полотна) ---- */
#btn-canvases.active { background: var(--surface-active); color: var(--text-accent); }
#canvases-dropdown {
  position: fixed;
  width: 320px;
  max-height: 70vh;
  padding: 6px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 4px 16px var(--shadow), 0 1px 4px var(--shadow);
  z-index: 30;
  display: flex;
  flex-direction: column;
}
#canvases-dropdown .dd-header {
  display: flex;
  align-items: center;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  flex-shrink: 0;
}
#canvases-dropdown .dd-title { font-size: 13px; font-weight: 600; color: var(--text); }
#canvases-dropdown .dd-count { font-size: 11px; color: var(--text-muted); margin-left: 6px; }
#canvases-dropdown .dd-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 0;
}
#canvases-dropdown .dd-empty {
  padding: 16px 12px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}
#canvases-dropdown .dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  color: var(--text);
}
#canvases-dropdown .dd-item:hover { background: var(--surface-hover); }
#canvases-dropdown .dd-item.active {
  background: var(--surface-active);
  color: var(--text-accent);
}
#canvases-dropdown .dd-item.active .dd-meta { color: var(--text-accent); opacity: .75; }
#canvases-dropdown .dd-icon {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--surface-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
#canvases-dropdown .dd-item.active .dd-icon { background: rgba(25,113,194,.12); color: var(--text-accent); }
#canvases-dropdown .dd-text { flex: 1; min-width: 0; }
#canvases-dropdown .dd-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#canvases-dropdown .dd-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
#canvases-dropdown .dd-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .1s;
}
#canvases-dropdown .dd-item:hover .dd-actions,
#canvases-dropdown .dd-item:focus-within .dd-actions { opacity: 1; }
#canvases-dropdown .dd-item.active .dd-actions { opacity: .6; }
#canvases-dropdown .dd-icon-btn {
  width: 24px; height: 24px;
  border: none; border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#canvases-dropdown .dd-icon-btn:hover { background: rgba(0,0,0,.06); color: var(--text); }
[data-theme="dark"] #canvases-dropdown .dd-icon-btn:hover { background: rgba(255,255,255,.08); }
#canvases-dropdown .dd-icon-btn.danger:hover { background: rgba(224,49,49,.12); color: #e03131; }
#canvases-dropdown .dd-sep { height: 1px; background: var(--border); margin: 4px 8px; flex-shrink: 0; }
#canvases-dropdown .dd-footer-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none; border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  flex-shrink: 0;
}
#canvases-dropdown .dd-footer-btn:hover { background: var(--surface-hover); }
#canvases-dropdown .dd-footer-btn svg { color: var(--text-muted); flex-shrink: 0; }
#canvases-dropdown .dd-footer-btn.primary,
#canvases-dropdown .dd-footer-btn.primary svg { color: var(--text-accent); }
#canvases-dropdown .dd-url-form {
  padding: 8px 10px 10px;
  flex-shrink: 0;
}
#canvases-dropdown .dd-url-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
#canvases-dropdown .dd-url-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
#canvases-dropdown .dd-url-input {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-family: ui-monospace, "SF Mono", monospace;
  color: var(--text);
  background: var(--bg);
  min-width: 0;
  resize: vertical;
  min-height: 38px;
}
#canvases-dropdown .dd-url-input:focus { outline: none; border-color: var(--text-accent); }
#canvases-dropdown .dd-url-btn {
  padding: 6px 10px;
  border: none; border-radius: 6px;
  background: var(--text-accent);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
#canvases-dropdown .dd-url-btn:hover { filter: brightness(1.05); }
#canvases-dropdown .dd-name-input {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--text-accent);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
#canvases-dropdown .dd-name-input:focus { outline: none; }
