/* ==========================================================================
   PARTICLE MORPH — three.js playground experiment (scripts/particle-morph.js)
   The widget's own styles, scoped to #morph-root; type is the site's Geist.
   ========================================================================== */

.pm-page {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding-top: var(--header-h);
}
.pm-page__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-16);
  padding-block: var(--space-16);
}
.pm-page__title { font-size: var(--text-sm); line-height: var(--leading-sm); color: var(--color-text); }
.pm-page__stage { flex: 1; display: flex; min-height: 30rem; }

#morph-root {
  --ink: rgba(10,10,10,1); --ink-70: rgba(10,10,10,0.70); --ink-45: rgba(10,10,10,0.45);
  --ink-30: rgba(10,10,10,0.30); --ink-12: rgba(10,10,10,0.12); --ink-06: rgba(10,10,10,0.06);
  --panel-bg: rgba(255,255,255,0.55); --panel-brd: rgba(10,10,10,0.08);
  position: relative; width: 100%; flex: 1; min-height: 480px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; font-family: var(--font-sans);
}
#sphere-container {
  position: relative; width: min(500px, 80vw, 80vh); height: min(500px, 80vw, 80vh);
  overflow: visible; flex-shrink: 0;
}

#panel-trigger {
  position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
  z-index: 100; height: 10px; width: 10px;
}
#toggle-btn {
  width: 10px; height: 10px; border-radius: 50%; background: rgba(0,0,0,0.75);
  border: none; cursor: pointer; padding: 0; position: relative; flex-shrink: 0;
  outline: none; transition: transform 0.15s ease, background 0.2s ease;
}
#toggle-btn:hover { transform: scale(0.9); }
#toggle-btn.open  { background: rgba(0,0,0,0.35); }
#toggle-btn::before {
  content: ''; position: absolute; inset: -4px; border-radius: 50%;
  border: 1.5px solid rgba(0,0,0,0.3); animation: pulse-ring 2s ease-out infinite;
}
#toggle-btn.open::before { animation: none; border-color: transparent; }
@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.6; }
  70% { transform: scale(2.2); opacity: 0; }
  100% { transform: scale(2.2); opacity: 0; }
}

#panel-wrapper {
  position: absolute; top: 50%; right: 36px;
  transform: translateY(-50%) scale(0.01); transform-origin: right center;
  opacity: 0; pointer-events: none; max-width: calc(100% - 60px); z-index: 99;
  transition: transform 0.42s cubic-bezier(0.34,1.56,0.64,1), opacity 0.18s ease;
}
#panel-wrapper.open {
  transform: translateY(-50%) scale(1); opacity: 1; pointer-events: auto;
  transition: transform 0.28s cubic-bezier(0.4,0,0.6,1), opacity 0.18s ease;
}

#morph-root .controls {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--panel-bg); border: 1px solid var(--panel-brd);
  border-radius: 16px; padding: 14px 14px 12px;
  backdrop-filter: blur(20px) saturate(1.4); -webkit-backdrop-filter: blur(20px) saturate(1.4);
  box-shadow: 0 1px 0 rgba(255,255,255,0.6) inset, 0 12px 40px -12px rgba(10,10,10,0.28);
  width: 206px; max-width: 100%;
  max-height: min(560px, 82vh);
  max-height: min(560px, 82svh);
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
#morph-root .controls::-webkit-scrollbar { width: 5px; }
#morph-root .controls::-webkit-scrollbar-thumb { background: var(--ink-12); border-radius: 3px; }

#panel-wrapper.open .controls > * { animation: row-in 0.4s cubic-bezier(0.34,1.3,0.64,1) both; }
#panel-wrapper.open .controls > *:nth-child(1){animation-delay:.03s}
#panel-wrapper.open .controls > *:nth-child(2){animation-delay:.05s}
#panel-wrapper.open .controls > *:nth-child(3){animation-delay:.07s}
#panel-wrapper.open .controls > *:nth-child(4){animation-delay:.09s}
#panel-wrapper.open .controls > *:nth-child(5){animation-delay:.11s}
#panel-wrapper.open .controls > *:nth-child(6){animation-delay:.13s}
#panel-wrapper.open .controls > *:nth-child(7){animation-delay:.15s}
#panel-wrapper.open .controls > *:nth-child(8){animation-delay:.17s}
#panel-wrapper.open .controls > *:nth-child(9){animation-delay:.19s}
#panel-wrapper.open .controls > *:nth-child(10){animation-delay:.21s}
#panel-wrapper.open .controls > *:nth-child(n+11){animation-delay:.23s}
@keyframes row-in { from { opacity:0; transform:translateY(-6px);} to { opacity:1; transform:translateY(0);} }

#morph-root .panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding-bottom: 10px; margin-bottom: 2px; border-bottom: 1px solid var(--ink-06);
}
#morph-root .panel-head .title { font-size: 12px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-70); }
#morph-root .panel-head .now-shape {
  font-size: 9px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink); background: var(--ink-06); padding: 3px 8px; border-radius: 20px;
}

#morph-root .section-label { font-size: 8.5px; font-weight: 700; letter-spacing: 0.24em; text-transform: uppercase; color: var(--ink-30); margin: 9px 0 5px; }

