:root {
  --bg: #f6f1e8;
  --bg-accent: #efe7d8;
  --ink: #1b1916;
  --panel: #221e1a;
  --panel-2: #2d2823;
  --panel-3: #3a342d;
  --accent: #f15d3d;
  --accent-2: #3bbf9f;
  --muted: #9e9488;
  --line: #3d362f;
  --canvas: #ffffff;
  --canvas-border: #cec4b5;
  --shadow: 0 30px 80px rgba(20, 16, 12, 0.25);
  --mono: "IBM Plex Mono", monospace;
  --sans: "IBM Plex Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei",
    "Heiti SC", sans-serif;
  --serif: "Fraunces", "Noto Serif SC", "Songti SC", "SimSun", serif;
  --toolbar-collapsed: 76px;
  --toolbar-expanded: 176px;
  --ruler-bg: #332a22;
  --ruler-line: rgba(241, 93, 61, 0.55);
  --ruler-line-strong: rgba(241, 93, 61, 0.9);
  --ruler-text: rgba(255, 248, 235, 0.9);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: radial-gradient(
      circle at 10% 10%,
      rgba(241, 93, 61, 0.08),
      transparent 40%
    ),
    radial-gradient(
      circle at 90% 20%,
      rgba(59, 191, 159, 0.12),
      transparent 45%
    ),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-accent) 100%);
  min-height: 100vh;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--panel);
  color: #fdf6ea;
  border-bottom: 1px solid #1a1713;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: conic-gradient(
    from 120deg,
    var(--accent),
    #f9b55a,
    var(--accent-2),
    var(--accent)
  );
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.brand-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.5px;
}

.brand-subtitle {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  color: rgba(255, 255, 255, 0.6);
}

.menu {
  display: flex;
  gap: 10px;
  align-items: center;
}

.menu-group {
  position: relative;
}

.menu-trigger {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #f6f0e6;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
}

.menu-trigger:hover,
.menu-group.open .menu-trigger {
  border-color: rgba(255, 255, 255, 0.4);
  color: #ffffff;
}

.menu-dropdown {
  position: absolute;
  top: 110%;
  left: 0;
  min-width: 180px;
  background: #1b1815;
  color: #f5efe5;
  border: 1px solid #2e2924;
  border-radius: 14px;
  padding: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  display: none;
  z-index: 50;
}

.menu-group.open .menu-dropdown {
  display: grid;
  gap: 6px;
}

