/* =========================================================
  ChemEquilibrium Lab - assets/css/simulation.css
  ---------------------------------------------------------
  Style khusus Mode Simulasi:
  - reaction vessel / wadah reaksi
  - canvas particle animation
  - efek partikel dan tumbukan
  - indikator Q, K, status setimbang
  - panel kontrol gangguan
  - konsentrasi dan arah pergeseran
  - responsive polish
========================================================= */

/* =========================================================
  Simulation Panel Decorative Layers
========================================================= */

.simulation-panel {
  position: relative;
  overflow: hidden;
}

.simulation-panel::before,
.simulation-panel::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: var(--radius-full);
  z-index: 0;
}

.simulation-panel::before {
  width: 520px;
  height: 520px;
  left: -180px;
  top: 120px;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.16), transparent 70%);
}

.simulation-panel::after {
  width: 420px;
  height: 420px;
  right: -150px;
  bottom: -120px;
  background: radial-gradient(circle, rgba(249, 115, 22, 0.16), transparent 70%);
}

.simulation-panel > * {
  position: relative;
  z-index: 1;
}

/* =========================================================
  Reaction Equation Enhancements
========================================================= */

.reaction-equation-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

.reaction-equation-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 18% 50%, rgba(37, 99, 235, 0.12), transparent 32%),
    radial-gradient(circle at 82% 50%, rgba(249, 115, 22, 0.12), transparent 32%);
  z-index: -1;
}

.formula-token {
  position: relative;
  isolation: isolate;
}

.formula-token::after {
  content: "";
  position: absolute;
  inset: -4px;
  z-index: -1;
  border-radius: inherit;
  opacity: 0;
  filter: blur(8px);
  transition: opacity var(--duration-normal) var(--ease-out);
}

.formula-token:hover::after {
  opacity: 0.8;
}

.formula-reactant::after {
  background: rgba(37, 99, 235, 0.34);
}

.formula-product::after {
  background: rgba(249, 115, 22, 0.34);
}

.reaction-arrow {
  position: relative;
  animation: simulationArrowPulse 2.4s ease-in-out infinite;
}

@keyframes simulationArrowPulse {
  0%,
  100% {
    transform: translateX(0);
    opacity: 1;
  }

  45% {
    transform: translateX(5px);
    opacity: 0.82;
  }

  70% {
    transform: translateX(-5px);
    opacity: 0.92;
  }
}

/* =========================================================
  Vessel Card
========================================================= */

.vessel-card {
  padding: var(--space-4);
  border-radius: var(--radius-3xl);
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow-md);
}

.vessel-toolbar h3 {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.vessel-toolbar h3::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: var(--radius-full);
  background: var(--gradient-equilibrium);
  box-shadow: 0 0 0 6px rgba(147, 51, 234, 0.12);
}

.rate-pills strong {
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.rate-pills span:first-child strong {
  color: var(--reactant);
}

.rate-pills span:last-child strong {
  color: var(--product);
}

/* =========================================================
  Reaction Vessel Visual
========================================================= */

.reaction-vessel {
  position: relative;
  isolation: isolate;
}

.reaction-vessel::before,
.reaction-vessel::after {
  content: "";
  position: absolute;
  pointer-events: none;
  z-index: 2;
}

.reaction-vessel::before {
  inset: 18px;
  border-radius: calc(var(--radius-3xl) - 0.5rem);
  border: 1px dashed rgba(37, 99, 235, 0.2);
}

.reaction-vessel::after {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(15, 23, 42, 0.12), transparent);
}

.particle-canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

.vessel-overlay {
  z-index: 3;
}

.vessel-label {
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
}

.vessel-legend {
  min-height: 42px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border-soft);
}

/* =========================================================
  Vessel State Modifiers
========================================================= */

.simulation-panel.is-balanced .reaction-vessel {
  border-color: rgba(22, 163, 74, 0.28);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.6),
    var(--shadow-md),
    0 0 36px rgba(22, 163, 74, 0.18);
}

.simulation-panel.is-shifting-right .reaction-vessel {
  border-color: rgba(37, 99, 235, 0.32);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.6),
    var(--shadow-md),
    0 0 36px rgba(37, 99, 235, 0.16);
}

.simulation-panel.is-shifting-left .reaction-vessel {
  border-color: rgba(249, 115, 22, 0.34);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.6),
    var(--shadow-md),
    0 0 36px rgba(249, 115, 22, 0.16);
}

