:root {
  --fg: #f0f0f0;
  --fg-muted: #999;
  --fg-faint: #555;
  --border: rgba(255,255,255,0.15);
  --border-strong: rgba(255,255,255,0.35);
  --card: #262626;
}
* { box-sizing: border-box; }
.app, .app * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
/* SVG text doesn't always inherit user-select; set it explicitly to
   suppress the macOS dictionary popup on force-touch / three-finger-tap. */
svg text {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.stage canvas {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}
.stage {
  touch-action: none;
}
body {
  margin: 0;
  padding: clamp(12px, 3vw, 32px);
  background: black;
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  gap: clamp(12px, 2vw, 24px);
  flex-direction: row;
}

@media (orientation: portrait) {
  body {
    flex-direction: column;
  }
}

body, button, input, textarea, select, .app, .app * {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  flex: 0 0 300px;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  color: rgba(255, 255, 255, 0.85);
}
.sb-section {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
/* Class selectors with display: flex would otherwise win over the
   browser default [hidden] { display: none } and leak everything visible. */
[hidden] { display: none !important; }
.sb-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.55);
  font-weight: 600;
}
.sb-hint {
  margin: 0;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.45);
  line-height: 1.5;
}
.sb-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px;
}

/* Segmented mode toggle */
.seg-toggle {
  display: flex;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  flex: 1;
  background: transparent;
  color: rgba(255, 255, 255, 0.65);
  border: none;
  border-radius: 4px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.seg-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.seg-btn.active {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

/* Generic sidebar buttons */
.sb-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.sb-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.16); }
.sb-btn:active:not(:disabled) { background: rgba(255, 255, 255, 0.24); }
.sb-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.sb-btn.copied { background: rgba(80, 200, 120, 0.4); }

.dataset-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dataset-row select {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  font: inherit;
  font-size: 12px;
}
.dataset-lock {
  font-size: 12px;
  opacity: 0.7;
}
.dataset-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

/* Emotion list */
.emotion-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 280px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  padding: 4px;
}
.emotion-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
}
.emotion-list li:hover { background: rgba(255, 255, 255, 0.05); }
.emotion-list .em-chip {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.emotion-list .em-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.emotion-list .em-remove {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
}
.emotion-list .em-remove:hover { color: #ff8888; }

.add-emotion input,
.sb-input {
  width: 100%;
  padding: 5px 8px;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.sb-input { user-select: text; -webkit-user-select: text; }
.add-emotion input:focus,
.sb-input:focus {
  outline: 1px solid rgba(255, 255, 255, 0.4);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
}
.slider-row label { min-width: 80px; }
.slider-row input[type="range"] { flex: 1; min-width: 0; }
.slider-row span { min-width: 3em; text-align: right; font-variant-numeric: tabular-nums; }

.dev-coord-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.dev-coord-row .sb-input { flex: 1; }

.sb-export {
  width: 100%;
  min-height: 140px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  color: #fff;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  line-height: 1.4;
  resize: vertical;
  user-select: text;
  -webkit-user-select: text;
}

/* ============================================================
   Main app column
   ============================================================ */
.app {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: clamp(12px, 2vw, 20px);
}
/* Card lives inside the sidebar — vertical stack, full sidebar width. */
.sidebar .card {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin: 0;
  color: rgba(255, 255, 255, 0.3);
  gap: 24px;
  font-size: 13px;
  line-height: 1.5;
  margin-top: 24px;
}
.card-data {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.card-chip {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 6px;
  background: #333;
}

.card-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.card-pair {
  display: flex;
  flex-direction: row;
  gap: 20px;
}

.card-pair > div {
  width: 50%;
}

.card-section.card-emotion {
  flex: 1;
  min-width: 120px;
  justify-content: center;
}
.card-caption {
  margin: 8px 0 4px 0;
  font-size: 13px;
  font-weight: 500;
  color: white;
}

.card-header .card-caption {
  margin: 0;
}
.nearest-label {
  font-size: 36px;
  font-weight: 600;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--accent, #333);
}
.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 14px;
  line-height: 1.6;
}
.card-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255, 255, 255, 0.85);
  min-width: 0;
}
.card-list .list-chip {
  width: 0.85em;
  height: 0.85em;
  border-radius: 2px;
  flex-shrink: 0;
}
.card-list .list-text {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-vad-rows {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: space-between;
  align-items: baseline;
  column-gap: 12px;
  row-gap: 2px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  width: 66%;
}
.value-row {
  display: contents;
}
.value-row .num {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 500;
  opacity: 0.85;
  white-space: pre;
}
/* Pre-touch placeholder */
.card:not(.touched) .card-list,
.card:not(.touched) .card-vad-rows {
  opacity: 0.2;
}
/* Hide handle until first interaction (view mode only — in edit/dev the
   handle is hidden regardless). The .touched class is toggled on .app. */
.app.mode-view:not(.touched) .stage .handle,
.app.mode-view:not(.touched) .stage .handle-shadow,
.app.mode-view:not(.touched) .stage .mirror-handle {
  display: none;
}

/* Mode-aware rules — generalized from the old .app.dev-mode {…} */
.app:not(.mode-view) .stage .handle,
.app:not(.mode-view) .stage .handle-shadow,
.app:not(.mode-view) .stage .mirror-handle {
  display: none;
}
.app.mode-edit .label,
.app.mode-dev .label {
  cursor: grab;
  pointer-events: auto;
  opacity: 0.7 !important;
}
.app.mode-edit .label:active,
.app.mode-dev .label:active {
  cursor: grabbing;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: calc(100vh - 200px);
  max-width: calc(100vh - 200px);
  margin: 0 auto;
}
.stage canvas, .stage svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.stage svg { pointer-events: none; }
.stage svg .interactive { pointer-events: auto; }
.label {
  font-size: 14px;
  fill: #fff;
  font-weight: 500;
  opacity: 0;
  text-shadow: 0 1px 1px rgba(0,0,0,0.6);
  pointer-events: none;
}
.axis-end-label {
  fill: #000;
  font-size: 13px;
  font-weight: 600;
  opacity: 0.6;
  pointer-events: none;
}
.perimeter {
  fill: none;
  stroke: #000;
  stroke-width: 2;
}
.handle {
  stroke: #000;
  stroke-width: 2;
  transition: r 0.15s ease, stroke-width 0.15s ease;
}
.handle.active {
  stroke-width: 3;
}
.handle-shadow {
  fill: rgba(0,0,0,0.35);
  transition: r 0.15s ease;
}
.mirror-handle {
  fill: rgba(0, 0, 0, 0.45);
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 1;
  pointer-events: none;
}