.menu-dropdown button {
  width: 100%;
  background: transparent;
  border: none;
  color: inherit;
  text-align: left;
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.menu-dropdown button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.menu-sep {
  height: 1px;
  background: #322c26;
  margin: 4px 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ghost-btn,
.primary-btn,
.tool {
  font-family: var(--sans);
}

.ghost-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #f6f0e6;
  padding: 6px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ghost-btn:hover {
  border-color: rgba(255, 255, 255, 0.5);
  color: #ffffff;
}

.zoom-readout {
  background: rgba(255, 255, 255, 0.08);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.4px;
}

.workspace {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 320px;
  flex: 1;
}

.toolbar {
  background: var(--panel-2);
  border-right: 1px solid #27211c;
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: var(--toolbar-collapsed);
  transition: width 0.2s ease;
  overflow-x: hidden;
}

.toolbar.is-expanded {
  width: var(--toolbar-expanded);
}

.toolbar-header {
  display: flex;
  justify-content: center;
}

.toolbar-toggle {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.75);
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 11px;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toolbar-toggle:hover {
  color: #fff6ec;
  border-color: rgba(255, 255, 255, 0.35);
}

.toolbar-toggle-icon {
  position: relative;
  width: 10px;
  height: 10px;
  display: inline-block;
}

.toolbar-toggle-icon::before {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  top: 1px;
  left: 1px;
}

.toolbar.is-expanded .toolbar-toggle-icon::before {
  transform: rotate(135deg);
}

.toolbar-toggle-label {
  white-space: nowrap;
}

.toolbar .label-expanded {
  display: none;
}

.toolbar.is-expanded .label-expanded {
  display: inline;
}

.toolbar.is-expanded .label-collapsed {
  display: none;
}

.toolbar-group {
  display: grid;
  gap: 8px;
}

.tool-group-title {
  font-size: 10px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
  display: none;
}

.tool {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  color: rgba(255, 255, 255, 0.8);
  padding: 10px 6px;
  border-radius: 14px;
  font-size: 11px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.tool:hover,
.tool.active {
  background: rgba(241, 93, 61, 0.2);
  border-color: rgba(241, 93, 61, 0.6);
  color: #fff4ed;
}

.tool-label {
  font-size: 10px;
  letter-spacing: 0.4px;
  text-transform: none;
  font-weight: 600;
}

.tool-icon {
  position: relative;
  width: 22px;
  height: 22px;
  color: currentColor;
  display: none;
}

.tool-icon::before,
.tool-icon::after {
  content: "";
  position: absolute;
  box-sizing: border-box;
}

.icon-select::before {
  width: 0;
  height: 0;
  border-left: 8px solid currentColor;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  transform: rotate(-20deg);
  top: 4px;
  left: 6px;
}

.icon-pan::before {
  left: 3px;
  right: 3px;
  top: 50%;
  height: 2px;
  background: currentColor;
  transform: translateY(-50%);
}

.icon-pan::after {
  top: 3px;
  bottom: 3px;
  left: 50%;
  width: 2px;
  background: currentColor;
  transform: translateX(-50%);
}

.icon-zoom::before {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-radius: 50%;
  top: 3px;
  left: 3px;
}

.icon-zoom::after {
  width: 7px;
  height: 2px;
  background: currentColor;
  right: 3px;
  bottom: 4px;
  transform: rotate(45deg);
}

.icon-rect::before {
  inset: 5px 3px;
  border: 2px solid currentColor;
  border-radius: 3px;
}

.icon-square::before {
  inset: 4px;
  border: 2px solid currentColor;
  border-radius: 3px;
}

.icon-circle::before {
  inset: 4px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.icon-ellipse::before {
  inset: 5px 3px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.icon-line::before {
  left: 3px;
  right: 3px;
  top: 50%;
  height: 2px;
  background: currentColor;
  transform: translateY(-50%);
}

.icon-arrow::before {
  left: 3px;
  right: 7px;
  top: 50%;
  height: 2px;
  background: currentColor;
  transform: translateY(-50%);
}

.icon-arrow::after {
  right: 2px;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 6px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: translateY(-50%);
}

.icon-path::before {
  inset: 4px;
  border: 2px dashed currentColor;
  border-radius: 6px;
}

.icon-text::before {
  content: "T";
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  top: 2px;
  left: 7px;
}

.icon-image::before {
  inset: 4px;
  border: 2px solid currentColor;
  border-radius: 3px;
}

.icon-image::after {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  top: 6px;
  left: 6px;
}

.icon-nodes::before {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  top: 6px;
  left: 6px;
  box-shadow: 8px 0 0 currentColor, 0 8px 0 currentColor, 8px 8px 0 currentColor;
}

.canvas-wrap {
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 16px;
}

.canvas-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.doc-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 22px;
}

.doc-status {
  font-size: 12px;
  color: var(--muted);
}

.canvas-meta-actions {
  display: flex;
  gap: 8px;
}

.canvas-stage {
  position: relative;
  flex: 1;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 24px;
  padding: 20px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}

.canvas-container {
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.02),
      rgba(0, 0, 0, 0.02) 1px,
      transparent 1px,
      transparent 24px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(0, 0, 0, 0.02),
      rgba(0, 0, 0, 0.02) 1px,
      transparent 1px,
      transparent 24px
    );
  border-radius: 18px;
  padding: 18px;
  overflow: hidden;
  position: relative;
}

#svg-canvas {
  width: 100%;
  height: 100%;
  background: var(--canvas);
  border-radius: 14px;
  border: 1px solid var(--canvas-border);
  box-shadow: var(--shadow);
}

#svg-canvas.pan-mode {
  cursor: grab;
}

#svg-canvas.pan-mode:active {
  cursor: grabbing;
}

#sve-bg {
  fill: var(--canvas);
}

.ruler {
  position: absolute;
  background: var(--ruler-bg);
  color: #fff;
  z-index: 2;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

.ruler.hidden {
  display: none;
}

.ruler-x {
  top: 0;
  left: 0;
  height: 28px;
  border-radius: 10px;
}

.ruler-y {
  top: 0;
  left: 0;
  width: 28px;
  border-radius: 10px;
}

.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}

.status-left,
.status-right {
  display: flex;
  gap: 12px;
  align-items: center;
}

