:root {
  --panel-bg: #252830;
  --panel-border: #3d424a;
  --panel-text: #e6e8ec;
  --panel-muted: #9ca3af;
  --accent: #5b8def;
  --accent-hover: #7aa3f2;
  --danger: #e85d6a;
  --danger-hover: #ec7a85;
  --canvas-bg: #1a1d23;
  --item-bg: #2d3139;
  --item-active: #3a3f4a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--canvas-bg);
  color: var(--panel-text);
  min-height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
}

.panel {
  width: 280px;
  min-width: 240px;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.panel-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  flex: 1;
}

.panel-header .version {
  font-size: 1.0rem;
  font-weight: 500;
  color: var(--panel-muted);
  background: var(--item-bg);
  padding: 0.2em 0.5em;
  border-radius: 4px;
  margin-left: 0.35em;
  vertical-align: middle;
}

.btn-about {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  background: var(--item-bg);
  color: var(--panel-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-about:hover {
  background: var(--item-active);
  color: var(--panel-text);
  border-color: var(--panel-muted);
}

.btn-about-icon {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  font-family: system-ui, sans-serif;
}

.panel-actions {
  padding: 1rem 1.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  transition: background 0.15s, color 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.models-section {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0 1rem 1rem;
}

.models-section h2 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--panel-muted);
}

.model-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.model-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 2px;
  background: var(--item-bg);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.model-item:hover {
  background: var(--item-active);
}

.model-item.active {
  background: var(--item-active);
  outline: 1px solid var(--accent);
}

.model-item-label {
  flex: 1;
  min-width: 0;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-remove {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  color: var(--panel-muted);
  border-radius: 6px;
  font-size: 1.1rem;
  line-height: 1;
}

.btn-remove:hover {
  background: rgba(232, 93, 106, 0.2);
  color: var(--danger);
}

.canvas-area {
  flex: 1;
  position: relative;
  background: var(--canvas-bg);
  min-width: 0;
}

.canvas-container {
  position: absolute;
  inset: 0;
  display: none;
}

.canvas-container.visible {
  display: block;
}

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

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--panel-muted);
  font-size: 1rem;
}

.empty-state.hidden {
  display: none;
}

/* About modal */
.about-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.about-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.about-overlay[hidden] {
  display: none;
}

.about-overlay.visible[hidden] {
  display: flex;
}

.about-dialog {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  max-width: 420px;
  width: 100%;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.about-dialog-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--panel-border);
}

.about-dialog-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
}

.btn-about-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--panel-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-about-close:hover {
  background: var(--item-bg);
  color: var(--panel-text);
}

.about-dialog-body {
  padding: 1.25rem;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.55;
}

.about-dialog-body p {
  margin: 0 0 1rem;
}

.about-dialog-body p:last-child {
  margin-bottom: 0;
}

.about-dialog-body code {
  font-size: 0.85em;
  padding: 0.15em 0.4em;
  background: var(--item-bg);
  border-radius: 4px;
}

.about-dialog-body a {
  color: var(--accent);
  text-decoration: none;
}

.about-dialog-body a:hover {
  text-decoration: underline;
}

@media (max-width: 640px) {
  .app {
    flex-direction: column;
  }

  .panel {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
  }
}
