* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: #0f172a;
  background: linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
}
.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  gap: 10px;
  padding: 12px;
}
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  backdrop-filter: blur(4px);
}
.toolbar button {
  border: 1px solid #94a3b8;
  border-radius: 8px;
  padding: 6px 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
  color: #0f172a;
  font-weight: 600;
  cursor: pointer;
  transition: transform 90ms ease, box-shadow 120ms ease, border-color 120ms ease;
}
.toolbar button:hover {
  border-color: #64748b;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}
.toolbar button:active { transform: translateY(1px); }
.toolbar code {
  background: #e2e8f0;
  border-radius: 6px;
  padding: 1px 5px;
}
.toolbar-spacer { flex: 1 1 auto; }
.workspace {
  position: relative;
  border: 1px solid #94a3b8;
  border-radius: 14px;
  min-height: 420px;
  padding: 8px;
  overflow: hidden;
  background: #f8fafc;
  box-shadow: inset 0 1px 0 #fff;
}
/* During preview: current layout stays solid; preview overlay is transparent + distinct tone */
.node {
  position: relative;
  min-width: var(--min-box-width-px, 70px);
  min-height: var(--min-box-height-px, 70px);
}
.container { display: flex; width: 100%; height: 100%; gap: 6px; }
.container.column { flex-direction: row; }
.container.row { flex-direction: column; }
.child { position: relative; min-width: 40px; min-height: 40px; display: flex; }
.panel {
  width: 100%;
  height: 100%;
  border: 1px solid #94a3b8;
  border-radius: 12px;
  overflow: hidden;
  background: #ffffff;
  display: grid;
  grid-template-rows: auto 1fr auto;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}
.panel.drop-panel-enter {
  animation: panel-drop-enter 130ms cubic-bezier(0.16, 0.8, 0.24, 1);
}
@keyframes panel-drop-enter {
  from {
    opacity: 0.5;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
.workspace.resizing-layout,
.workspace.resizing-layout * {
  cursor: default !important;
}
.workspace[data-gap-resize-axis="column"] {
  cursor: ew-resize;
}
.workspace[data-gap-resize-axis="row"] {
  cursor: ns-resize;
}
.panel.active-panel { outline: 2px solid #1d4ed8; outline-offset: -2px; }
.resize-handle {
  position: absolute;
  border: 0;
  padding: 0;
  background: transparent;
  opacity: 0;
  transition: opacity 100ms ease;
  z-index: 3;
}
.resize-handle::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(100, 116, 139, 0.95);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  width: 12px;
  height: 12px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.workspace[data-resize-affordance="cursor-only"] .resize-handle::after {
  display: none;
}
.panel .resize-handle {
  pointer-events: none;
}
.resize-top-left {
  top: 0;
  left: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize !important;
}
.resize-top-right {
  top: 0;
  right: 0;
  width: 16px;
  height: 16px;
  cursor: nesw-resize !important;
}
.resize-bottom-left {
  bottom: 0;
  left: 0;
  width: 16px;
  height: 16px;
  cursor: nesw-resize !important;
}
.resize-bottom-right {
  bottom: 0;
  right: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize !important;
}
.resize-top {
  top: 0;
  left: 16px;
  right: 16px;
  height: 8px;
  cursor: ns-resize !important;
}
.resize-right {
  top: 16px;
  right: 0;
  bottom: 16px;
  width: 8px;
  cursor: ew-resize !important;
}
.resize-bottom {
  bottom: 0;
  left: 16px;
  right: 16px;
  height: 8px;
  cursor: ns-resize !important;
}
.resize-left {
  top: 16px;
  left: 0;
  bottom: 16px;
  width: 8px;
  cursor: ew-resize !important;
}
.panel.edge-top .resize-top,
.panel.edge-right .resize-right,
.panel.edge-bottom .resize-bottom,
.panel.edge-left .resize-left,
.panel.edge-top.edge-left .resize-top-left,
.panel.edge-top.edge-right .resize-top-right,
.panel.edge-bottom.edge-left .resize-bottom-left,
.panel.edge-bottom.edge-right .resize-bottom-right {
  opacity: 1 !important;
  pointer-events: auto;
}
.tabs {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid #e2e8f0;
  min-height: 44px;
  align-items: center;
  overflow: auto;
  background: #f8fafc;
}
.tab {
  border: 1px solid #94a3b8;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: grab;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
}
.tab:active { cursor: grabbing; }
.tab-label { pointer-events: none; }
.tab-close {
  border: 1px solid #94a3b8;
  border-radius: 999px;
  width: 16px;
  height: 16px;
  padding: 0;
  line-height: 14px;
  text-align: center;
  font-size: 11px;
  cursor: pointer;
  flex: 0 0 auto;
  background: #f1f5f9;
}
.panel-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
  padding: 0;
  overflow: hidden;
  container-type: size;
}
.panel-number {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2.1rem, 9vw, 8rem);
  font-weight: 700;
  line-height: 1;
  color: #64748b;
  opacity: 0.72;
  user-select: none;
}
@supports (container-type: size) {
  .panel-number {
    font-size: min(76cqw, 76cqh);
  }
}
.panel-meta {
  padding: 6px 8px;
  border-top: 1px solid #e2e8f0;
  font-size: 12px;
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.workspace-preview {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 65;
  opacity: 0;
  transition: none;
}
.workspace-preview.active {
  opacity: 1;
}
.workspace-preview.combined-tone {
  opacity: 1;
}
/* Outline-only preview: dashed borders show where the new layout will go */
.workspace-preview.active .panel,
.workspace-preview.combined-tone .panel {
  background: transparent !important;
  border: 2px dashed #22c55e;
  box-shadow: none;
}
.workspace-preview.active .tabs,
.workspace-preview.combined-tone .tabs {
  background: transparent !important;
  border-bottom-color: rgba(34, 197, 94, 0.5);
}
.workspace-preview.active .tab,
.workspace-preview.combined-tone .tab {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.6);
  color: #16a34a;
}
.workspace-preview.active .panel-meta,
.workspace-preview.combined-tone .panel-meta {
  background: transparent !important;
  border-top-color: rgba(34, 197, 94, 0.4);
  color: #16a34a;
}
.workspace-preview.active .panel-number,
.workspace-preview.combined-tone .panel-number {
  color: rgba(34, 197, 94, 0.9);
  font-weight: 600;
}
.workspace-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 70; transition: opacity 120ms linear; }
.workspace-overlay.faded { opacity: 0.3; }
.workspace-overlay .zone {
  position: absolute;
  transition: opacity 80ms linear, filter 80ms linear, box-shadow 80ms linear;
}
.workspace-overlay .zone.selected {
  opacity: 0.92 !important;
  z-index: 2;
}
.workspace-overlay .zone.dimmed {
  opacity: 0.18 !important;
  filter: saturate(0.45);
}
.create-drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  transform: translate(-9999px, -9999px);
  pointer-events: none;
  z-index: 1000;
  border: 1px solid #94a3b8;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  user-select: none;
  white-space: nowrap;
}
.hud {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(4px);
  padding: 10px;
  font-size: 13px;
}
.mono { font-family: Consolas, "Courier New", monospace; }