#morph-root .shape-grid, #morph-root .preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 4px; }
#morph-root .preset-grid { grid-template-columns: repeat(2, 1fr); }
#morph-root .rand-btn {
  font-family: inherit; font-size: 9px; font-weight: 700; letter-spacing: 0.16em;
  text-transform: uppercase; color: #fff; background: var(--ink); border: none;
  border-radius: 9px; padding: 9px 4px; margin-top: 6px; cursor: pointer;
  transition: transform 0.12s ease, opacity 0.2s ease;
}
#morph-root .rand-btn:hover { opacity: 0.85; }
#morph-root .rand-btn:active { transform: scale(0.97); }
#morph-root .shape-chip {
  font-family: inherit; font-size: 8.5px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-45); background: transparent;
  border: 1px solid var(--ink-12); border-radius: 8px; padding: 7px 4px;
  cursor: pointer; transition: all 0.18s ease;
}
#morph-root .shape-chip:hover { border-color: var(--ink-30); color: var(--ink-70); }
#morph-root .shape-chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

#morph-root .control-row { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
#morph-root .control-row .row-top { display: flex; align-items: center; justify-content: space-between; }
#morph-root .control-row label { color: var(--ink-45); font-size: 9.5px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; }
#morph-root .control-row .val {
  color: var(--ink); font-size: 10px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--ink-06); padding: 2px 7px; border-radius: 6px; min-width: 34px; text-align: center;
}

#morph-root input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 3px;
  border-radius: 3px; background: var(--ink-12); cursor: pointer; outline: none;
}
#morph-root input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--ink); border: 2.5px solid #fff; box-shadow: 0 1px 4px rgba(10,10,10,0.35);
  transition: transform 0.12s ease;
}
#morph-root input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.18); }
#morph-root input[type=range]::-webkit-slider-thumb:active { transform: scale(0.95); }
#morph-root input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--ink);
  border: 2.5px solid #fff; box-shadow: 0 1px 4px rgba(10,10,10,0.35); cursor: pointer;
}
#morph-root input[type=range]::-moz-range-track { height: 3px; border-radius: 3px; background: var(--ink-12); }

#morph-root .control-row select {
  width: 100%; background: var(--ink-06); border: 1px solid var(--ink-12); color: var(--ink);
  padding: 8px 10px; border-radius: 9px; font-size: 11px; font-weight: 500; font-family: inherit;
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%230a0a0a' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
#morph-root .color-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; }
#morph-root .color-row label { color: var(--ink-45); font-size: 9.5px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; }
#morph-root input[type=color] {
  width: 46px; height: 26px; border: 1px solid var(--ink-12); background: transparent;
  border-radius: 8px; cursor: pointer; padding: 2px;
}
#morph-root input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
#morph-root input[type=color]::-webkit-color-swatch { border: none; border-radius: 6px; }

#morph-root .toggle-row {
  display: flex; align-items: center; justify-content: space-between; padding: 5px 0;
  color: var(--ink-45); font-size: 9.5px; font-weight: 500; letter-spacing: 0.12em;
  text-transform: uppercase; cursor: pointer; user-select: none;
}
#morph-root .toggle-row input { display: none; }
#morph-root .switch {
  position: relative; width: 34px; height: 19px; border-radius: 20px;
  background: var(--ink-12); transition: background 0.22s ease; flex-shrink: 0;
}
#morph-root .switch::after {
  content: ''; position: absolute; top: 2.5px; left: 2.5px; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(10,10,10,0.35);
  transition: transform 0.24s cubic-bezier(0.34,1.56,0.64,1);
}
#morph-root .toggle-row input:checked + .switch { background: var(--ink); }
#morph-root .toggle-row input:checked + .switch::after { transform: translateX(15px); }

#morph-root .divider { height: 1px; background: var(--ink-06); margin: 10px 0 2px; }
#morph-root .hint { font-size: 8.5px; font-weight: 500; letter-spacing: 0.08em; color: var(--ink-30); text-align: center; margin-top: 10px; line-height: 1.5; }

/* Dark theme: the toggle dot reads on dark paper */
:root[data-theme="dark"] #toggle-btn { background: rgba(255,255,255,0.8); }
:root[data-theme="dark"] #toggle-btn::before { border-color: rgba(255,255,255,0.35); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #toggle-btn { background: rgba(255,255,255,0.8); }
  :root:not([data-theme="light"]) #toggle-btn::before { border-color: rgba(255,255,255,0.35); }
}

/* Mobile: pin panel to the viewport; svh cap keeps internal scroll usable */
@media (max-width: 600px) {
  #panel-wrapper {
    position: fixed; top: 50%; right: 12px; left: auto;
    transform: translateY(-50%) scale(0.01); max-width: calc(100vw - 24px);
  }
  #panel-wrapper.open { transform: translateY(-50%) scale(1); }
  #morph-root .controls {
    width: min(230px, calc(100vw - 24px));
    max-height: 86vh; max-height: 86svh;
  }
  #morph-root .panel-head .title { font-size: 11px; letter-spacing: 0.12em; }
  #morph-root .panel-head .now-shape { font-size: 8.5px; letter-spacing: 0.1em; }
}