.properties {
  background: var(--panel-2);
  border-left: 1px solid #27211c;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  color: #f7f0e6;
}

.panel-section {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid #2b251f;
  border-radius: 16px;
  padding: 14px;
}

.panel-title {
  font-size: 12px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 10px;
}

.panel-body {
  display: grid;
  gap: 10px;
}

.field {
  display: grid;
  gap: 6px;
}

.color-inputs {
  display: grid;
  grid-template-columns: 1fr 44px auto;
  gap: 8px;
  align-items: center;
}

.color-inputs input[type="color"] {
  padding: 0;
  height: 36px;
  width: 44px;
  border-radius: 10px;
  border: 1px solid #3a332d;
  background: #1a1714;
  cursor: pointer;
}

.chip-btn {
  border: 1px solid #3a332d;
  background: #1a1714;
  color: rgba(247, 240, 230, 0.75);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.chip-btn.active,
.chip-btn[aria-pressed="true"] {
  background: rgba(241, 93, 61, 0.2);
  border-color: rgba(241, 93, 61, 0.7);
  color: #fff4ed;
}

.opacity-controls {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
  align-items: center;
}

.opacity-input {
  position: relative;
}

.opacity-input input {
  padding-right: 22px;
}

.opacity-input .unit {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: rgba(247, 240, 230, 0.6);
  pointer-events: none;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: #2a2320;
  border: 1px solid #3a332d;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #1b0f0a;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #1b0f0a;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: rgba(255, 255, 255, 0.5);
}

input,
select,
textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #3a332d;
  background: #1a1714;
  color: #f7f0e6;
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--mono);
}

input:disabled {
  opacity: 0.6;
}

.panel-inline {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-note {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.45);
  line-height: 1.4;
}

.primary-btn {
  background: var(--accent);
  color: #1b0f0a;
  border: none;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
}

.modal::backdrop {
  background: rgba(11, 9, 7, 0.65);
}

.modal-card {
  background: #1a1714;
  border-radius: 18px;
  padding: 20px;
  color: #f7f0e6;
  border: 1px solid #322c26;
  min-width: 320px;
}

.modal-wide .modal-card {
  min-width: min(820px, 90vw);
}

.modal-title {
  font-family: var(--serif);
  font-size: 20px;
  margin-bottom: 14px;
}

.modal-body {
  display: grid;
  gap: 12px;
}

.modal-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: rgba(247, 240, 230, 0.8);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(247, 240, 230, 0.72);
}

.check-row input {
  accent-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

#source-editor {
  min-height: 320px;
  resize: vertical;
  font-family: var(--mono);
}

.source-error {
  color: #ffb4a7;
  font-size: 12px;
  min-height: 18px;
}

.shortcut-grid {
  display: grid;
  gap: 8px;
}

.shortcut-grid div {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #2b251f;
  padding-bottom: 6px;
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #1a1714;
  color: #f7f0e6;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid #2f2822;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 72px minmax(0, 1fr) 260px;
  }
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    border-right: none;
    border-bottom: 1px solid #27211c;
  }

  .properties {
    border-left: none;
    border-top: 1px solid #27211c;
  }
}

#svg-canvas .selection-box {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 6 4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

#svg-canvas .selection-handle {
  fill: var(--accent);
  stroke: #1b0f0a;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}

#svg-canvas .rotation-handle {
  fill: var(--accent-2);
  stroke-width: 1.1;
}

#svg-canvas .rotation-arrow {
  fill: none;
  stroke: var(--accent-2);
  stroke-width: 1.1;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  opacity: 0.9;
}

#svg-canvas .rotation-arrowhead {
  fill: var(--accent-2);
  stroke: none;
  pointer-events: none;
}

#svg-canvas .guide-line {
  stroke: rgba(59, 191, 159, 0.8);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  vector-effect: non-scaling-stroke;
}

#svg-canvas .node-point {
  fill: #f6f0e6;
  stroke: #1b0f0a;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}

#svg-canvas .node-point.active {
  fill: var(--accent-2);
}
.toolbar.is-expanded .tool-group-title {
  display: block;
}

.toolbar.is-expanded .tool {
  flex-direction: row;
  justify-content: flex-start;
  gap: 10px;
  text-align: left;
  padding: 10px 12px;
}

.toolbar.is-expanded .tool-label {
  font-size: 11px;
}

.toolbar.is-expanded .tool-icon {
  display: block;
}
