:root {
  --bg-1: #f4eef5;
  --bg-2: #eef2f7;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-border: rgba(255, 255, 255, 0.9);
  --ink: #2c2a35;
  --ink-soft: #736f7d;
  --accent: #ff8a5b;
  --accent-ink: #7a3512;
  --teal: #3aa697;
  --danger: #e35b5b;
  --radius: 16px;
  --shadow-soft: 0 10px 30px rgba(60, 40, 70, 0.12);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  background: radial-gradient(circle at 20% 0%, #fbf3ff 0%, var(--bg-1) 42%, var(--bg-2) 100%);
}

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

/* --- Top bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  z-index: 5;
}

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

.brand-mark {
  font-size: 28px;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.12));
}

.brand-text h1 {
  font-family: 'Fredoka', 'Inter', sans-serif;
  font-size: 19px;
  margin: 0;
  line-height: 1.1;
  letter-spacing: 0.2px;
}

.brand-text p {
  margin: 0;
  font-size: 11px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.btn-group {
  display: flex;
  gap: 4px;
}

.icon-btn-lg {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: #fff;
  cursor: pointer;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.icon-btn-lg:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(60, 40, 70, 0.12);
}

.icon-btn-lg:disabled,
.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.grid-size {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
  margin-right: 4px;
}

.grid-size select {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
  color: var(--ink);
}

.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(60, 40, 70, 0.12);
}

.btn:active {
  transform: translateY(0);
}

.btn-ghost {
  background: rgba(0, 0, 0, 0.03);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), #ffb35b);
  color: #5a2a0a;
  border: none;
}

.btn-danger {
  background: rgba(227, 91, 91, 0.12);
  color: var(--danger);
  border: 1px solid rgba(227, 91, 91, 0.25);
}

/* --- Tab bar --- */
.tabbar {
  display: flex;
  gap: 4px;
  padding: 8px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
}

.tab-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.tab-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

.tab-btn.active {
  background: rgba(255, 138, 91, 0.14);
  color: var(--accent-ink);
}

.tab-view.hidden {
  display: none;
}

/* --- Workspace layout --- */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-width, 320px);
  flex-shrink: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.splitter {
  flex-shrink: 0;
  width: 9px;
  margin: 0 -4px;
  cursor: col-resize;
  position: relative;
  z-index: 4;
  background: transparent;
}

.splitter::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 1px;
  background: rgba(0, 0, 0, 0.08);
  transition: background 0.12s ease;
}

.splitter:hover::after,
.splitter.dragging::after {
  background: var(--accent);
  width: 2px;
  left: 3.5px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-soft);
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--ink-soft);
}

.canvas-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  cursor: crosshair;
}

#blueprint {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.brush-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 6px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-soft);
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  max-width: 100%;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.segmented button {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  padding: 5px 8px;
  min-width: 22px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink-soft);
}

.segmented button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tool-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border-radius: 12px;
  border: 1.5px solid rgba(0, 0, 0, 0.06);
  background: #fff;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.tool-btn .tool-icon {
  font-size: 20px;
  line-height: 1;
}

.tool-btn .tool-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-soft);
}

.tool-btn:hover {
  transform: translateY(-1px);
}

.tool-btn.active {
  border-color: var(--accent);
  background: rgba(255, 138, 91, 0.12);
  box-shadow: 0 0 0 3px rgba(255, 138, 91, 0.14);
}

.tool-btn.active .tool-label {
  color: var(--accent-ink);
}

/* --- Viewport --- */
.viewport {
  flex: 1;
  position: relative;
  min-width: 0;
}

#canvas3d {
  position: absolute;
  inset: 0;
}

#canvas3d canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.viewport-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 11.5px;
  color: var(--ink-soft);
  background: var(--panel);
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.floating.card {
  position: absolute;
  width: 240px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
}

.lighting-card {
  top: 16px;
  right: 16px;
}

.selection-card {
  bottom: 16px;
  left: 16px;
}

.selection-card.hidden {
  display: none;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.card-header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
}

.icon-btn {
  border: none;
  background: rgba(0, 0, 0, 0.06);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  color: var(--ink-soft);
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 9px;
  font-size: 11.5px;
  color: var(--ink-soft);
  font-weight: 600;
}

.slider-row input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
  margin-bottom: 10px;
}

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

