/* style.css */
:root {
  color-scheme: dark;
  --bg: #11131b;
  --surface: #1a1d29;
  --surface-raised: #232736;
  --surface-hover: #2b3041;
  --canvas: #151822;
  --canvas-export: #151822;
  --text: #f4f6fb;
  --muted: #9aa3b5;
  --faint: #626b7d;
  --border: rgba(224, 231, 255, .11);
  --accent: #7c8cff;
  --accent-soft: rgba(124, 140, 255, .18);
  --danger: #fb7185;
  --shadow: 0 18px 50px rgba(0, 0, 0, .3);
  --grid: rgba(196, 205, 233, .15);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #eef0f7;
    --surface: #ffffff;
    --surface-raised: #f7f8fc;
    --surface-hover: #eceffa;
    --canvas: #f8f9fd;
    --canvas-export: #f8f9fd;
    --text: #202432;
    --muted: #687186;
    --faint: #8b93a4;
    --border: rgba(40, 48, 70, .12);
    --accent: #5968e8;
    --accent-soft: rgba(89, 104, 232, .13);
    --grid: rgba(61, 75, 113, .14);
    --shadow: 0 18px 44px rgba(57, 67, 102, .13);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef0f7;
  --surface: #ffffff;
  --surface-raised: #f7f8fc;
  --surface-hover: #eceffa;
  --canvas: #f8f9fd;
  --canvas-export: #f8f9fd;
  --text: #202432;
  --muted: #687186;
  --faint: #8b93a4;
  --border: rgba(40, 48, 70, .12);
  --accent: #5968e8;
  --accent-soft: rgba(89, 104, 232, .13);
  --grid: rgba(61, 75, 113, .14);
  --shadow: 0 18px 44px rgba(57, 67, 102, .13);
}

* { box-sizing: border-box; }

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

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

.app-shell {
  height: 100%;
  min-height: 480px;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 85% -15%, rgba(97, 110, 255, .13), transparent 30rem),
    var(--bg);
}

.topbar {
  min-height: 68px;
  height: 68px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  position: relative;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 11px;
  overflow: hidden;
  background: linear-gradient(135deg, #8694ff, #b573ff);
  box-shadow: 0 6px 18px rgba(108, 102, 255, .3);
}

.brand-mark span {
  position: absolute;
  width: 17px;
  height: 17px;
  border: 2px solid rgba(255,255,255,.92);
  border-radius: 4px;
  transform: rotate(28deg);
}
.brand-mark span:nth-child(1) { left: 8px; top: 1px; }
.brand-mark span:nth-child(2) { left: 3px; top: 14px; }
.brand-mark span:nth-child(3) { right: 2px; bottom: 1px; }

.board-title {
  width: min(230px, 34vw);
  display: block;
  margin: 0;
  padding: 1px 3px;
  border: 1px solid transparent;
  border-radius: 5px;
  outline: none;
  color: var(--text);
  background: transparent;
  font-weight: 720;
  font-size: 15px;
  letter-spacing: -.01em;
}
.board-title:hover, .board-title:focus {
  border-color: var(--border);
  background: var(--surface-hover);
}

.save-status {
  margin: 1px 3px 0;
  color: var(--muted);
  font-size: 11px;
}

.top-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-button, .more-button, .zoom-value {
  display: grid;
  place-items: center;
  min-width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
}
.icon-button:hover, .more-button:hover, .zoom-value:hover {
  background: var(--surface-hover);
}
.icon-button:disabled {
  cursor: default;
  opacity: .33;
}
.icon-button svg, .more-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}
.more-button svg circle { fill: currentColor; stroke: none; }
.zoom-value {
  min-width: 49px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.top-divider {
  width: 1px;
  height: 24px;
  margin: 0 5px;
  background: var(--border);
}

.more-menu {
  position: absolute;
  z-index: 20;
  top: 47px;
  right: 0;
  width: 172px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-raised);
  box-shadow: var(--shadow);
}
.more-menu button {
  width: 100%;
  min-height: 40px;
  padding: 0 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
}
.more-menu button:hover { background: var(--surface-hover); }
.more-menu .danger { color: var(--danger); }

