/* =========================================================================
   drawXX — local whiteboard
   ========================================================================= */
:root {
  --accent: #d97706;
  --accent-soft: #fef3c7;
  --accent-text: #ffffff;
  --bg: #ffffff;
  --island: #ffffff;
  --island-border: rgba(0, 0, 0, 0.07);
  --text: #1b1b1f;
  --text-muted: #857c6e;
  --hover: #fdf6ea;
  --active: #fde9c0;
  --divider: #ece7df;
  --shadow: 0 2px 4px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.08);
  --radius: 10px;
  --danger: #e03131;
  font-size: 14px;
}
html.theme-dark {
  --accent: #fbbf24;
  --accent-soft: #4a3410;
  --accent-text: #1b1b1f;
  --bg: #121212;
  --island: #23211d;
  --island-border: rgba(255,255,255,.09);
  --text: #e8e4dc;
  --text-muted: #a09688;
  --hover: #332c22;
  --active: #4a3410;
  --divider: #3b352c;
  --shadow: 0 2px 4px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: Assistant, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
#app { position: fixed; inset: 0; }
#canvas, #canvas-ui { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#canvas { touch-action: none; }
/* the overlay carries selection UI, so it must never swallow pointer events */
#canvas-ui { pointer-events: none; z-index: 2; }

/* Dark theme inverts the scene exactly like Excalidraw, so a drawing made in
   light mode stays readable in dark mode without rewriting any element color. */
html.theme-dark #canvas,
html.theme-dark #text-editor,
html.theme-dark .swatch,
html.theme-dark .lib-item img { filter: invert(93%) hue-rotate(180deg); }
/* the export preview must show the real exported pixels, so it stays unfiltered */

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5;
      stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- layers */
.layer { position: absolute; z-index: 5; display: flex; gap: 8px; pointer-events: none; }
.layer > *, .layer .row > * { pointer-events: all; }
.top-left     { top: 12px; left: 12px; flex-direction: column; align-items: flex-start; max-height: calc(100vh - 24px); }
.top-center   { top: 12px; left: 50%; transform: translateX(-50%); flex-direction: column; align-items: center; }
.top-right    { top: 12px; right: 12px; align-items: flex-start; }
.bottom-left  { bottom: 12px; left: 12px; align-items: center; }
.bottom-right { bottom: 12px; right: 12px; }

.island {
  background: var(--island);
  border: 1px solid var(--island-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px;
}

/* --------------------------------------------------------------- buttons */
button { font: inherit; color: inherit; cursor: pointer; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: none; border-radius: var(--radius);
  background: transparent; color: var(--text);
}
.icon-btn.solid { background: var(--island); border: 1px solid var(--island-border); box-shadow: var(--shadow); }
.icon-btn.round { border-radius: 50%; font-weight: 700; }
.icon-btn.sm { width: 28px; height: 28px; font-size: 13px; }
.icon-btn:hover { background: var(--hover); }
.btn {
  border: 1px solid var(--island-border); background: var(--island); color: var(--text);
  border-radius: var(--radius); padding: 0 14px; height: 36px; box-shadow: var(--shadow);
  font-weight: 600; font-size: 13px;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { box-shadow: none; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn:hover { background: var(--hover); }
.btn.primary:hover { background: var(--accent); }
.btn.danger { color: var(--danger); }

/* --------------------------------------------------------------- toolbar */
.toolbar { display: flex; align-items: center; gap: 2px; padding: 4px 6px; }
.toolbar .sep { width: 1px; height: 24px; background: var(--divider); margin: 0 4px; }
.tool {
  position: relative; width: 36px; height: 36px; border: none; background: transparent;
  border-radius: var(--radius); display: flex; align-items: center; justify-content: center;
  color: var(--text);
}
.tool:hover { background: var(--hover); }
.tool.active { background: var(--accent); color: var(--accent-text); }
html.theme-dark .tool.active { color: #1b1b1f; }
.tool .num { position: absolute; right: 3px; bottom: 1px; font-size: 8px; opacity: .55; }
.tool.active .num { opacity: .8; }
.hint { margin-top: 8px; font-size: 12px; color: var(--text-muted); text-align: center; pointer-events: none; }
.hint kbd {
  background: var(--island); border: 1px solid var(--divider); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 5px; font-size: 11px; font-family: ui-monospace, monospace;
}

/* ------------------------------------------------------------ properties */
.panel { width: 212px; padding: 12px; max-height: calc(100vh - 150px); overflow-y: auto; }
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: var(--divider); border-radius: 3px; }
.prop { margin-bottom: 10px; }
.prop > h3 { font-size: 12px; font-weight: 400; color: var(--text-muted); margin: 0 0 4px; }
.swatches { display: flex; align-items: center; gap: 6px; }
.swatch {
  width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--island-border);
  cursor: pointer; padding: 0; background-clip: padding-box;
}
.swatch.active { outline: 1px solid var(--accent); outline-offset: 2px; }
.swatch.transparent {
  background-image: linear-gradient(45deg,#ddd 25%,transparent 25%,transparent 75%,#ddd 75%),
                    linear-gradient(45deg,#ddd 25%,#fff 25%,#fff 75%,#ddd 75%);
  background-size: 8px 8px; background-position: 0 0, 4px 4px;
}
.swatch-divider { width: 1px; height: 22px; background: var(--divider); margin: 0 2px; }
.swatch.current { width: 26px; height: 26px; border-radius: 7px; }
.btn-group { display: flex; gap: 4px; flex-wrap: wrap; }
.opt {
  width: 30px; height: 30px; border: none; border-radius: 7px; background: var(--hover);
  display: flex; align-items: center; justify-content: center; color: var(--text); font-size: 12px;
}
.opt.wide { width: auto; padding: 0 8px; }
.opt:hover { background: var(--active); }
.opt.active { background: var(--accent); color: var(--accent-text); }
html.theme-dark .opt.active { color: #1b1b1f; }
.opt svg { width: 16px; height: 16px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.panel .actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* --------------------------------------------------------------- popups */
.popup {
  background: var(--island); border: 1px solid var(--island-border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px;
  min-width: 212px; z-index: 30;
}
.menu { margin-top: 6px; max-height: calc(100vh - 80px); overflow-y: auto; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px;
  border: none; background: transparent; border-radius: 8px; font-size: 13px; text-align: left;
}
.menu-item:hover:not(:disabled) { background: var(--hover); }
.menu-item:disabled { opacity: .4; cursor: default; }
.menu-item .sc { margin-left: auto; font-size: 11px; color: var(--text-muted); font-family: ui-monospace, monospace; }
.menu-item.accent { color: var(--accent); }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--divider); margin: 6px 4px; }
.menu-label { font-size: 12px; color: var(--text-muted); padding: 6px 10px 2px; }
#context-menu { position: absolute; }

.seg { display: flex; gap: 4px; padding: 2px 10px 8px; }
.seg button {
  flex: 1; height: 30px; border: none; border-radius: 7px; background: var(--hover);
  display: flex; align-items: center; justify-content: center; color: var(--text);
}
.seg button.active { background: var(--accent); color: var(--accent-text); }
html.theme-dark .seg button.active { color: #1b1b1f; }
select {
  width: calc(100% - 20px); margin: 0 10px 8px; height: 32px; border-radius: 8px;
  border: 1px solid var(--divider); background: var(--island); color: var(--text); padding: 0 8px;
}

/* ---------------------------------------------------------------- zoom */
.zoom, .undo-redo { display: flex; align-items: center; padding: 2px; }
.zoom button, .undo-redo button {
  border: none; background: transparent; border-radius: 8px; height: 32px; min-width: 32px;
  display: flex; align-items: center; justify-content: center; color: var(--text); font-size: 12px;
}
.zoom button:hover, .undo-redo button:hover { background: var(--hover); }
.zoom #zoom-reset { min-width: 54px; font-variant-numeric: tabular-nums; }
button:disabled { opacity: .35; cursor: default; }

/* --------------------------------------------------------------- sidebar */
.sidebar {
  position: absolute; top: 12px; right: 12px; bottom: 12px; width: 302px;
  background: var(--island); border: 1px solid var(--island-border); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 20; display: flex; flex-direction: column; overflow: hidden;
}
.sidebar header { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--divider); }
.sidebar footer { padding: 8px 12px; border-top: 1px solid var(--divider); font-size: 11px; color: var(--text-muted); }
.spacer { flex: 1; }
.lib-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px; align-content: start; }
.lib-item {
  aspect-ratio: 1; border: 1px solid var(--divider); border-radius: 8px; background: var(--bg);
  display: flex; align-items: center; justify-content: center; cursor: pointer; position: relative; padding: 4px;
}
.lib-item:hover { border-color: var(--accent); }
.lib-item img, .lib-item svg.preview { max-width: 100%; max-height: 100%; width: auto; height: auto; }
.lib-item .rm {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--danger); color: #fff; border: none; font-size: 11px; display: none; line-height: 1;
}
.lib-item:hover .rm { display: block; }
.lib-empty { grid-column: 1 / -1; color: var(--text-muted); font-size: 12px; text-align: center; padding: 30px 10px; }

/* ----------------------------------------------------------------- stats */
#stats { position: absolute; right: 12px; bottom: 60px; width: 220px; font-size: 12px; z-index: 15; }
#stats table { width: 100%; border-collapse: collapse; }
#stats td { padding: 2px 0; }
#stats td:last-child { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-muted); }
#stats h3 { margin: 8px 0 4px; font-size: 11px; text-transform: uppercase; color: var(--text-muted); letter-spacing: .04em; }
#stats input {
  width: 64px; border: 1px solid var(--divider); background: var(--bg); color: var(--text);
  border-radius: 6px; padding: 2px 4px; font-size: 12px; text-align: right;
}

/* -------------------------------------------------------------- find bar */
.find-bar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; background: var(--island);
  border: 1px solid var(--island-border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px 8px; z-index: 40;
}
.find-bar input { border: none; background: transparent; color: var(--text); outline: none; width: 190px; font-size: 13px; }
.find-bar button { border: none; background: transparent; color: var(--text); border-radius: 6px; width: 26px; height: 26px; }
.find-bar button:hover { background: var(--hover); }
.find-bar .ic { width: 16px; height: 16px; color: var(--text-muted); }
.muted { color: var(--text-muted); font-size: 12px; min-width: 42px; text-align: right; }

/* ---------------------------------------------------------------- modal */
.modal-root { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.modal {
  position: relative; background: var(--island); border-radius: 14px; box-shadow: var(--shadow);
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 64px); overflow: hidden;
  display: flex; flex-direction: column;
}
.modal header { display: flex; align-items: center; padding: 16px 20px 8px; }
.modal h2 { margin: 0; font-size: 18px; flex: 1; }
#modal-body { padding: 8px 20px 20px; overflow-y: auto; }

.cmdk-input {
  width: 100%; border: none; border-bottom: 1px solid var(--divider); background: transparent;
  color: var(--text); font-size: 16px; padding: 10px 2px; outline: none; margin-bottom: 8px;
}
.cmdk-list { max-height: 50vh; overflow-y: auto; }
.cmdk-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  font-size: 13px; cursor: pointer; border: none; background: transparent; width: 100%; text-align: left; color: inherit;
}
.cmdk-item.sel { background: var(--accent); color: var(--accent-text); }
html.theme-dark .cmdk-item.sel { color: #1b1b1f; }
.cmdk-item .sc { margin-left: auto; font-size: 11px; opacity: .7; font-family: ui-monospace, monospace; }
.cmdk-group { font-size: 11px; text-transform: uppercase; color: var(--text-muted); padding: 10px 10px 4px; letter-spacing: .04em; }

.shortcut-cols { columns: 2; column-gap: 28px; }
.shortcut-cols section { break-inside: avoid; margin-bottom: 18px; }
.shortcut-cols h3 { font-size: 13px; margin: 0 0 6px; }
.shortcut-row { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 3px 0; }
.shortcut-row span { flex: 1; color: var(--text-muted); }
.shortcut-row kbd {
  background: var(--hover); border: 1px solid var(--divider); border-radius: 4px;
  padding: 2px 6px; font-size: 11px; font-family: ui-monospace, monospace;
}

.export-preview {
  border: 1px solid var(--divider); border-radius: 10px; min-height: 200px; max-height: 42vh;
  display: flex; align-items: center; justify-content: center; overflow: hidden; margin-bottom: 16px;
  background-image: linear-gradient(45deg,#f0f0f0 25%,transparent 25%,transparent 75%,#f0f0f0 75%),
                    linear-gradient(45deg,#f0f0f0 25%,#fff 25%,#fff 75%,#f0f0f0 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px;
}
.export-preview img { max-width: 100%; max-height: 40vh; object-fit: contain; }
.export-opts { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 18px; font-size: 13px; }
.export-opts label { display: flex; align-items: center; gap: 6px; }
.export-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; font-size: 13px; }
.field input[type=text], .field input[type=url] {
  height: 34px; border-radius: 8px; border: 1px solid var(--divider);
  background: var(--bg); color: var(--text); padding: 0 10px;
}

/* --------------------------------------------------------- text editor */
#text-editor {
  position: absolute; display: none; margin: 0; padding: 0; border: none; outline: none;
  background: transparent; overflow: hidden; resize: none; white-space: pre;
  word-break: normal; z-index: 10; line-height: 1.25;
}

/* ------------------------------------------------------- sponsor dock */
#sponsor-dock {
  position: absolute; right: 12px; bottom: 58px; width: 268px; z-index: 6;
  background: var(--island); border: 1px solid var(--island-border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 10px 10px;
  animation: dock-in .35s ease both;
}
@keyframes dock-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
#sponsor-dock .dock-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
#sponsor-dock .dock-label {
  font-size: .62rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); font-weight: 600;
}
#sponsor-dock #sponsor-hide {
  margin-left: auto; width: 20px; height: 20px; border: none; background: transparent;
  color: var(--text-muted); border-radius: 5px; font-size: 11px; line-height: 1;
}
#sponsor-dock #sponsor-hide:hover { background: var(--hover); color: var(--text); }
#sponsor-dock [data-sponsor-slot] { min-height: 92px; display: flex; align-items: center; font-size: .8rem; }
#sponsor-dock img { border-radius: 6px; max-width: 100%; }
#sponsor-dock .sponsor-house, #sponsor-dock .sponsor-custom {
  display: flex; gap: 10px; align-items: center; text-decoration: none; color: var(--text-muted);
  line-height: 1.45;
}
#sponsor-dock .sponsor-house { flex-direction: column; align-items: flex-start; gap: 3px; }
#sponsor-dock .sponsor-house strong, #sponsor-dock .sponsor-custom strong {
  color: var(--text); display: block; font-size: .85rem;
}
#sponsor-dock #carbonads, #sponsor-dock .ea-content {
  font: inherit !important; background: transparent !important; border: 0 !important;
}
#sponsor-dock a { color: var(--text-muted) !important; text-decoration: none; }
#sponsor-dock .carbon-poweredby, #sponsor-dock .ea-callout { font-size: .65rem !important; }
@media (max-width: 760px), (max-height: 620px) { #sponsor-dock { display: none !important; } }

/* -------------------------------------------------------------- toast */
.toast {
  position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%);
  background: var(--island); border: 1px solid var(--island-border); border-radius: 999px;
  box-shadow: var(--shadow); padding: 8px 16px; font-size: 13px; z-index: 50;
}

.hidden { display: none !important; }
.zen .top-left #properties, .zen .top-right, .zen .bottom-left .island, .zen .hint { display: none !important; }