.camera-presets {
  display: flex;
  gap: 8px;
}

.camera-presets .btn {
  flex: 1;
  padding: 7px 8px;
  font-size: 12px;
  text-align: center;
}

.mode-toggles {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.drive-toggle {
  flex: 1;
  text-align: center;
  padding: 9px 6px;
  font-size: 12.5px;
}

.drive-toggle.active {
  background: linear-gradient(135deg, var(--teal), #2f8074);
  color: #fff;
}

.selection-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.selection-actions .btn {
  flex: 1;
  padding: 7px 8px;
  font-size: 12px;
  text-align: center;
}

/* --- Config tab --- */
.config-view {
  flex: 1;
  margin: 16px 22px;
  overflow-y: auto;
  max-width: 560px;
}

.config-view h2 {
  margin: 0 0 14px;
  font-size: 15px;
}

.config-group h3 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
}

.config-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-top: 10px;
}

.config-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  color: var(--ink-soft);
  font-weight: 600;
}

.config-field input {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 9px;
  width: 90px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #fff;
  color: var(--ink);
}

#heightRangeError {
  color: var(--danger);
  min-height: 1em;
  margin-top: 8px;
}

/* --- Version tab --- */
.version-view {
  flex: 1;
  margin: 16px 22px;
  overflow-y: auto;
}

.version-view h2 {
  margin: 0 0 4px;
  font-size: 15px;
}

.version-list {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-top: 10px;
}

.version-list th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  padding: 6px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.version-list td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  vertical-align: top;
}

.version-tag {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-weight: 700;
  white-space: nowrap;
}

.version-row-clickable {
  cursor: pointer;
}

.version-row-clickable:hover {
  background: rgba(0, 0, 0, 0.03);
}

.version-details {
  color: var(--ink-soft);
  white-space: pre-wrap;
  background: rgba(0, 0, 0, 0.02);
}

.version-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.version-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.06);
  color: var(--ink-soft);
}

.version-badge-added { background: rgba(58, 166, 151, 0.16); color: #1f6b60; }
.version-badge-changed { background: rgba(255, 138, 91, 0.16); color: var(--accent-ink); }
.version-badge-fixed { background: rgba(227, 91, 91, 0.14); color: var(--danger); }

/* --- Reports tab --- */
.reports-view {
  flex: 1;
  display: flex;
  gap: 16px;
  min-height: 0;
  margin: 16px 22px;
}

.reports-list {
  width: 280px;
  flex-shrink: 0;
  overflow-y: auto;
}

.reports-list h2 {
  margin: 0 0 8px;
  font-size: 15px;
}

.reports-list-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.reports-list-items li {
  display: flex;
  align-items: center;
  gap: 4px;
}

.reports-list-item-button {
  flex: 1;
  text-align: left;
  border: 1.5px solid rgba(0, 0, 0, 0.06);
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reports-list-item-button:hover {
  border-color: var(--accent);
}

.reports-list-items li.selected .reports-list-item-button {
  border-color: var(--accent);
  background: rgba(255, 138, 91, 0.1);
}

.reports-list-item-title {
  font-size: 13px;
  font-weight: 600;
}

.reports-list-item-date {
  font-size: 10.5px;
  color: var(--ink-soft);
}

.reports-delete {
  border: none;
  background: rgba(227, 91, 91, 0.1);
  color: var(--danger);
  width: 26px;
  height: 26px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 11px;
}

.reports-viewer {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0;
  overflow: hidden;
}

.reports-viewer .hint {
  margin: 0;
}

.reports-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.reports-iframe.hidden {
  display: none;
}

@media (max-width: 980px) {
  .sidebar {
    width: 260px;
  }
  .floating.card {
    width: 200px;
  }
  .splitter {
    display: none;
  }
}

/* --- Narrow / touch screens: stack panels instead of side-by-side --- */
@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .workspace {
    flex-direction: column;
    overflow-y: auto;
  }

  .sidebar {
    width: 100%;
    max-height: 46vh;
    border-right: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  }

  .viewport {
    min-height: 46vh;
  }

  .floating.card {
    width: 168px;
    padding: 10px;
  }

  .reports-view {
    flex-direction: column;
  }

  .reports-list {
    width: 100%;
    max-height: 40vh;
  }
}