.workspace {
  min-height: 0;
  flex: 1;
  position: relative;
  display: flex;
}

.toolbar {
  z-index: 4;
  width: 64px;
  display: flex;
  flex: 0 0 64px;
  align-items: center;
  flex-direction: column;
  gap: 4px;
  padding: 14px 10px;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

.tool {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.tool:hover { color: var(--text); background: var(--surface-hover); }
.tool.active {
  color: #fff;
  border-color: rgba(151, 163, 255, .32);
  background: var(--accent);
  box-shadow: 0 5px 12px rgba(75, 83, 200, .25);
}
.tool svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}
.tool:first-child svg { fill: currentColor; stroke: none; }
.tool kbd {
  position: absolute;
  right: -4px;
  bottom: -3px;
  display: none;
  min-width: 13px;
  padding: 1px 3px;
  border-radius: 3px;
  color: var(--faint);
  background: var(--surface);
  font-size: 8px;
  line-height: 1.15;
  font-family: inherit;
}
.tool:hover kbd { display: block; }
.tool-divider {
  width: 29px;
  height: 1px;
  margin: 4px 0;
  background: var(--border);
}

.board-area {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: var(--canvas);
}

#board {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
}
#board.tool-select { cursor: default; }
#board.tool-hand, #board.panning { cursor: grab; }
#board.panning { cursor: grabbing; }

.grid-dot { fill: var(--grid); }
.arrow-head { fill: context-stroke; }
.canvas-item { cursor: move; }
.tool-select .canvas-item { cursor: move; }
.tool-text .canvas-item, .tool-sticky .canvas-item { cursor: default; }

.rough-line {
  filter: url("#none");
  stroke-dasharray: none;
}
.rough-text { letter-spacing: .2px; }

.selection-box {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 5;
  vector-effect: non-scaling-stroke;
}
.resize-handle {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 2;
  cursor: nwse-resize;
  vector-effect: non-scaling-stroke;
}

.selection-menu {
  position: fixed;
  z-index: 8;
  display: flex;
  gap: 2px;
  padding: 4px;
  transform: translate(0, -100%);
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-raised);
  box-shadow: var(--shadow);
}
.selection-menu button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.selection-menu button:hover { background: var(--surface-hover); }
.selection-menu svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hint {
  position: absolute;
  z-index: 2;
  bottom: 17px;
  left: 18px;
  max-width: calc(100% - 36px);
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  pointer-events: none;
  font-size: 12px;
  backdrop-filter: blur(8px);
}

.properties {
  z-index: 3;
  width: 220px;
  flex: 0 0 220px;
  padding: 18px 16px;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  transition: width .2s ease, padding .2s ease;
}
.properties.collapsed {
  width: 0;
  flex-basis: 0;
  overflow: visible;
  padding: 0;
}
.properties.collapsed > :not(.panel-heading) { display: none; }
.properties.collapsed .panel-heading {
  position: absolute;
  top: 84px;
  right: 0;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 9px 0 0 9px;
  background: var(--surface);
}
.properties.collapsed .panel-heading > span { display: none; }
.properties.collapsed .collapse-button svg { transform: rotate(180deg); }

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  color: var(--text);
  font-size: 13px;
  font-weight: 760;
}
.collapse-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.collapse-button:hover { background: var(--surface-hover); }
.collapse-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.property-label {
  display: block;
  margin: 18px 0 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 730;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
}
.swatch {
  position: relative;
  width: 25px;
  height: 25px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.16);
  cursor: pointer;
}
.swatch:hover { transform: scale(1.1); }
.swatch.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.none-swatch {
  overflow: hidden;
  border-color: var(--border);
  background:
    linear-gradient(135deg, transparent 46%, #fb7185 47%, #fb7185 53%, transparent 54%),
    var(--surface-raised);
}
.none-swatch span { display: none; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-raised);
}
.segmented button {
  min-height: 33px;
  padding: 0 3px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
}
.segmented button:hover { color: var(--text); }
.segmented button.selected {
  color: var(--text);
  background: var(--accent-soft);
}