.simulation-panel.is-heated .reaction-vessel {
  background:
    radial-gradient(circle at 30% 28%, rgba(255, 255, 255, 0.74), transparent 24%),
    linear-gradient(135deg, rgba(255, 237, 213, 0.84), rgba(254, 243, 199, 0.72), rgba(243, 232, 255, 0.56));
}

.simulation-panel.is-cooled .reaction-vessel {
  background:
    radial-gradient(circle at 28% 28%, rgba(255, 255, 255, 0.74), transparent 24%),
    linear-gradient(135deg, rgba(219, 234, 254, 0.84), rgba(236, 254, 255, 0.72), rgba(255, 255, 255, 0.56));
}

.simulation-panel.has-catalyst .reaction-vessel::before {
  border-color: rgba(147, 51, 234, 0.28);
  animation: simulationCatalystGlow 1.8s ease-in-out infinite;
}

@keyframes simulationCatalystGlow {
  0%,
  100% {
    box-shadow: inset 0 0 0 rgba(147, 51, 234, 0);
  }

  50% {
    box-shadow: inset 0 0 28px rgba(147, 51, 234, 0.16);
  }
}

/* =========================================================
  Floating Simulation Effects
========================================================= */

.shift-wave {
  position: absolute;
  top: 50%;
  width: 130px;
  height: 130px;
  border-radius: var(--radius-full);
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.86), rgba(147, 51, 234, 0.22), transparent 66%);
  animation: simulationShiftWave 900ms var(--ease-out) forwards;
}

.shift-wave.to-right {
  left: 28%;
}

.shift-wave.to-left {
  right: 28%;
}

@keyframes simulationShiftWave {
  0% {
    opacity: 0.9;
    transform: translate(-50%, -50%) scale(0.4);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.2);
  }
}

.temperature-flash {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  animation: simulationTemperatureFlash 720ms ease-out forwards;
}

.temperature-flash.is-hot,
.temperature-flash:not(.is-cold) {
  background: radial-gradient(circle, rgba(249, 115, 22, 0.28), transparent 68%);
}

.temperature-flash.is-cold {
  background: radial-gradient(circle, rgba(34, 211, 238, 0.28), transparent 68%);
}

@keyframes simulationTemperatureFlash {
  0% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

/* =========================================================
  Status & Data Cards
========================================================= */

.data-card,
.concentration-card {
  position: relative;
  overflow: hidden;
}

.data-card::before,
.concentration-card::before {
  content: "";
  position: absolute;
  width: 160px;
  height: 160px;
  right: -80px;
  top: -80px;
  border-radius: var(--radius-full);
  background: rgba(37, 99, 235, 0.08);
  pointer-events: none;
}

.metric-list > div {
  transition:
    transform var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

.metric-list > div:hover {
  transform: translateX(2px);
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(37, 99, 235, 0.18);
}

#kValue,
#qValue,
#temperatureValue,
#volumeValue,
#forwardRateValue,
#reverseRateValue,
#reactantConcentration,
#productConcentration {
  font-variant-numeric: tabular-nums;
}

#kValue {
  color: var(--equilibrium);
}

#qValue {
  color: var(--primary);
}

#shiftDirectionValue {
  color: var(--product);
}

.simulation-panel.is-balanced #shiftDirectionValue {
  color: var(--success);
}

.simulation-panel.is-shifting-left #shiftDirectionValue {
  color: var(--reactant);
}

.simulation-panel.is-shifting-right #shiftDirectionValue {
  color: var(--product);
}

.concentration-row strong {
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.bar-track {
  position: relative;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.12);
}

.bar-fill {
  position: relative;
  overflow: hidden;
}

.bar-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.38), transparent);
  transform: translateX(-100%);
  animation: simulationBarShimmer 2.2s ease-in-out infinite;
}

@keyframes simulationBarShimmer {
  0% {
    transform: translateX(-100%);
  }

  70%,
  100% {
    transform: translateX(100%);
  }
}

/* =========================================================
  Control Panel
========================================================= */

.control-panel-stack {
  min-width: 0;
}

.control-card {
  position: relative;
  overflow: hidden;
}

.control-card::before {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  right: -84px;
  top: -84px;
  border-radius: var(--radius-full);
  background: rgba(147, 51, 234, 0.08);
  pointer-events: none;
}

.control-card > * {
  position: relative;
  z-index: 1;
}

.control-group {
  position: relative;
}

.control-group h4 {
  margin-bottom: var(--space-1);
}

.control-group .btn {
  min-height: 48px;
}

.range-control {
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid var(--border-soft);
}

.range-control span {
  white-space: nowrap;
}

