/* Compact desktop header; tools wrap into a scrollable row on narrow screens. */
:root { --topbar-h: 64px; --sb-w: 280px; --radius: 10px; --ink-2: #94949e; }
[data-theme="slate"] { --ink-2: #9aa9bf; }
[data-theme="graphite"] { --ink-2: #a8a29e; }
[data-theme="midnight"] { --ink-1: #aaaacb; --ink-2: #9898b9; }
#app { height: 100dvh; width: 100%; grid-template-columns: var(--sb-w) minmax(0, 1fr); grid-template-rows: var(--topbar-h) minmax(0, 1fr) var(--timeline-h); }
#topbar { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); padding: 0 14px; gap: 0 12px; background: var(--bg-1); }
.tb-left { gap: 10px; min-width: 0; }
.brand { font-size: 15px; letter-spacing: .08em; }
.brand .dot { width: 7px; height: 18px; border-radius: 2px; }
.titlefield { font-size: 12px; color: var(--ink-1); border: 1px solid var(--line); padding: 8px 10px; max-width: 180px; min-width: 0; width: 100%; text-overflow: ellipsis; }
.tb-right { grid-column: 3; grid-row: 1; overflow: visible; }
.tb-center { grid-column: 2; grid-row: 1; min-width: 0; justify-content: flex-start; padding: 0; overflow-x: auto; scrollbar-width: thin; border-top: 0; }
/* Auto margins center the tools when they fit, and preserve the scroll origin on narrow screens. */
.tb-center .toolgroup { margin-inline: auto; border: 0; background: transparent; box-shadow: none; padding: 4px; gap: 2px; }
.tbtn { width: 36px; height: 36px; color: var(--ink-1); }
.tb-center .tbtn { width: 44px; height: 44px; flex-direction: column; gap: 4px; border-radius: 8px; }
.tool-label { font-size: 9px; font-weight: 500; line-height: 1; }
.tb-center .tbtn svg { width: 18px; height: 18px; }
.tbtn.active { color: var(--accent-fg); }
#styleControls { position: absolute; left: 14px; top: 14px; max-width: calc(100% - 28px); z-index: 12; padding: 9px 12px; gap: 10px; background: var(--bg-1); box-shadow: 0 8px 28px #0005; overflow-x: auto; scrollbar-width: thin; }
.ctrl-group { gap: 7px; flex-shrink: 0; }
.ctrl-group label { color: var(--ink-1); font-size: 10px; letter-spacing: .03em; }
select { min-height: 32px; }
input[type=color] { width: 28px; height: 28px; }
.swatch { width: 22px; height: 22px; padding: 0; }
.library-toggle { display: flex; align-items: center; justify-content: center; gap: 7px; min-width: 38px; height: 36px; border: 1px solid var(--line); background: var(--bg-2); color: var(--ink-0); border-radius: 8px; flex-shrink: 0; }
.library-toggle svg { width: 17px; height: 17px; }
#app.library-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
#app.library-collapsed #sidebar { visibility: hidden; }
body:has(#app.library-collapsed) #sb-resize { display: none; }
#sidebar { min-height: 0; }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; }
.sidebar-heading strong { font-size: 14px; font-weight: 600; }
.sidebar-heading span { display: block; color: var(--ink-1); font-size: 11px; margin-top: 5px; }
.sidebar-heading button { width: 32px; height: 32px; border: 0; background: transparent; color: var(--ink-1); border-radius: 6px; }
.tabs { margin: 0 12px 8px; padding: 3px; background: var(--bg-0); border: 1px solid var(--line); border-radius: 9px; }
.tab-wrapper { border: 0; }
.tab { font-size: 11px; letter-spacing: .02em; text-transform: none; height: 36px; border: 0; border-radius: 6px; color: var(--ink-1); }
.tab.active { background: var(--bg-3); color: var(--ink-0); box-shadow: 0 1px 4px #0003; }
.panel { padding: 8px 14px 20px; gap: 12px; overscroll-behavior: contain; }
.field-row { gap: 6px; }
.field-row label, .section-label { font-size: 10px; color: var(--ink-1); letter-spacing: .07em; }
.field-row input, .field-row select { min-height: 38px; font-size: 12px; padding: 8px 10px; }
.upload-btn { min-height: 40px; color: var(--ink-1); line-height: 1.5; text-align: center; }
.map-grid { gap: 9px; }
.map-card img { height: auto; aspect-ratio: 1.65; }
.map-card .cap { padding: 9px 8px; font-size: 11px; }
.map-card.selected { border-color: var(--ink-0); }
.map-card.selected .cap { background: var(--ink-0); color: var(--bg-0); }
.map-card .del { border: 0; width: 26px; height: 26px; color: white; }
.hero-icon-grid { grid-template-columns: repeat(auto-fill, minmax(48px,1fr)); gap: 7px; }
.hero-team-tab { min-height: 38px; }
.empty-hint { padding: 24px 12px; border: 1px dashed var(--line); border-radius: 8px; color: var(--ink-1); }
#zoomHud { bottom: 16px; right: 16px; padding: 4px; background: var(--bg-1); }
#zoomHud button { width: 34px; height: 34px; color: var(--ink-1); }
#zoomHud .pct { width: 48px; color: var(--ink-0); font-size: 11px; }
.hint-bar { left: 16px; bottom: 18px; transform: none; max-width: calc(100% - 220px); white-space: normal; line-height: 1.4; color: #b9b9c0; border-radius: 6px; padding: 5px 8px; }
#toast { position: fixed; top: calc(var(--topbar-h) + 16px); max-width: calc(100vw - 32px); text-align: center; line-height: 1.5; }
#toast:not(.show) { visibility: hidden; }
#timeline { min-width: 0; }
#pbBar { min-width: 0; }
#pbScrub { min-width: 30px; width: auto; }
#pbTime { color: var(--ink-1); }
.more-item, .theme-chip { min-height: 40px; font-size: 12px; }
.more-menu, .theme-picker, .callout-panel, #ctxmenu { max-width: calc(100vw - 24px); max-height: calc(100dvh - 140px); overflow-y: auto; }
#coachNote { max-width: calc(100vw - 24px); max-height: calc(100dvh - 140px); }
:where(button, input, select, textarea, [tabindex], [contenteditable]):focus-visible { outline: 2px solid var(--ink-0); outline-offset: 3px; }
.upload-btn:focus-visible, .map-card:focus-visible { outline-offset: -3px; }
.map-card:focus-within .del { opacity: 1; }
.tab-wrapper:focus-within .tab-float { width: 22px; }
#libraryBackdrop { display: none; }
@media (max-width: 1320px) and (min-width: 981px) {
  .tb-left .brand { display: none; }
}
@media (max-width: 980px) {
  :root { --topbar-h: 100px; }
  #topbar { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: 48px 52px; padding: 0 10px; gap: 0 8px; }
  .tb-right { grid-column: 2; grid-row: 1; }
  .tb-center { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 760px) {
  #app, #app.library-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
  .tb-left { gap: 8px; }
  .brand { font-size: 13px; }
  .brand .dot { display: none; }
  .titlefield { max-width: 160px; }
  #sidebar { position: fixed; left: 0; top: var(--topbar-h); bottom: 0; width: min(320px, calc(100vw - 48px)); z-index: 40; box-shadow: 16px 0 40px #0005; }
  #app:not(.library-collapsed) #libraryBackdrop { display: block; position: fixed; inset: var(--topbar-h) 0 0; background: #0008; z-index: 35; border: 0; }
  #sb-resize, .tab-float { display: none; }
  .tb-center .tbtn { width: 44px; }
  .hint-bar { bottom: 66px; max-width: calc(100% - 32px); font-size: 11px; }
  #zoomHud { bottom: max(12px, env(safe-area-inset-bottom)); right: 12px; }
  #zoomHud button { height: 40px; width: 40px; }
  #styleControls { left: 10px; top: 10px; max-width: calc(100% - 20px); }
  #pbName { display: none; }
  #timeline { padding: 0 6px; }
  #pbBar { gap: 5px; }
  #pbTime { min-width: 65px; font-size: 10px; }
  #coachNote { top: calc(var(--topbar-h) + 12px) !important; right: 12px !important; left: auto !important; }
  .float-panel { left: 12px !important; top: calc(var(--topbar-h) + 12px) !important; max-height: calc(100dvh - var(--topbar-h) - 24px); }
  #recBar > span:nth-child(3) { font-size: 10px !important; }
}
@media (max-width: 480px) {
  .brand { display: none; }
  .titlefield { max-width: none; }
  .tb-right .tbtn { width: 32px; }
  input, select, textarea { font-size: 16px !important; }
  #styleControls select { max-width: 140px; }
}
@media (pointer: coarse) {
  .tbtn, .library-toggle, .hero-team-tab, .tab, .upload-btn { min-height: 44px; }
  .hero-icon-cell button { touch-action: none; }
  .map-card .del { opacity: 1; width: 32px; height: 32px; }
  .cp-img-actions { display: flex; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
#boardWelcome { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); width: min(460px, calc(100% - 48px)); text-align: center; }
#boardWelcome[hidden] { display: none; }
.welcome-eyebrow { color: #a1a1aa; font-size: 10px; font-weight: 600; letter-spacing: .18em; }
#boardWelcome h1 { color: #fafafa; font-family: 'Inter', sans-serif; font-size: clamp(28px, 3.2vw, 46px); line-height: 1.12; letter-spacing: -.05em; margin: 18px 0; font-weight: 600; }
#boardWelcome p { color: #a1a1aa; font-size: 13px; line-height: 1.75; max-width: 320px; margin: 0 auto 24px; }
.welcome-actions { display: flex; justify-content: center; gap: 10px; }
.welcome-actions button { min-height: 42px; border-radius: 8px; padding: 10px 16px; border: 1px solid #ffffff26; color: #fafafa; background: #ffffff08; font-size: 12px; font-weight: 600; }
.welcome-actions #chooseMapBtn { background: #fafafa; color: #09090b; }
.welcome-actions button:hover { filter: brightness(.85); }
.welcome-actions span { margin-left: 12px; }
.welcome-footnote { display: block; color: #a1a1aa; font-size: 10px; margin-top: 24px; }
.welcome-footnote + .welcome-footnote { margin-top: 4px; }
.credits-link { color: inherit; text-decoration: underline; text-decoration-color: rgba(161,161,170,.45); text-underline-offset: 2px; }
.credits-link:hover { color: #fafafa; text-decoration-color: currentColor; }
@media (max-height: 520px) {
  #boardWelcome { top: 42%; }
  #boardWelcome h1 { font-size: 26px; margin: 8px 0; }
  #boardWelcome p { margin-bottom: 12px; }
  .welcome-eyebrow, .welcome-footnote { display: none; }
}
.tab-float { padding: 0; }
@media (max-width: 760px) {
  .tb-center { mask-image: linear-gradient(to right, #000 calc(100% - 12px), transparent); }
}

/* Theme accents follow the same roles throughout the workspace. */
:root { color-scheme: dark; }
.brand .dot { background: var(--accent); }
.tab.active { background: var(--accent-dim); color: var(--accent); }
.map-card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.map-card.selected .cap { background: var(--accent); color: var(--accent-fg); }
input[type=range], #pbScrub { accent-color: var(--accent); }
:where(button, input, select, textarea, [tabindex], [contenteditable]):focus-visible { outline-color: var(--accent); }
#boardWelcome h1 { color: var(--ink-0); }
.welcome-eyebrow, #boardWelcome p, .welcome-footnote { color: var(--ink-1); }
.welcome-actions button { color: var(--ink-0); background: var(--bg-1); border-color: var(--line); }
.welcome-actions #chooseMapBtn { background: var(--accent); color: var(--accent-fg); }
.theme-picker { width: 380px; min-width: 0; padding: 0; gap: 0; overflow: hidden; background: var(--bg-1); border-radius: 16px; }
.theme-heading { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 14px; flex-shrink: 0; border-bottom: 1px solid var(--line); }
.theme-heading strong { font-size: 15px; font-weight: 600; }
.theme-heading p { font-size: 12px; color: var(--ink-1); margin: 6px 0 0; }
.theme-close { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); color: var(--ink-1); }
.theme-collection { padding: 4px 16px 16px; overflow-y: auto; min-height: 0; overscroll-behavior: contain; scrollbar-width: thin; }
.theme-collection h3 { font-family: inherit; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .09em; color: var(--ink-1); margin: 16px 0 9px; }
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.theme-chip { display: flex; flex-direction: column; align-items: stretch; gap: 0; position: relative; padding: 5px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink-0); background: var(--bg-0); }
.theme-chip:hover { background: var(--bg-2); border-color: var(--ink-2); }
.theme-chip.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.theme-chip.active::after { content: none; }
.theme-preview { display: block; position: relative; height: 54px; border-radius: 5px; overflow: hidden; background: var(--preview-bg); }
.preview-header { display: flex; align-items: center; justify-content: space-between; position: absolute; inset: 0 0 auto; height: 12px; padding: 0 6px; background: var(--preview-panel); border-bottom: 1px solid #ffffff12; }
.preview-header i { width: 16px; height: 3px; border-radius: 2px; background: var(--preview-accent); }
.preview-header b { width: 26px; height: 4px; border-radius: 2px; background: var(--preview-raised); }
.preview-sidebar { position: absolute; top: 12px; bottom: 0; width: 28px; padding: 7px 5px; background: var(--preview-panel); display: grid; gap: 4px; align-content: start; }
.preview-sidebar i { height: 4px; border-radius: 2px; background: var(--preview-raised); }
.preview-sidebar i:first-child { background: var(--preview-accent); opacity: .7; }
.preview-stroke { position: absolute; width: 34px; height: 16px; top: 26px; left: 45%; border-top: 2px solid var(--preview-accent); border-right: 2px solid var(--preview-accent); border-radius: 0 8px 0 0; transform: rotate(-14deg); }
.preview-dot { position: absolute; right: 16%; bottom: 10px; width: 6px; height: 6px; border-radius: 50%; background: var(--preview-accent); }
.theme-caption { padding: 8px 4px 5px; display: grid; gap: 4px; }
.theme-caption strong { font-size: 12px; font-weight: 600; }
.theme-caption > span { color: var(--ink-1); font-size: 10px; }
.theme-check { display: none; position: absolute; right: 9px; top: 64px; color: var(--accent); font-size: 12px; }
.theme-chip.active .theme-check { display: block; }
.theme-footer { display: flex; justify-content: space-between; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 10px; color: var(--ink-1); flex-shrink: 0; }
.theme-current { color: var(--accent); }
@media (max-width: 480px) {
  .theme-picker { width: calc(100vw - 24px); right: 12px !important; }
}

/* Keep rotation and zoom controls within narrow boards. */
#zoomHud #mapRotation { width: 44px; font-size: 11px; font-variant-numeric: tabular-nums; }
@media (max-width: 480px) {
  #zoomHud { display: grid; grid-template-columns: repeat(4, 1fr); }
}

#zoomHud #mapRotation[hidden], #mapRotationInput[hidden] { display: none; }
#mapRotationInput {
  box-sizing: border-box; width: 64px; height: 22px; min-width: 0;
  border: 1px solid var(--accent); border-radius: 4px;
  background: var(--bg, #171922); color: #fff;
  font-family: inherit; font-size: 11px; font-variant-numeric: tabular-nums; text-align: center;
}
#mapRotationInput[aria-invalid="true"] { border-color: #ff7373; }

/* Compact voice draft panel; the placement preview remains visible on the board. */
#board.tool-voice { cursor: crosshair; }
#voiceDialog {
  position: fixed; inset: auto 18px 24px auto; margin: 0;
  width: min(360px, calc(100vw - 24px)); box-sizing: border-box;
  max-height: calc(100dvh - 32px); overflow-y: auto;
  padding: 18px; border: 1px solid var(--border, #454958); border-radius: 14px;
  background: var(--panel, #20242f); color: var(--text, #f2f4f8);
  box-shadow: 0 12px 40px #0006; font: 14px/1.45 sans-serif;
}
#voiceDialog::backdrop { background: transparent; }
#voiceDialog h2 { font-size: 18px; margin: 0 0 8px; }
#voiceDialog label { display: block; margin-top: 10px; }
#voiceDialog select, #voiceDialog textarea { display: block; width: 100%; box-sizing: border-box; margin-top: 4px; padding: 8px; background: #151923; color: #f2f4f8; border: 1px solid #667085; border-radius: 6px; font: inherit; }
#voiceDialog textarea { resize: vertical; }
#voiceDialog .voice-help { font-size: 12px; opacity: .8; margin: 8px 0; }
#voiceStatus { min-height: 2.9em; }
#voiceDialog button { padding: 8px 10px; border-radius: 6px; border: 1px solid #667085; color: #f2f4f8; background: #303849; font: inherit; cursor: pointer; }
#voiceDialog button:disabled { opacity: .45; cursor: default; }
#voiceDialog button:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; }
#voiceDevices { margin-top: 8px; }
.voice-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
#voiceDialog #voiceAdd { background: #5145a0; }
@media (max-width: 480px) { #voiceDialog { right: 12px; bottom: 12px; } }

/* Keep text sizing visible before the other drawing controls. */
#fontGroup { order: -1; }
#fontSizeInput { width: 72px; padding: 5px; color: var(--ink-0); background: var(--bg-2); border: 1px solid var(--line); border-radius: 4px; }
#voiceSize { padding: 7px; color: var(--ink-0); background: var(--bg-2); border: 1px solid var(--line); border-radius: 4px; }

/* Leave room for notches and make controls usable with fingers. */
#topbar { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
#voiceDialog { bottom: max(12px, env(safe-area-inset-bottom)); }
@media (pointer: coarse) {
  #voiceDialog button, #voiceDialog select, #voiceSize, .sidebar-heading button { min-height: 44px; }
  .swatch { width: 32px; height: 32px; }
}
@media (max-height: 480px) and (max-width: 980px) {
  #boardWelcome p, #boardWelcome .welcome-eyebrow { display: none; }
  #boardWelcome h1 { font-size: 22px; margin: 4px 0 10px; }
  .hint-bar { display: none; }
}