/* ── Dark Mode ─────────────────────────────────────────────────────────────── */
html[data-theme="dark"],
html[data-theme="dark"] body {
  color: #e2e8f0;
  background: linear-gradient(180deg, #0f172a 0%, #1a1a2e 100%);
}
html[data-theme="dark"] .toolbar {
  background: rgba(15, 23, 42, 0.88);
  border-color: #334155;
}
html[data-theme="dark"] .toolbar button {
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border-color: #475569;
  color: #e2e8f0;
}
html[data-theme="dark"] .toolbar button:hover {
  border-color: #64748b;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
html[data-theme="dark"] .toolbar code {
  background: #1e293b;
  color: #94a3b8;
}
html[data-theme="dark"] .workspace {
  border-color: #475569;
  background: #0f172a;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
html[data-theme="dark"] .panel {
  border-color: #334155;
  background: #1e293b;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
html[data-theme="dark"] .panel.active-panel {
  outline-color: #3b82f6;
}
html[data-theme="dark"] .tabs {
  border-bottom-color: #334155;
  background: #0f172a;
}
html[data-theme="dark"] .tab {
  border-color: #475569;
  background: #1e293b;
  color: #e2e8f0;
}
html[data-theme="dark"] .tab-close {
  border-color: #475569;
  background: #0f172a;
  color: #94a3b8;
}
html[data-theme="dark"] .panel-meta {
  border-top-color: #334155;
  background: #0f172a;
  color: #94a3b8;
}
html[data-theme="dark"] .panel-number {
  color: #475569;
}
html[data-theme="dark"] .hud {
  border-color: #334155;
  background: rgba(15, 23, 42, 0.88);
  color: #94a3b8;
}
html[data-theme="dark"] .resize-handle::after {
  border-color: rgba(148, 163, 184, 0.95);
  background: rgba(15, 23, 42, 0.95);
}
html[data-theme="dark"] .create-drag-ghost {
  border-color: #475569;
  background: rgba(15, 23, 42, 0.96);
  color: #e2e8f0;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}
html[data-theme="dark"] .workspace-preview.active .panel,
html[data-theme="dark"] .workspace-preview.combined-tone .panel {
  border-color: #4ade80;
}
html[data-theme="dark"] .workspace-preview.active .tabs,
html[data-theme="dark"] .workspace-preview.combined-tone .tabs {
  border-bottom-color: rgba(74, 222, 128, 0.5);
}
html[data-theme="dark"] .workspace-preview.active .tab,
html[data-theme="dark"] .workspace-preview.combined-tone .tab {
  background: rgba(74, 222, 128, 0.12);
  border-color: rgba(74, 222, 128, 0.5);
  color: #4ade80;
}
html[data-theme="dark"] .workspace-preview.active .panel-meta,
html[data-theme="dark"] .workspace-preview.combined-tone .panel-meta {
  border-top-color: rgba(74, 222, 128, 0.4);
  color: #4ade80;
}
html[data-theme="dark"] .workspace-preview.active .panel-number,
html[data-theme="dark"] .workspace-preview.combined-tone .panel-number {
  color: #4ade80;
}
