:root {
  --bg-primary: #1a202c;
  --bg-secondary: #2d3748;
  --bg-tertiary: #4a5568;
  --text-primary: #f7fafc;
  --text-secondary: #a0aec0;
  --accent: #63b3ed;
  --accent-hover: #4299e1;
  --border: #4a5568;
  --success: #48bb78;
  --danger: #fc8181;
  --panel-width: 220px;
  --header-height: 56px;
}

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

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  height: var(--header-height);
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--accent);
}

.logo a { color: inherit; text-decoration: none; }

.mode-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-primary);
  border-radius: 8px;
  padding: 3px;
}

.mode-tab {
  padding: 0.4rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.mode-tab.active {
  background: var(--accent);
  color: #1a202c;
  font-weight: 600;
}

.mode-tab:hover:not(.active) { color: var(--text-primary); }

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:disabled:hover { background: var(--bg-tertiary); }
.btn-ghost:disabled:hover { background: transparent; }
.btn-primary { background: var(--accent); color: #1a202c; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-block { display: block; width: 100%; margin-bottom: 0.4rem; text-align: center; }
.btn-file { cursor: pointer; }

/* Ad slots */
.ad-slot {
  background: var(--bg-primary);
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  text-align: center;
  font-size: 0.75rem;
  padding: 0.5rem;
}

.ad-header { border-bottom: 1px solid var(--border); }
.ad-sidebar { margin-top: 1rem; min-height: 90px; }
.ad-footer { margin-bottom: 1.5rem; min-height: 90px; }

/* Workspace */
.workspace {
  display: flex;
  margin-top: calc(var(--header-height) + 32px);
  height: calc(100vh - var(--header-height) - 32px);
}

.panel {
  width: var(--panel-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 0.75rem;
}

.panel-right {
  border-right: none;
  border-left: 1px solid var(--border);
}

.panel-section {
  margin-bottom: 1rem;
}

.panel-section h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.panel-section label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  margin-bottom: 0.4rem;
  gap: 0.5rem;
}

.panel-section select,
.panel-section input[type="color"] {
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  border-radius: 4px;
  padding: 0.2rem;
  cursor: pointer;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
}

/* Shape grid */
.shape-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.shape-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.7rem;
  transition: all 0.15s;
}

.shape-btn svg { width: 36px; height: 28px; }
.shape-btn.active, .shape-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Templates */
.template-list { display: flex; flex-direction: column; gap: 0.35rem; }

.template-btn {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.78rem;
  text-align: left;
  transition: all 0.15s;
}

.template-btn:hover { border-color: var(--accent); background: var(--bg-tertiary); }

.guide-tip {
  background: var(--bg-primary);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 0.75rem;
}

/* Canvas */
.canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
  cursor: default;
}

.canvas-wrap.panning { cursor: grab; }
.canvas-wrap.panning:active { cursor: grabbing; }

#diagram-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.grid-bg { opacity: 0.4; }
.grid-bg.hidden { display: none; }

.zoom-controls {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.6rem;
}

.zoom-controls button {
  width: 28px; height: 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1rem;
}

#zoom-level { font-size: 0.78rem; min-width: 42px; text-align: center; }

.badge {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  padding: 0.6rem 1.2rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(102,126,234,0.4);
  animation: badgePop 0.5s ease;
  z-index: 10;
}

@keyframes badgePop {
  0% { transform: translateX(-50%) scale(0.5); opacity: 0; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* SVG elements */
.node-group { cursor: move; }
.node-group.selected .node-shape { stroke: var(--accent); stroke-width: 2.5; }
.node-text {
  font-size: 13px;
  fill: var(--text-primary);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}

.conn-path {
  fill: none;
  stroke-width: 2;
  cursor: pointer;
}
.conn-path.selected { stroke-width: 3; }
.conn-label {
  font-size: 11px;
  fill: var(--text-secondary);
  text-anchor: middle;
  cursor: pointer;
}

.connect-point {
  fill: var(--accent);
  stroke: white;
  stroke-width: 1.5;
  cursor: crosshair;
  opacity: 0;
  transition: opacity 0.15s;
}
.node-group:hover .connect-point,
.node-group.show-points .connect-point { opacity: 1; }

.resize-handle {
  fill: var(--accent);
  stroke: white;
  stroke-width: 1;
  cursor: nwse-resize;
  opacity: 0;
}
.node-group.selected .resize-handle { opacity: 1; }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 480px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content h2 { margin-bottom: 0.75rem; font-size: 1.2rem; }
.modal-content p { color: var(--text-secondary); margin-bottom: 1rem; line-height: 1.6; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.modal-templates { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1rem; }

/* Context menu */
.context-menu {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem;
  z-index: 150;
  min-width: 140px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.context-menu.hidden { display: none; }

.context-menu button {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.85rem;
}

.context-menu button:hover { background: var(--bg-tertiary); }

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: white;
  padding: 0.7rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 300;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
  transition: opacity 0.3s;
}

.toast.hidden { opacity: 0; pointer-events: none; }

/* Inline editor (positioned with viewport coordinates from app.js) */
.inline-editor {
  position: fixed;
  z-index: 50;
  background: var(--bg-secondary);
  border: 2px solid var(--accent);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 13px;
  padding: 4px 8px;
  resize: none;
  outline: none;
  text-align: center;
  font-family: inherit;
}

/* Footer guide */
.footer {
  padding: 2rem 1.5rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.guide-content {
  max-width: 800px;
  margin: 0 auto 1.5rem;
}

.guide-content h2 { font-size: 1.3rem; margin-bottom: 1rem; }
.guide-content h3 { font-size: 1rem; margin: 1.2rem 0 0.5rem; color: var(--accent); }
.guide-content p { color: var(--text-secondary); line-height: 1.8; font-size: 0.9rem; margin-bottom: 0.5rem; }

.footer-links, .copyright {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.privacy-page {
  max-width: 700px;
  margin: calc(var(--header-height) + 2rem) auto 2rem;
  padding: 0 1.5rem;
  line-height: 1.8;
}

.privacy-page h1 { margin-bottom: 0.5rem; }
.privacy-page h2 { font-size: 1rem; margin: 1.5rem 0 0.5rem; color: var(--accent); }
.privacy-page ul { margin: 0.5rem 0 0.5rem 1.5rem; color: var(--text-secondary); }
.privacy-page li { margin-bottom: 0.3rem; }
.privacy-page p { color: var(--text-secondary); margin-bottom: 0.5rem; }

/* Mobile toolbar */
.mobile-toolbar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 0.5rem;
  justify-content: space-around;
  z-index: 100;
}

.mobile-toolbar button {
  width: 44px; height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1.1rem;
  cursor: pointer;
}

.hidden { display: none !important; }

/* Responsive */
@media (max-width: 900px) {
  .panel-left, .panel-right { display: none; }
  .workspace { height: calc(100vh - var(--header-height) - 32px - 60px); margin-bottom: 60px; }
  .mobile-toolbar { display: flex; }
  .header-actions .btn-ghost { display: none; }
  .mode-tab { padding: 0.35rem 0.6rem; font-size: 0.78rem; }
}

@media (max-width: 500px) {
  .logo { font-size: 0.9rem; }
  #btn-share { font-size: 0.75rem; padding: 0.35rem 0.6rem; }
}