/* ==========================================================================
   MuJoCo Cartpole Inverted Pendulum Simulator - Style System
   ========================================================================== */

:root {
  --bg-primary: #0a0d14;
  --bg-secondary: #101623;
  --bg-card: rgba(22, 30, 46, 0.75);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --accent-cyan: #00f0ff;
  --accent-blue: #3b82f6;
  --accent-purple: #8b5cf6;
  --accent-yellow: #fbbf24;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --glass-blur: blur(16px);
  --shadow-glow: 0 0 20px rgba(0, 240, 255, 0.15);
  --font-sans: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ================= Header ================= */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: rgba(16, 22, 35, 0.85);
  backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--bg-card-border);
  z-index: 100;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 10px var(--accent-emerald);
  animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 30%, var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  font-family: var(--font-sans);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  color: #fff;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.45);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border: 1px solid var(--bg-card-border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

/* ================= Main Layout ================= */
.main-layout {
  display: flex;
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* 3D Viewport */
.viewport-wrapper {
  flex: 1;
  position: relative;
  height: 100%;
  background: #000;
  overflow: hidden;
}

#canvas-container {
  width: 100%;
  height: 100%;
}

/* Telemetry Overlay */
.telemetry-overlay {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  pointer-events: none;
  z-index: 20;
}

.telemetry-card {
  background: rgba(10, 15, 25, 0.8);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--bg-card-border);
  padding: 8px 14px;
  border-radius: 10px;
  min-width: 110px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.telemetry-card.highlight {
  border-color: rgba(0, 240, 255, 0.3);
  box-shadow: var(--shadow-glow);
}

.telemetry-card .label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
}

.telemetry-card .value {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.progress-bar-wrap {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
  position: relative;
}

.progress-bar {
  height: 100%;
  width: 50%;
  background: var(--accent-cyan);
  transition: width 0.05s linear;
}

/* Oscilloscope Graph Panel */
.graph-panel {
  position: absolute;
  bottom: 64px;
  left: 16px;
  background: rgba(10, 15, 25, 0.75);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--bg-card-border);
  border-radius: 12px;
  padding: 8px 14px;
  z-index: 20;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  width: calc(100% - 32px);
  max-width: 620px;
}

.graph-panel.hidden {
  transform: translateY(120%);
  opacity: 0;
  pointer-events: none;
}

.graph-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-family: var(--font-mono);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}
.dot-cyan { background: var(--accent-cyan); box-shadow: 0 0 6px var(--accent-cyan); }
.dot-magenta { background: #f43f5e; box-shadow: 0 0 6px #f43f5e; }
.dot-yellow { background: var(--accent-yellow); box-shadow: 0 0 6px var(--accent-yellow); }

#oscilloscopeCanvas {
  width: 100%;
  height: 85px;
  display: block;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 6px;
}

/* Floating Controls */
.viewport-controls {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  gap: 8px;
  z-index: 20;
}

.floating-btn {
  background: rgba(16, 22, 35, 0.85);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.floating-btn:hover {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}

.impulse-btn {
  background: rgba(244, 63, 94, 0.15);
  border-color: rgba(244, 63, 94, 0.4);
  color: #ff94a8;
}

.impulse-btn:hover {
  background: rgba(244, 63, 94, 0.3);
  box-shadow: 0 0 12px rgba(244, 63, 94, 0.4);
}

/* ================= Control Sidebar ================= */
.control-panel {
  width: 380px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--bg-card-border);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.5);
  z-index: 50;
}

.panel-section {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--bg-card-border);
  border-radius: 12px;
  padding: 16px;
}

.section-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  letter-spacing: -0.01em;
}

.mode-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-chip {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--bg-card-border);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-main);
  display: flex;
  flex-direction: column;
}

.mode-chip strong {
  font-size: 0.85rem;
}

.mode-chip span {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.mode-chip.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent-blue);
  box-shadow: 0 0 14px rgba(59, 130, 246, 0.25);
}

.formula-box {
  background: #090d15;
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  border-left: 3px solid var(--accent-cyan);
}

.formula-box code {
  font-size: 0.78rem;
  color: var(--accent-cyan);
  display: block;
}

.formula-box small {
  font-size: 0.7rem;
  color: var(--text-dim);
  display: block;
  margin-top: 4px;
}

/* Gain sliders */
.control-row {
  margin-bottom: 12px;
}

.control-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  margin-bottom: 4px;
  color: var(--text-muted);
}

.gain-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-cyan);
}

input[type="range"] {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
  -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-cyan);
  transition: transform 0.1s ease;
}

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

/* Param Grid */
.param-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.param-item {
  background: rgba(0, 0, 0, 0.25);
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.param-item label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
}

.param-value {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  font-family: var(--font-mono);
}

.highlight-box {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.08));
  border-color: rgba(59, 130, 246, 0.3);
}

.highlight-box h3 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-yellow);
  margin-bottom: 6px;
}

.highlight-box p {
  font-size: 0.78rem;
  color: #cbd5e1;
  line-height: 1.5;
}

/* ================= Modal Window ================= */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-window {
  width: 90%;
  max-width: 960px;
  max-height: 85vh;
  background: #111827;
  border: 1px solid var(--bg-card-border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: #1a2234;
  border-bottom: 1px solid var(--bg-card-border);
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.8rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: #fff;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  font-size: 0.92rem;
  line-height: 1.7;
  color: #e2e8f0;
}

.modal-body h1, .modal-body h2, .modal-body h3 {
  color: #fff;
  margin-top: 1.4em;
  margin-bottom: 0.6em;
}

.modal-body h2 {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 6px;
  color: var(--accent-cyan);
}

.modal-body p {
  margin-bottom: 1em;
}

.modal-body ul, .modal-body ol {
  margin-left: 20px;
  margin-bottom: 1em;
}

.modal-body pre {
  background: #090d15;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin-bottom: 1.2em;
}

.modal-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2em 0;
}

.modal-body th, .modal-body td {
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 14px;
  text-align: left;
}

.modal-body th {
  background: rgba(255, 255, 255, 0.05);
  color: var(--accent-cyan);
}

/* Responsive */
@media (max-width: 900px) {
  .main-layout {
    flex-direction: column;
  }
  .control-panel {
    width: 100%;
    height: 320px;
  }
}
