:root {
  --radius: 10px;
  --radius-sm: 6px;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
}

html[data-theme="dark"] {
  --bg: #1c1c1e;
  --surface: #232326;
  --surface-2: #2a2a2d;
  --border: #38383a;
  --text-primary: #f5f5f7;
  --text-secondary: #c7c7cc;
  --text-muted: #8e8e93;
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.16);
  --success: #32d74b;
  --error: #ff453a;
  --preview-bg: #2a2a2d;
}

html[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --border: #e2e2e6;
  --text-primary: #1d1d1f;
  --text-secondary: #48484d;
  --text-muted: #86868b;
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.1);
  --success: #248a3d;
  --error: #d70015;
  --preview-bg: #eeeef0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, "SF Pro Text", "Segoe UI", system-ui, Arial, sans-serif;
  font-size: 12.5px;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s var(--ease), color 0.25s var(--ease);
}

.panel {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
.panel-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

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

.brand-mark {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.brand-mark circle { fill: var(--accent); stroke: none; }

.brand h1 {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
  font-family: "SF Mono", "Consolas", monospace;
  color: var(--text-secondary);
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.tab-btn:hover { color: var(--text-primary); }

.tab-btn.active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.theme-toggle {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.3s var(--ease), background 0.2s var(--ease);
}

.theme-toggle:hover { transform: rotate(20deg); background: var(--accent-soft); }
.theme-toggle svg { fill: none; stroke: currentColor; stroke-width: 1.6; }
.theme-toggle svg circle, .theme-toggle svg path { fill: currentColor; stroke: none; }
#iconSun { display: none; }
#iconMoon { display: block; }
html[data-theme="dark"] #iconSun { display: block; }
html[data-theme="dark"] #iconMoon { display: none; }

/* Body layout */
.body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 240px;
  min-width: 200px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preset-item {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.08s var(--ease);
}

.preset-item:hover { background: var(--surface-2); }
.preset-item:active { transform: scale(0.98); }

.preset-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.preset-item-name {
  display: block;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-primary);
}

.preset-item-desc {
  display: block;
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* Detail pane */
.detail {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeIn 0.2s var(--ease);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.detail-title { font-size: 18px; font-weight: 700; margin: 0; }
.detail-subtitle { font-size: 12px; color: var(--accent); font-weight: 500; margin: 2px 0 0; }
.detail-desc { font-size: 12px; color: var(--text-secondary); line-height: 1.5; margin: 0; max-width: 46ch; }

.preview-box {
  background: var(--preview-bg);
  border-radius: var(--radius);
  height: 140px;
  min-height: 140px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: background 0.25s var(--ease);
}

.preview-shape {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--accent);
}

.preview-text {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
}

.sliders { display: flex; flex-direction: column; gap: 14px; }

.slider-row { display: flex; flex-direction: column; gap: 6px; }

.slider-row-top {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
}

.slider-label { color: var(--text-secondary); font-weight: 500; }
.slider-value { color: var(--text-muted); font-family: "SF Mono", "Consolas", monospace; }

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  outline: none;
  transition: background 0.2s var(--ease);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.12s var(--ease);
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-webkit-slider-thumb:active { transform: scale(1.25); }

.apply-btn {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 9px 22px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  margin-top: auto;
  transition: transform 0.1s var(--ease), box-shadow 0.2s var(--ease), opacity 0.15s var(--ease);
  box-shadow: 0 2px 8px var(--accent-soft);
}

.apply-btn:hover { box-shadow: 0 4px 14px var(--accent-soft); }
.apply-btn:active { transform: scale(0.96); }
.apply-btn.applying { opacity: 0.6; pointer-events: none; }

.hint-inline {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

/* Footer */
.status-bar {
  display: flex;
  justify-content: space-between;
  padding: 7px 16px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10.5px;
  font-family: "SF Mono", "Consolas", monospace;
  background: var(--surface);
}

#status-text.success { color: var(--success); }
#status-text.error { color: var(--error); }

.footer-right { display: flex; align-items: center; gap: 12px; }
.footer-credit { color: var(--text-muted); opacity: 0.75; }

/* Curve preview (Easing tab) */
.curve-svg { width: 100%; height: 100%; }
.curve-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: d 0.15s var(--ease);
}
.curve-guide {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.5;
}
.curve-handle {
  fill: var(--accent);
  transition: cx 0.15s var(--ease), cy 0.15s var(--ease);
}
.curve-endpoint { fill: var(--text-secondary); }

/* Graphs tab — interactive curve editor */
.graph-editor { display: flex; flex-direction: column; gap: 10px; }

.graph-editor .curve-svg {
  background: var(--preview-bg);
  border-radius: var(--radius);
  height: 170px;
  display: block;
}

/* Dragging must track the pointer 1:1 — the Easing tab's smoothing
   transition would make the handle visibly lag behind the cursor. */
.curve-handle-draggable {
  transition: none;
  cursor: grab;
  touch-action: none;
}
.curve-handle-draggable:active { cursor: grabbing; }
.curve-handle-draggable:hover { r: 7; }

.curve-value-input {
  width: 100%;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 8px 10px;
  outline: none;
}
.curve-value-input:focus { border-color: var(--accent); }

.curve-toolbar { display: flex; gap: 8px; }
.curve-icon-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.curve-icon-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.curve-icon-btn.starred { color: var(--accent); border-color: var(--accent); }

.curve-presets-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 6px;
}
.curve-presets-row::-webkit-scrollbar { height: 5px; }
.curve-presets-row::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

.curve-preset-tile {
  position: relative;
  flex: 0 0 auto;
  width: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 4px 5px;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.curve-preset-tile:hover { border-color: var(--accent); }
.curve-preset-tile.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.curve-thumb-svg { width: 32px; height: 32px; color: var(--text-secondary); }
.curve-preset-tile.active .curve-thumb-svg { color: var(--accent); }
.curve-preset-name {
  font-size: 9px;
  font-weight: 600;
  max-width: 52px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.curve-preset-star {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 9px;
  color: var(--accent);
}
.curve-preset-del {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 15px;
  height: 15px;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--error);
  color: #fff;
  border-radius: 50%;
  font-size: 10px;
  line-height: 1;
}
.curve-preset-tile:hover .curve-preset-del { display: flex; }

/* Code preview (Expressions tab) */
.code-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 11px;
  line-height: 1.7;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 90px;
  max-height: 180px;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  transition: background 0.2s var(--ease);
}
.code-box::-webkit-scrollbar { width: 6px; }
.code-box::-webkit-scrollbar-track { background: transparent; }
.code-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
.code-box::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.code-keyword { color: var(--accent); }

.target-select {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
  flex-shrink: 0;
}

.field-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.field-label-center { text-align: center; }

/* Smooth crossfade + slide when switching presets/tabs */
.detail-anim {
  animation: detailIn 0.22s var(--ease);
}
@keyframes detailIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Expressions tab: real per-preset previews (replaces generic pulse) --- */
@keyframes previewWiggle {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(calc(var(--p-amp) * 0.6), calc(var(--p-amp) * -0.8)); }
  40%  { transform: translate(calc(var(--p-amp) * -0.9), calc(var(--p-amp) * 0.3)); }
  60%  { transform: translate(calc(var(--p-amp) * 0.4), calc(var(--p-amp) * 0.9)); }
  80%  { transform: translate(calc(var(--p-amp) * -0.5), calc(var(--p-amp) * -0.5)); }
  100% { transform: translate(0, 0); }
}
@keyframes previewBounceSettle {
  0%   { transform: translateY(calc(var(--p-amp) * -2)); }
  40%  { transform: translateY(0); }
  55%  { transform: translateY(calc(var(--p-amp) * -1)); }
  70%  { transform: translateY(0); }
  82%  { transform: translateY(calc(var(--p-amp) * -0.4)); }
  92%  { transform: translateY(0); }
  100% { transform: translateY(0); }
}
@keyframes previewLoopCycle {
  0%   { transform: translateX(-30px); }
  50%  { transform: translateX(30px); }
  100% { transform: translateX(-30px); }
}
@keyframes previewSine {
  0%, 100% { transform: translateY(calc(var(--p-amp) * -1)); }
  50%      { transform: translateY(var(--p-amp)); }
}
@keyframes previewThrow {
  0%   { transform: translateX(-38px); }
  60%  { transform: translateX(30px); }
  100% { transform: translateX(30px); }
}

/* --- Text tab: real per-preset previews (replaces static label) --- */
.preview-text-row { display: flex; align-items: baseline; justify-content: center; }
.preview-char, .preview-word {
  display: inline-block;
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: pre;
}
.preview-word { margin-right: 0.28em; }

@keyframes previewFadeUp {
  0%   { opacity: 0; transform: translateY(var(--p-off)); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes previewBlurReveal {
  0%   { opacity: 0; filter: blur(var(--p-blur)); }
  100% { opacity: 1; filter: blur(0); }
}
@keyframes previewCharRise {
  0%   { opacity: 0; transform: translateY(var(--p-off)); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes previewBouncy {
  0%   { transform: scale(0); }
  60%  { transform: scale(var(--p-overshoot)); }
  100% { transform: scale(1); }
}
@keyframes previewSpringScale {
  0%   { opacity: 0; transform: scale(var(--p-scale)); }
  55%  { opacity: 1; transform: scale(calc(var(--p-scale) + (1 - var(--p-scale)) * 1.25)); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes previewBurst {
  0%   { opacity: 0; filter: blur(var(--p-blur)); transform: translateY(var(--p-off)) scale(var(--p-scale)); }
  100% { opacity: 1; filter: blur(0); transform: translateY(0) scale(1); }
}
@keyframes previewPop {
  0%   { opacity: 0; }
  100% { opacity: 1; }
}
@keyframes previewSpringRise {
  0%   { opacity: 0; transform: translateY(var(--p-off)); }
  10%  { opacity: 1; }
  45%  { transform: translateY(calc(var(--p-off) * -0.25)); }
  65%  { transform: translateY(calc(var(--p-off) * 0.12)); }
  82%  { transform: translateY(calc(var(--p-off) * -0.05)); }
  100% { opacity: 1; transform: translateY(0); }
}

/* Editable numeric field (e.g. Number Counter From/To) shown next to the slider */
.slider-numinput {
  width: 66px;
  text-align: right;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 11.5px;
  padding: 3px 6px;
  outline: none;
}
.slider-numinput:focus { border-color: var(--accent); }
/* Hide native spinner arrows — the range slider below already covers
   coarse adjustment, this field is for typing an exact value. */
.slider-numinput::-webkit-inner-spin-button,
.slider-numinput::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Tools tab */
.tools-wide {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool-wide-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 500;
  padding: 10px 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.08s var(--ease);
}
.tool-wide-btn:hover { background: var(--accent-soft); border-color: var(--accent-dim, var(--accent)); }
.tool-wide-btn:active { transform: scale(0.98); }
.tool-wide-btn.applying { opacity: 0.6; pointer-events: none; }

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

.tool-grid-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 12px 4px;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), transform 0.08s var(--ease);
}
.tool-grid-btn:hover { background: var(--accent-soft); color: var(--text-primary); }
.tool-grid-btn:active { transform: scale(0.94); }
.tool-grid-btn.applying { opacity: 0.6; pointer-events: none; }

.anchor-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  width: 210px;
  height: auto;
  margin: 4px auto 0;
  background: var(--preview-bg);
  border-radius: var(--radius);
  padding: 14px;
  box-sizing: border-box;
}

.anchor-btn {
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.08s var(--ease);
}
.anchor-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.anchor-btn:active { transform: scale(0.92); }
.anchor-btn.applying { opacity: 0.6; pointer-events: none; }
.anchor-mark { stroke: var(--text-secondary); stroke-width: 1.6; stroke-linecap: round; }
.anchor-dot { fill: var(--text-secondary); }
.anchor-btn:hover .anchor-mark { stroke: var(--accent); }
.anchor-btn:hover .anchor-dot { fill: var(--accent); }