.shortcuts {
  margin-top: 30px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}
.shortcuts strong {
  display: block;
  margin-bottom: 12px;
  color: var(--text);
  font-size: 11px;
}
.shortcuts div {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}
kbd {
  display: inline-grid;
  min-width: 25px;
  min-height: 20px;
  place-items: center;
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-bottom-color: color-mix(in srgb, var(--border), var(--text) 20%);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface-raised);
  font-family: inherit;
  font-size: 10px;
}

.mobile-style-button {
  display: none;
}

.toast {
  position: fixed;
  z-index: 40;
  bottom: 22px;
  left: 50%;
  padding: 10px 15px;
  transform: translate(-50%, 20px);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  background: var(--surface-raised);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  font-size: 13px;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 850px) {
  .properties {
    position: absolute;
    z-index: 12;
    right: 12px;
    bottom: 12px;
    width: min(305px, calc(100vw - 24px));
    max-height: min(520px, calc(100vh - 130px));
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    transform: translateY(calc(100% + 30px));
    opacity: 0;
    pointer-events: none;
    transition: transform .22s ease, opacity .22s ease;
  }
  .properties.mobile-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  .properties.collapsed {
    width: min(305px, calc(100vw - 24px));
    padding: 18px 16px;
  }
  .properties.collapsed > :not(.panel-heading) { display: block; }
  .properties.collapsed .panel-heading {
    position: static;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }
  .properties.collapsed .panel-heading > span { display: block; }
  .mobile-style-button {
    position: fixed;
    z-index: 10;
    right: 14px;
    bottom: 14px;
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    background: var(--surface-raised);
    box-shadow: var(--shadow);
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
  }
  .mobile-style-button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-width: 1.8;
  }
  .hint { bottom: 18px; }
}

@media (max-width: 560px) {
  .topbar {
    height: 60px;
    min-height: 60px;
    padding: 8px 10px;
  }
  .brand-mark { width: 32px; height: 32px; flex-basis: 32px; }
  .brand-mark span { transform: scale(.86) rotate(28deg); transform-origin: center; }
  .board-title { width: min(150px, 37vw); font-size: 14px; }
  .save-status { font-size: 10px; }
  .top-actions { gap: 0; }
  .top-actions .top-divider,
  #zoomOutBtn,
  #zoomInBtn,
  .zoom-value {
    display: none;
  }
  .icon-button, .more-button { min-width: 40px; }
  .toolbar {
    position: absolute;
    z-index: 7;
    bottom: 11px;
    left: 50%;
    width: auto;
    max-width: calc(100vw - 20px);
    height: 58px;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 7px;
    transform: translateX(-50%);
    border: 1px solid var(--border);
    border-radius: 14px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
    scrollbar-width: none;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .tool {
    flex: 0 0 41px;
    width: 41px;
    height: 41px;
  }
  .tool-divider {
    flex: 0 0 1px;
    width: 1px;
    height: 27px;
    margin: 0 3px;
  }
  .tool kbd { display: none !important; }
  .hint {
    bottom: 77px;
    left: 10px;
    max-width: calc(100% - 20px);
    font-size: 11px;
  }
  .mobile-style-button {
    right: 12px;
    bottom: 77px;
    min-height: 40px;
    padding: 0 11px;
  }
  .selection-menu { transform: translate(-40%, -110%); }
}

@media (max-height: 520px) and (min-width: 561px) {
  .toolbar { overflow-y: auto; padding-bottom: 9px; }
  .tool { flex-basis: 36px; height: 36px; }
  .topbar { min-height: 57px; height: 57px; }
}
