:root {
  --bg: #f4f5ef;
  --surface: #fffdf8;
  --ink: #1f2a1f;
  --muted: #5f6a61;
  --border: #d4d0c4;
  --accent: #2f5f4f;
  --danger: #9e2a2b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 0% 0%, #f9e7c8 0, transparent 45%),
    radial-gradient(circle at 100% 0%, #d8f0e4 0, transparent 45%),
    var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 253, 248, 0.93);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
}

.status {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.header-actions {
  display: flex;
  gap: 0.45rem;
}

.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 250px;
  gap: 0.75rem;
  padding: 0.75rem;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface);
  padding: 0.75rem;
  box-shadow: 0 6px 16px rgba(47, 95, 79, 0.08);
}

.right-panel {
  max-height: calc(100vh - 90px);
  overflow: auto;
}

.panel h2 {
  margin: 0 0 0.45rem;
  font-size: 0.92rem;
}

.style-section {
  border-top: 1px solid var(--border);
  padding-top: 0.45rem;
  margin-top: 0.45rem;
}

.style-section:first-of-type {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.style-section h3 {
  margin: 0 0 0.4rem;
  font-size: 0.84rem;
  color: var(--ink);
}

.style-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
}

.style-option input[type="radio"] {
  width: auto;
  margin: 0;
}

.style-row {
  display: grid;
  grid-template-columns: auto 1fr 3.7rem;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
}

.style-row-label {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.style-range {
  width: 100%;
}

.style-percent {
  width: 100%;
}

.style-percent::-webkit-outer-spin-button,
.style-percent::-webkit-inner-spin-button {
  margin: 0;
}

.tool-grid {
  display: grid;
  gap: 0.2rem;
  grid-template-columns: repeat(4, 1.8rem);
  justify-content: start;
  margin-bottom: 0.8rem;
  max-height: calc(100vh - 260px);
  overflow: auto;
}

.tool-btn {
  aspect-ratio: 1 / 1;
  width: 1.8rem;
  min-width: 1.8rem;
  min-height: 1.8rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.92rem;
  line-height: 1;
  position: relative;
  z-index: 0;
  border-radius: 0.42rem;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Segoe UI", sans-serif;
}

.tool-btn:hover,
.tool-btn:focus-visible {
  z-index: 6;
}

.tool-btn:hover::after,
.tool-btn:focus-visible::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: -1.75rem;
  transform: translateX(-50%);
  white-space: nowrap;
  background: #1f2a1f;
  color: #fff;
  border-radius: 0.35rem;
  padding: 0.16rem 0.3rem;
  font-size: 0.68rem;
  pointer-events: none;
  z-index: 20;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.tool-stack {
  display: grid;
  gap: 0.2rem;
  grid-template-columns: repeat(3, 1.8rem);
  justify-content: start;
}

.action-btn {
  aspect-ratio: 1 / 1;
  width: 1.8rem;
  min-width: 1.8rem;
  min-height: 1.8rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  line-height: 1;
  border-radius: 0.42rem;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Segoe UI", sans-serif;
}

.canvas-panel {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: #fcfcf8;
  box-shadow: 0 6px 16px rgba(47, 95, 79, 0.08);
  min-height: 640px;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  height: calc(100vh - 130px);
  min-height: 620px;
  overflow: auto;
  border-radius: 0.75rem;
}

.shape-text-editor {
  position: absolute;
  z-index: 20;
  border: 1.5px solid #2ea8ef;
  border-radius: 0.4rem;
  background: rgba(255, 255, 255, 0.96);
  color: #1f2a1f;
  padding: 0.4rem 0.5rem;
  resize: both;
  outline: none;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  line-height: 1.2;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

#diagram-svg {
  width: 1400px;
  height: 900px;
  display: block;
  cursor: crosshair;
}

#diagram-svg.select-mode {
  cursor: default;
}

label {
  display: grid;
  gap: 0.2rem;
  color: var(--muted);
  font-size: 0.84rem;
  margin-bottom: 0.45rem;
}

.align-label {
  margin-bottom: 0.2rem;
}

.align-control {
  display: grid;
  grid-template-columns: repeat(3, 1.8rem);
  gap: 0.2rem;
  margin-bottom: 0.45rem;
}

.align-btn {
  aspect-ratio: 1 / 1;
  width: 1.8rem;
  min-width: 1.8rem;
  min-height: 1.8rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.42rem;
  line-height: 1;
}

.align-icon {
  display: block;
  height: 0.5rem;
  border-radius: 0.1rem;
  background: repeating-linear-gradient(
    to bottom,
    currentColor,
    currentColor 1px,
    transparent 1px,
    transparent 3px
  );
}

.align-btn[data-align="start"] .align-icon {
  width: 0.9rem;
  margin-right: auto;
}

.align-btn[data-align="middle"] .align-icon {
  width: 0.72rem;
  margin: 0 auto;
}

.align-btn[data-align="end"] .align-icon {
  width: 0.9rem;
  margin-left: auto;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.42rem;
  padding: 0.42rem;
  background: #fff;
  color: var(--ink);
}

button {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: #fff;
  color: var(--ink);
  padding: 0.4rem 0.62rem;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

button.primary {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

button.danger {
  border-color: var(--danger);
  color: var(--danger);
}

button.active {
  border-color: var(--accent);
  background: rgba(47, 95, 79, 0.1);
  color: var(--accent);
  font-weight: 600;
}

.select-mode .shape-group {
  cursor: move;
}

.selection-box {
  fill: transparent;
  stroke: #2f5f4f;
  stroke-width: 1.6;
  stroke-dasharray: 8 5;
  pointer-events: none;
}

.rotate-stem {
  stroke: #2f5f4f;
  stroke-width: 1.2;
  pointer-events: none;
}

.marquee-box {
  fill: rgba(46, 168, 239, 0.12);
  stroke: #2ea8ef;
  stroke-width: 1.2;
  stroke-dasharray: 6 4;
  pointer-events: none;
}

.resize-handle {
  fill: #2ea8ef;
  stroke: #ffffff;
  stroke-width: 1.4;
  cursor: pointer;
}

.resize-handle.n,
.resize-handle.s {
  cursor: ns-resize;
}

.resize-handle.e,
.resize-handle.w {
  cursor: ew-resize;
}

.resize-handle.ne,
.resize-handle.sw {
  cursor: nesw-resize;
}

.resize-handle.nw,
.resize-handle.se {
  cursor: nwse-resize;
}

.resize-handle.line-start,
.resize-handle.line-end {
  cursor: move;
}

.resize-handle.rotate {
  fill: #f39c12;
  cursor: grab;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .canvas-wrap {
    height: 64vh;
    min-height: 420px;
  }
}