#temperatureSlider {
  accent-color: var(--product);
}

#volumeSlider {
  accent-color: var(--secondary);
}

.toggle-row input:checked + span {
  color: var(--secondary);
}

.explanation-card {
  background:
    radial-gradient(circle at 88% 20%, rgba(249, 115, 22, 0.12), transparent 30%),
    rgba(255, 255, 255, 0.84);
}

.explanation-text {
  position: relative;
  padding-left: var(--space-4);
}

.explanation-text::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.35em;
  bottom: 0.35em;
  width: 4px;
  border-radius: var(--radius-full);
  background: var(--gradient-equilibrium);
}

/* =========================================================
  Simulation Numeric Change Animations
========================================================= */

.value-bump {
  animation: simulationValueBump 420ms var(--ease-bounce);
}

@keyframes simulationValueBump {
  0% {
    transform: scale(1);
  }

  45% {
    transform: scale(1.16);
  }

  100% {
    transform: scale(1);
  }
}

.data-card.is-updating,
.concentration-card.is-updating {
  animation: simulationDataCardPulse 520ms ease-out;
}

@keyframes simulationDataCardPulse {
  0%,
  100% {
    box-shadow: var(--shadow-lg);
  }

  45% {
    box-shadow: var(--shadow-lg), 0 0 0 6px rgba(37, 99, 235, 0.12);
  }
}

/* =========================================================
  Particle DOM Fallback
========================================================= */

.dom-particle {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  pointer-events: none;
  z-index: 2;
  box-shadow:
    inset -5px -5px 8px rgba(0, 0, 0, 0.22),
    inset 4px 4px 7px rgba(255, 255, 255, 0.74),
    0 6px 14px rgba(15, 23, 42, 0.18);
}

.dom-particle.is-reactant {
  background: var(--reactant);
}

.dom-particle.is-product {
  background: var(--product);
}

.dom-particle.is-transition {
  background: var(--equilibrium);
  animation: simulationSoftPulse 800ms ease-in-out infinite;
}

@keyframes simulationSoftPulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.08);
    opacity: 0.86;
  }
}

/* =========================================================
  Accessibility / Reduced Motion
========================================================= */

@media (prefers-reduced-motion: reduce) {
  .reaction-arrow,
  .bar-fill::after,
  .simulation-panel.has-catalyst .reaction-vessel::before,
  .dom-particle.is-transition {
    animation: none !important;
  }
}

/* =========================================================
  Responsive Simulation Mode
========================================================= */

@media (max-width: 1360px) {
  .vessel-card {
    min-height: 580px;
  }

  .reaction-vessel {
    min-height: 470px;
  }

  .rate-pills {
    justify-content: flex-start;
  }
}

@media (max-width: 1180px) {
  .control-panel-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-card {
    grid-row: span 2;
  }

  .explanation-card {
    align-self: start;
  }
}

@media (max-width: 980px) {
  .simulation-grid {
    padding-inline: var(--space-4);
  }

  .simulation-side-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .vessel-toolbar {
    align-items: flex-start;
  }

  .concentration-row {
    grid-template-columns: 64px 1fr 80px;
  }
}

@media (max-width: 760px) {
  .simulation-panel::before,
  .simulation-panel::after {
    opacity: 0.55;
  }

  .reaction-equation-card {
    min-height: auto;
  }

  .vessel-card {
    min-height: auto;
    padding: var(--space-3);
  }

  .reaction-vessel {
    min-height: 420px;
    border-radius: var(--radius-2xl);
  }

  .reaction-vessel::before {
    inset: 12px;
  }

  .reaction-vessel::after {
    display: none;
  }

  .vessel-overlay {
    inset: var(--space-3);
  }

  .vessel-label {
    font-size: 0.66rem;
  }

  .vessel-legend {
    justify-content: flex-start;
  }

  .simulation-side-stack,
  .control-panel-stack {
    grid-template-columns: 1fr;
  }

  .control-card {
    grid-row: auto;
  }

  .button-grid.two-columns {
    grid-template-columns: 1fr;
  }

  .range-control {
    grid-template-columns: 1fr;
  }

  .range-control span {
    white-space: normal;
  }
}

@media (max-width: 520px) {
  .formula-token {
    font-size: var(--text-lg);
  }

  .reaction-arrow {
    font-size: var(--text-4xl);
  }

  .rate-pills {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .rate-pills span {
    justify-content: space-between;
  }

  .reaction-vessel {
    min-height: 360px;
  }

  .vessel-legend {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .metric-list > div {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-list dd {
    text-align: left;
  }
}