:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --line: #d1d5db;
  --text: #0f172a;
  --muted: #475569;
  --selection: #111827;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(250, 204, 21, 0.18), transparent 24%),
    radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.12), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: "SF Pro Text", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding: 14px;
}

.toolbar {
  position: relative;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  border-radius: 18px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.07);
}

button,
select,
input {
  font: inherit;
  font-size: 16px;
}

button {
  border: 1px solid #cbd5e1;
  background: linear-gradient(180deg, #ffffff, #f1f5f9);
  color: var(--text);
  border-radius: 10px;
  min-height: 44px;
  padding: 10px 14px;
  cursor: pointer;
}

button:hover {
  background: linear-gradient(180deg, #ffffff, #e2e8f0);
}

.toolbar-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  min-height: 44px;
}

.toolbar-field select,
.toolbar-field input[type="range"] {
  min-height: 44px;
}

.slider-field output {
  min-width: 32px;
  text-align: right;
  color: var(--text);
  font-weight: 600;
}

.status {
  margin-left: auto;
  color: var(--muted);
  font-size: 14px;
}

.canvas-wrap {
  position: relative;
  z-index: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 24px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.08);
}

#treemap-svg {
  display: block;
  width: 100%;
  height: calc(100vh - 112px);
  min-height: 640px;
  touch-action: none;
  user-select: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.96));
}

.group-title-box {
  fill: rgba(255, 255, 255, 0.94);
  stroke: #dbe4ee;
  stroke-width: 1.2;
  rx: 12;
  ry: 12;
}

.group-boundary {
  fill: rgba(255, 255, 255, 0.86);
  stroke: #cbd5e1;
  stroke-width: 1.5;
  rx: 22;
  ry: 22;
}

.treemap-block {
  stroke: #ffffff;
  stroke-width: 2;
}

.block-input,
.title-input {
  border: none;
  outline: none;
  text-align: center;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 16px;
  width: 100%;
}

.html-editor {
  position: absolute;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  overflow: hidden;
  pointer-events: none;
}

.html-editor input {
  pointer-events: auto;
}

.title-editor {
  position: absolute;
  z-index: 4;
  padding: 4px 8px;
  border: 1px solid #dbe4ee;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

.title-editor input {
  font-weight: 700;
}

.selected-outline {
  fill: none;
  stroke: var(--selection);
  stroke-width: 2;
  stroke-dasharray: 6 4;
}

.handle {
  fill: #ffffff;
  stroke: var(--selection);
  stroke-width: 1.2;
  cursor: nwse-resize;
}

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

.tiny-label {
  font-size: 10px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .toolbar {
    gap: 10px;
    padding: 12px;
    border-radius: 16px;
  }

  .status {
    width: 100%;
    margin-left: 0;
  }

  #treemap-svg {
    min-height: 520px;
    height: calc(100vh - 170px);
  }
}

@media (max-width: 640px) {
  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }

  .toolbar button,
  .toolbar .toolbar-field,
  .toolbar .status {
    width: 100%;
  }

  .toolbar-field {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .slider-field output {
    text-align: left;
  }

  .status {
    grid-column: 1 / -1;
    font-size: 13px;
  }

  #treemap-svg {
    min-height: 480px;
    height: calc(100vh - 260px);
  }
}
