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

:root {
  --bg: #0f1117; --surface: #1a1d27; --surface2: #222535; --surface3: #2a2e42;
  --border: #2e3249; --accent: #5b7fff; --accent2: #7a95ff;
  --success: #22c55e; --danger: #ef4444; --warning: #f59e0b;
  --text: #e2e8f0; --muted: #8892a4;
  --font: 'Outfit', sans-serif;
  --topbar-h: 54px;
  --lib-w: 196px;
  --right-w: 268px;
  --pb-h: 38px;
  --r: 7px;
}

html, body { height: 100%; overflow: hidden; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 12px; }

/* ── TOPBAR ──────────────────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  flex-shrink: 0;
  z-index: 100;
  position: relative;
}

/* ISSUE #8: App title replaces simple logo */
.app-title {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 4px;
}
.app-version {
  font-size: 10px;
  color: var(--muted);
  font-weight: 400;
}

.task-nav { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.nav-arrow {
  background: var(--surface2); border: 1px solid var(--border); color: var(--muted);
  width: 28px; height: 28px; border-radius: var(--r); cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.nav-arrow:hover { border-color: var(--accent); color: var(--text); }
#taskNavLabel { font-size: 11px; color: var(--muted); white-space: nowrap; min-width: 42px; text-align: center; }

/* ISSUE #8: Shortened task bar */
.task-bar { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 560px; }
.task-bar input[type="text"] {
  flex: 1; background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 6px 10px; border-radius: var(--r); font-family: var(--font); font-size: 12px; min-width: 0;
}
.task-bar input[type="text"]:focus { outline: none; border-color: var(--accent); }

.task-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.task-controls label { display: flex; align-items: center; gap: 4px; color: var(--muted); cursor: pointer; font-size: 10px; }
.task-controls input[type="range"] { accent-color: var(--accent); }

.toggle-wrap { display: flex; align-items: center; gap: 5px; cursor: pointer; color: var(--muted); font-size: 10px; white-space: nowrap; }
.toggle-wrap input { display: none; }
.toggle { width: 28px; height: 15px; background: var(--surface3); border-radius: 8px; position: relative; transition: background 0.2s; border: 1px solid var(--border); flex-shrink: 0; }
.toggle::after { content: ''; position: absolute; width: 9px; height: 9px; background: #fff; border-radius: 50%; top: 2px; left: 2px; transition: left 0.2s; }
.toggle-wrap input:checked + .toggle { background: var(--accent); border-color: var(--accent); }
.toggle-wrap input:checked + .toggle::after { left: 15px; }

.topbar-actions { display: flex; gap: 6px; flex-shrink: 0; margin-left: auto; }

/* ISSUE #9: Child screen info badge */
.child-screen-info {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--success);
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: 20px;
  padding: 2px 8px;
  white-space: nowrap;
}

/* ── BUTTONS ─────────────────────────────────────────────────────────── */
.btn { padding: 6px 12px; border-radius: var(--r); border: 1px solid transparent; font-family: var(--font); font-size: 11px; font-weight: 600; cursor: pointer; transition: all 0.15s; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.btn-ghost { background: var(--surface2); border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { background: var(--surface3); color: var(--text); border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-xs { padding: 3px 8px; font-size: 10px; background: var(--surface2); border: 1px solid var(--border); color: var(--muted); border-radius: 4px; cursor: pointer; font-family: var(--font); }
.btn-xs:hover { color: var(--text); border-color: var(--accent); }

/* ── MAIN LAYOUT ─────────────────────────────────────────────────────── */
#main {
  display: grid;
  grid-template-columns: var(--lib-w) 1fr var(--right-w);
  height: calc(100vh - var(--topbar-h) - var(--pb-h));
  overflow: hidden;
}

/* ── LIBRARY ─────────────────────────────────────────────────────────── */
#library { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }

.lib-tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border); background: var(--bg); }
.lib-tabs button { flex: 1; min-width: 0; padding: 4px 2px; background: transparent; border: 1px solid transparent; border-radius: 4px; color: var(--muted); font-size: 9.5px; font-family: var(--font); cursor: pointer; transition: all 0.12s; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-tabs button:hover { background: var(--surface2); color: var(--text); }
.lib-tabs button.active { background: var(--accent); color: #fff; }

#libContent { flex: 1; overflow-y: auto; padding: 8px 6px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

.lib-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.lib-group-label { font-size: 9px; color: var(--muted); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; margin: 8px 0 4px; }

.lib-item { display: flex; align-items: center; justify-content: center; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r); padding: 6px 4px; cursor: grab; font-family: 'Fredoka One', sans-serif; font-size: 20px; height: 46px; transition: all 0.12s; position: relative; user-select: none; overflow: hidden; }
.lib-item:hover { background: var(--surface3); border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 3px 10px rgba(91,127,255,0.2); }
.lib-item:active { cursor: grabbing; transform: scale(0.95); }
.lib-label { position: absolute; bottom: 1px; right: 3px; font-family: var(--font); font-size: 8px; color: var(--muted); pointer-events: none; }

/* ISSUE #5: Fixed quick words layout */
.qword-list { display: flex; flex-direction: column; gap: 5px; }
.qword-item { display: flex; align-items: center; gap: 5px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r); padding: 4px 6px; cursor: pointer; transition: all 0.12s; }
.qword-item:hover { border-color: var(--accent); }
.qword-text { flex: 1; font-family: 'Fredoka One', sans-serif; font-size: 14px; cursor: pointer; }
.qword-text[contenteditable="true"] { outline: 1px solid var(--accent); border-radius: 3px; padding: 1px 3px; cursor: text; }
.qword-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px; }
.qword-del:hover { color: var(--danger); }
/* ISSUE #5: Fixed add button layout - full width, button not cut off */
.qword-add { display: flex; gap: 5px; margin-bottom: 6px; width: 100%; }
.qword-add input { flex: 1; min-width: 0; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 5px 8px; border-radius: var(--r); font-family: var(--font); font-size: 12px; }
.qword-add input:focus { outline: none; border-color: var(--accent); }
.qword-add .btn { flex-shrink: 0; }

/* Image gallery */
.img-gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.img-thumb { position: relative; aspect-ratio: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; cursor: pointer; }
.img-thumb img { width: 100%; height: 100%; object-fit: cover; }
.img-thumb:hover { border-color: var(--accent); }
.img-thumb .img-del { position: absolute; top: 2px; right: 2px; background: var(--danger); border: none; color: #fff; width: 18px; height: 18px; border-radius: 50%; cursor: pointer; font-size: 10px; display: none; align-items: center; justify-content: center; }
.img-thumb:hover .img-del { display: flex; }
.upload-zone { border: 2px dashed var(--border); border-radius: var(--r); padding: 16px; text-align: center; color: var(--muted); cursor: pointer; transition: border-color 0.2s; margin-bottom: 8px; font-size: 11px; }
.upload-zone:hover { border-color: var(--accent); color: var(--text); }

/* ── CANVAS AREA ─────────────────────────────────────────────────────── */
#canvas-area { display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }

.canvas-toolbar { display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }
.canvas-toolbar label { display: flex; align-items: center; gap: 5px; cursor: pointer; color: var(--muted); }
.canvas-toolbar input[type="color"] { width: 26px; height: 20px; border: none; background: none; cursor: pointer; border-radius: 3px; padding: 1px; }
.canvas-toolbar input[type="checkbox"] { accent-color: var(--accent); }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 10px; font-style: italic; }

#canvas-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: hidden; }

#canvas {
  position: relative;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
  /* ISSUE #9: Default ratio, overridden by JS when child connects */
  aspect-ratio: 16/10;
  width: 100%;
  max-width: 860px;
  max-height: calc(100vh - var(--topbar-h) - var(--pb-h) - 80px);
  cursor: crosshair;
}

