/* cloth3d — interactive WebGL Verlet cloth showcase
   Dark cinematic UI. System fonts only. No external resources. */

:root {
  --bg-0: #05070d;
  --bg-1: #0b1020;
  --panel: rgba(14, 18, 30, 0.66);
  --panel-solid: #0e1220;
  --hairline: rgba(255, 255, 255, 0.08);
  --hairline-strong: rgba(255, 255, 255, 0.14);
  --text: #e7ecf5;
  --muted: #8a93a8;
  --accent: #7cc0ff;
  --accent-dim: rgba(124, 192, 255, 0.18);
  --warm: #ffb86b;
  --track: rgba(255, 255, 255, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 8px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 8%, #101a33 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 70%);
  background-color: var(--bg-0);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  touch-action: none;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
canvas.grabbing { cursor: grabbing; }

/* ------------------------------------------------------------------ Panel */

.panel {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 296px;
  max-width: calc(100vw - 36px);
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  z-index: 10;
  transition: transform 0.24s var(--ease), opacity 0.24s var(--ease);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .panel { background: var(--panel-solid); }
}

.panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--hairline);
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.brand__dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #cfe6ff, var(--accent) 60%, #2f6fb0);
  box-shadow: 0 0 12px rgba(124, 192, 255, 0.8);
  flex: none;
}
.brand__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.brand__sub {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.panel__head .spacer { flex: 1; }

.iconbtn {
  appearance: none;
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: none;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease);
}
.iconbtn:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--hairline-strong); }
.iconbtn:active { transform: translateY(1px); }

.panel__body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: min(76vh, 680px);
  overflow-y: auto;
}
.panel.collapsed .panel__body { display: none; }
.panel.collapsed { width: auto; }
.panel.collapsed .brand__sub { display: none; }

/* Controls */
.ctrl { display: flex; flex-direction: column; gap: 7px; }
.ctrl__label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
}
.ctrl__val {
  font-size: 12px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: none;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--track);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #eaf4ff, var(--accent) 70%);
  border: none;
  box-shadow: 0 0 0 4px var(--accent-dim), 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: box-shadow 0.15s var(--ease);
}
input[type="range"]::-webkit-slider-thumb:hover { box-shadow: 0 0 0 6px var(--accent-dim), 0 2px 8px rgba(0, 0, 0, 0.6); }
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #eaf4ff, var(--accent) 70%);
  border: none;
  box-shadow: 0 0 0 4px var(--accent-dim);
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 999px; background: var(--track); }
input[type="range"]:focus-visible { box-shadow: 0 0 0 2px rgba(124, 192, 255, 0.5); }

/* Toggle switches */
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 34px;
  height: 19px;
  border-radius: 999px;
  background: var(--track);
  border: 1px solid var(--hairline);
  position: relative;
  flex: none;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease);
}
.switch__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #d4dcea;
  transition: transform 0.18s var(--ease), background 0.18s var(--ease);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.switch input:checked + .switch__track {
  background: linear-gradient(90deg, #2b6aa8, var(--accent));
  border-color: transparent;
}
.switch input:checked + .switch__track::after { transform: translateX(15px); background: #fff; }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px rgba(124, 192, 255, 0.4); }

/* Buttons & segmented control */
.btnrow { display: flex; gap: 8px; }
.btn {
  flex: 1;
  appearance: none;
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease);
}
.btn:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--hairline-strong); }
.btn:active { transform: translateY(1px); }
.btn--accent { background: linear-gradient(180deg, rgba(124,192,255,0.22), rgba(124,192,255,0.1)); border-color: rgba(124,192,255,0.4); }
.btn--accent:hover { background: linear-gradient(180deg, rgba(124,192,255,0.32), rgba(124,192,255,0.16)); }

.seg {
  display: flex;
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.seg button {
  flex: 1;
  appearance: none;
  border: none;
  border-right: 1px solid var(--hairline);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 6px;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.seg button:last-child { border-right: none; }
.seg button:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.seg button.active { background: var(--accent-dim); color: var(--text); }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--hairline);
}
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat__k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.stat__v { font-size: 14px; font-variant-numeric: tabular-nums; font-weight: 600; }

.divider { height: 1px; background: var(--hairline); margin: 0 -16px; }

/* ------------------------------------------------------ Instructions / help */

.help {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 11px 18px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 13px;
  color: var(--text);
  z-index: 9;
  max-width: calc(100vw - 36px);
  flex-wrap: wrap;
  justify-content: center;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.help.hidden { opacity: 0; transform: translateX(-50%) translateY(10px); pointer-events: none; }
.help span { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); white-space: nowrap; }
.help b { color: var(--text); font-weight: 600; }
kbd {
  font-family: inherit;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--hairline-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 2px 7px;
  color: var(--text);
}
.help__close {
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  width: 22px; height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: grid; place-items: center;
}
.help__close:hover { background: rgba(255, 255, 255, 0.16); }

.help-fab {
  position: fixed;
  left: 18px;
  bottom: 18px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--panel);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  z-index: 9;
  display: grid; place-items: center;
  box-shadow: var(--shadow);
  transition: transform 0.15s var(--ease), background 0.15s var(--ease);
}
.help-fab:hover { background: rgba(255, 255, 255, 0.1); transform: translateY(-2px); }

/* ------------------------------------------------------------------ Footer */

.footer {
  position: fixed;
  right: 16px;
  bottom: 14px;
  font-size: 11.5px;
  color: var(--muted);
  text-decoration: none;
  z-index: 8;
  opacity: 0.7;
  transition: opacity 0.2s var(--ease), color 0.2s var(--ease);
}
.footer:hover { opacity: 1; color: var(--accent); }

/* ------------------------------------------------------ WebGL fallback */

.fallback {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  text-align: center;
  padding: 24px;
  z-index: 20;
}
.fallback.show { display: grid; }
.fallback__card {
  max-width: 380px;
  padding: 28px 30px;
  background: var(--panel-solid);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.fallback__card h2 { margin: 0 0 8px; font-size: 18px; }
.fallback__card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

/* ------------------------------------------------------------- Responsive */

@media (max-width: 560px) {
  .panel { top: 12px; right: 12px; left: 12px; width: auto; }
  .help { bottom: 18px; font-size: 12px; gap: 10px; padding: 9px 14px; }
  .footer { left: 12px; right: auto; bottom: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