#grid-overlay { position: absolute; inset: 0; background-image: linear-gradient(rgba(0,0,0,0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(0,0,0,0.05) 1px, transparent 1px); background-size: 10% 10%; pointer-events: none; opacity: 0; transition: opacity 0.2s; z-index: 0; }
#grid-overlay.on { opacity: 1; }

/* ISSUE #4: Task overlay with matching banner style */
#task-overlay-prev {
  position: absolute; top: 0; left: 0; right: 0;
  z-index: 10; text-align: center; padding: 5px 44px 5px 10px;
  font-family: 'Nunito', sans-serif; font-weight: 900; color: #fff;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 0 0 8px 8px;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Canvas elements */
.canvas-el { position: absolute; transform-origin: center center; cursor: move; z-index: 2; }
.canvas-el:hover { outline: 1px dashed rgba(91,127,255,0.5); }
.canvas-el.selected { outline: 2px solid var(--accent) !important; }
.canvas-el.is-answer:not(.selected) { outline: 2px dashed var(--success) !important; }
.canvas-el.child-clicked { animation: cPulse 0.6s ease; }
@keyframes cPulse { 0%,100% { box-shadow: none; } 50% { box-shadow: 0 0 0 12px rgba(91,127,255,0.4); } }

.canvas-el svg { display: block; width: 100%; height: 100%; }
.canvas-el img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }

/* Rubber-band selection rect */
#rubber-band { position: absolute; border: 1.5px dashed var(--accent); background: rgba(91,127,255,0.08); pointer-events: none; z-index: 50; }

/* Selection overlay with handles */
#sel-overlay { position: absolute; border: 2px solid var(--accent); pointer-events: none; z-index: 60; transform-origin: center center; }
.sh { position: absolute; width: 10px; height: 10px; background: #fff; border: 2px solid var(--accent); border-radius: 2px; pointer-events: all; z-index: 61; }
.sh-nw { top:-5px; left:-5px; cursor:nwse-resize; }
.sh-n  { top:-5px; left:calc(50% - 5px); cursor:ns-resize; }
.sh-ne { top:-5px; right:-5px; cursor:nesw-resize; }
.sh-e  { top:calc(50% - 5px); right:-5px; cursor:ew-resize; }
.sh-se { bottom:-5px; right:-5px; cursor:nwse-resize; }
.sh-s  { bottom:-5px; left:calc(50% - 5px); cursor:ns-resize; }
.sh-sw { bottom:-5px; left:-5px; cursor:nesw-resize; }
.sh-w  { top:calc(50% - 5px); left:-5px; cursor:ew-resize; }
.sh-rot { top:-26px; left:calc(50% - 12px); cursor:grab; width:24px; height:24px; background:var(--accent); border-color:var(--accent2); color:#fff; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:13px; }
.sh-del { position:absolute; top:-22px; right:-22px; width:20px; height:20px; background:var(--danger); border:none; border-radius:50%; color:#fff; font-size:10px; cursor:pointer; display:flex; align-items:center; justify-content:center; pointer-events:all; }

/* ── RIGHT PANEL ─────────────────────────────────────────────────────── */
#right-panel { background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }

.right-tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--bg); }
.right-tabs button { flex: 1; padding: 8px 2px; background: transparent; border: none; border-bottom: 2px solid transparent; color: var(--muted); font-family: var(--font); font-size: 9px; font-weight: 600; cursor: pointer; transition: all 0.15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.right-tabs button:hover { color: var(--text); }
.right-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.rtab-content { display: none; flex: 1; overflow-y: auto; padding: 10px; flex-direction: column; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.rtab-content.active { display: flex; flex-direction: column; gap: 0; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 8px; color: var(--muted); text-align: center; }
.ei { font-size: 40px; opacity: 0.25; }
#no-sel { display: flex; flex: 1; }

/* ISSUE #3: Multi-select header */
.multi-sel-header { display: flex; align-items: center; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.multi-sel-header span:first-child { font-size: 20px; font-weight: 700; color: var(--accent); }
#multi-sel-props { display: none; }

/* Props shorthand */
.ps { border-bottom: 1px solid var(--border); padding: 8px 0; display: flex; flex-direction: column; gap: 6px; }
.psec { font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.pr { display: flex; align-items: center; gap: 6px; }
.pr label { width: 80px; flex-shrink: 0; color: var(--muted); font-size: 11px; }
.pr input[type="range"] { flex: 1; accent-color: var(--accent); }
.pr input[type="number"], .pr select, .pr input[type="text"] { flex: 1; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 4px 7px; border-radius: 5px; font-family: var(--font); font-size: 11px; }
.pr input:focus, .pr select:focus { outline: none; border-color: var(--accent); }
.pr select { background: var(--surface2); }
.pr input[type="color"] { width: 28px; height: 22px; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; background: none; padding: 1px; }
.pr input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.pr span { font-size: 10px; color: var(--muted); min-width: 28px; text-align: right; }

.props-actions { padding: 8px 0; display: flex; gap: 6px; }

/* Tasks tab */
.task-save-row { display: flex; gap: 6px; margin-bottom: 10px; flex-shrink: 0; }
.task-save-row input { flex: 1; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 6px 8px; border-radius: var(--r); font-family: var(--font); font-size: 12px; }
.task-save-row input:focus { outline: none; border-color: var(--accent); }

#quick-tasks-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.qt-item { display: flex; align-items: center; gap: 6px; padding: 7px 8px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r); cursor: pointer; transition: all 0.12s; user-select: none; }
.qt-item:hover { border-color: var(--accent); }
.qt-item.active-task { border-color: var(--success); background: rgba(34,197,94,0.08); }
.qt-drag-handle { color: var(--muted); cursor: grab; font-size: 12px; flex-shrink: 0; }
.qt-name { flex: 1; font-size: 12px; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qt-meta { font-size: 10px; color: var(--muted); max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qt-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; flex-shrink: 0; }
.qt-del:hover { color: var(--danger); }
/* ISSUE #10: Edit button */
.qt-edit { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 11px; flex-shrink: 0; padding: 2px 4px; }
.qt-edit:hover { color: var(--accent); }

.tasks-sep { border-top: 2px solid var(--border); margin: 8px 0; flex-shrink: 0; }

/* Template sections */
.template-sections { display: flex; flex-direction: column; gap: 8px; }
.tmpl-section { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.tmpl-section-header { padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 12px; }
.tmpl-section-header:hover { background: var(--surface3); }
.tmpl-section-body { padding: 6px 8px 8px; display: flex; flex-direction: column; gap: 4px; }
.tmpl-btn { padding: 6px 8px; background: var(--surface3); border: 1px solid var(--border); border-radius: 5px; color: var(--text); font-family: var(--font); font-size: 11px; cursor: pointer; text-align: left; transition: all 0.12s; }
.tmpl-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── ISSUE #7: Music tab ─────────────────────────────────────────────── */
.music-upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--r);
  padding: 16px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s;
  margin-bottom: 8px;
  font-size: 11px;
}
.music-upload-zone:hover { border-color: var(--accent); color: var(--text); }

.audio-list { display: flex; flex-direction: column; gap: 5px; }
.audio-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  cursor: pointer;
  transition: all 0.12s;
}
.audio-item:hover { border-color: var(--accent); }
.audio-item.active-audio { border-color: var(--success); background: rgba(34,197,94,0.1); }
.audio-icon { font-size: 16px; flex-shrink: 0; }
.audio-name { flex: 1; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audio-del { flex-shrink: 0; }

/* ── PROGRESS BAR ────────────────────────────────────────────────────── */
#progress-bar {
  height: var(--pb-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 10px;
  flex-shrink: 0;
  overflow: hidden;
}

.pb-stats { display: flex; align-items: center; gap: 10px; flex-shrink: 0; border-right: 1px solid var(--border); padding-right: 10px; margin-right: 10px; }
.pb-stat { font-size: 12px; font-weight: 700; display: flex; align-items: center; gap: 3px; }
.stat-ok { color: var(--success); }
.stat-no { color: var(--danger); }
.pb-acc { font-size: 10px; color: var(--muted); }

.pb-log-wrap { flex: 1; overflow: hidden; min-width: 0; }
#pb-log { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pb-log .pl-entry { display: inline; margin-right: 14px; }
#pb-log .pl-ok { color: var(--success); }
#pb-log .pl-no { color: var(--danger); }

.pb-actions { display: flex; gap: 5px; flex-shrink: 0; border-left: 1px solid var(--border); padding-left: 10px; margin-left: 10px; }

/* ── MODAL ───────────────────────────────────────────────────────────── */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 1000; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; min-width: 360px; max-width: 500px; position: relative; max-height: 80vh; overflow-y: auto; }
.modal-close { position: absolute; top: 10px; right: 12px; background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal-title { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.modal-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.modal-row input { flex: 1; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 7px 10px; border-radius: var(--r); font-family: var(--font); font-size: 12px; }
.modal-row input:focus { outline: none; border-color: var(--accent); }
.session-list { display: flex; flex-direction: column; gap: 5px; }
.sitem { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r); }
.sitem-name { flex: 1; font-weight: 600; font-size: 12px; }
.sitem-meta { font-size: 10px; color: var(--muted); }

/* Click notification */
.click-notif { position: fixed; bottom: calc(var(--pb-h) + 8px); left: 50%; transform: translateX(-50%) translateY(12px); background: var(--surface); border: 1px solid var(--border); border-radius: 40px; padding: 8px 18px; font-size: 12px; font-weight: 600; opacity: 0; transition: all 0.25s; z-index: 500; pointer-events: none; }
.click-notif.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.click-notif.ok { border-color: var(--success); color: var(--success); }
.click-notif.no { border-color: var(--danger); color: var(--danger); }
.click-notif.neutral { border-color: var(--accent); color: var(--accent); }

/* ── ISSUE #6: Context Menu ──────────────────────────────────────────── */
.ctx-menu {
  position: fixed;
  z-index: 2000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  min-width: 180px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
}
.ctx-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.ctx-item:hover { background: var(--surface2); }
.ctx-sep { height: 1px; background: var(--border); margin: 3px 4px; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE  (≤ 767px)
   ══════════════════════════════════════════════════════════════════════════ */

/* Mobile-only elements hidden on desktop */
.mob-topbar-controls { display: none; }
#mob-bottom-nav      { display: none; }
#mob-drawer          { display: none; }
#mob-drawer-overlay  { display: none; }

@media (max-width: 767px) {

  :root {
    --topbar-h: 50px;
    --mob-nav-h: 60px;
    --mob-drawer-h: 72vh;
  }

  /* ── Topbar on mobile: simplified ─────────────────────────────────────── */
  #topbar {
    padding: 0 8px;
    gap: 6px;
    justify-content: space-between;
  }

  /* Hide desktop-only topbar elements */
  .app-title    { display: none; }
  .task-nav     { display: none; }
  .task-bar     { display: none; }
  .topbar-actions { display: none; }

  /* Show mobile topbar controls */
  .mob-topbar-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
  }

  .mob-task-counter {
    font-size: 11px;
    color: var(--muted);
    min-width: 38px;
    text-align: center;
  }

  /* App title mini version */
  .mob-topbar-controls::before {
    content: '🍭';
    font-size: 20px;
    flex-shrink: 0;
  }

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

  /* ── Main layout: single column ───────────────────────────────────────── */
  #main {
    display: block;
    height: calc(100vh - var(--topbar-h) - var(--mob-nav-h));
    position: relative;
  }

  /* Library and right panel hidden (shown in drawer) */
  #library      { display: none; }
  #right-panel  { display: none; }

  /* Progress bar hidden on mobile (shown in drawer "more") */
  #progress-bar { display: none; }

  /* Canvas area fills screen */
  #canvas-area {
    height: 100%;
    width: 100%;
  }

  .canvas-toolbar {
    padding: 5px 8px;
    gap: 8px;
    font-size: 11px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .canvas-toolbar::-webkit-scrollbar { display: none; }
  .canvas-toolbar .hint { display: none; }

  #canvas-wrap {
    padding: 8px;
  }

  #canvas {
    border-radius: 8px;
    max-width: 100%;
    max-height: calc(100vh - var(--topbar-h) - var(--mob-nav-h) - 48px - 16px);
  }

  /* ── Mobile bottom navigation ─────────────────────────────────────────── */
  #mob-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--mob-nav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 500;
    padding: 0;
  }

  .mob-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 4px;
    transition: background 0.15s;
    border-top: 2px solid transparent;
  }
  .mob-nav-btn:active { background: var(--surface2); }
  .mob-nav-btn.active { border-top-color: var(--accent); }
  .mob-nav-btn.active .mob-nav-icon { filter: none; }
  .mob-nav-btn.active .mob-nav-label { color: var(--accent); }

  .mob-nav-icon  { font-size: 20px; line-height: 1; }
  .mob-nav-label { font-size: 9px; color: var(--muted); font-weight: 600; font-family: var(--font); }
  .mob-nav-btn.active .mob-nav-label { color: var(--accent); }

  /* ── Mobile Drawer (bottom sheet) ─────────────────────────────────────── */
  #mob-drawer-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
  }
  #mob-drawer-overlay.open {
    opacity: 1;
    pointer-events: all;
  }

  #mob-drawer {
    display: flex;
    flex-direction: column;
    position: fixed;
    bottom: var(--mob-nav-h);
    left: 0; right: 0;
    height: var(--mob-drawer-h);
    background: var(--surface);
    border-radius: 18px 18px 0 0;
    border: 1px solid var(--border);
    border-bottom: none;
    z-index: 700;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    overflow: hidden;
  }
  #mob-drawer.open {
    transform: translateY(0);
  }

  .mob-drawer-handle {
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 10px auto 6px;
    flex-shrink: 0;
  }

  #mob-drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }

  /* Inside drawer: library gets full lib-tabs treatment */
  #mob-drawer-content .lib-tabs {
    margin-bottom: 8px;
  }

  /* Inside drawer: right panel tabs */
  #mob-drawer-content .right-tabs {
    margin-bottom: 8px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
  }
  #mob-drawer-content .right-tabs button {
    font-size: 11px;
    padding: 10px 4px;
  }
  #mob-drawer-content .rtab-content {
    max-height: calc(var(--mob-drawer-h) - 120px);
    overflow-y: auto;
  }
  #mob-drawer-content .rtab-content.active {
    display: flex;
  }

  /* "More" panel in drawer */
  .mob-more-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .mob-more-panel .mob-more-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 4px;
  }
  .mob-more-panel .mob-more-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
  .mob-more-panel .btn {
    flex: 1;
    min-width: 120px;
    justify-content: center;
  }

  /* Mobile task field in drawer */
  .mob-task-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
  }
  .mob-task-input-row input[type="text"] {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 10px;
    border-radius: var(--r);
    font-family: var(--font);
    font-size: 13px;
  }
  .mob-task-input-row input:focus { outline: none; border-color: var(--accent); }

  /* Progress inside "more" on mobile */
  .mob-progress-mini {
    display: flex;
    gap: 16px;
    align-items: center;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 10px 14px;
  }
  .mob-progress-mini .pb-stat { font-size: 14px; }

  /* Context menu works on mobile too */
  .ctx-menu { font-size: 13px; }
  .ctx-item { padding: 11px 14px; }
}

@media (max-width: 400px) {
  .mob-nav-label { font-size: 8px; }
  .mob-nav-icon  { font-size: 18px; }
}
