:root {
  --navy-900: #0b1b2a;
  --navy-800: #0f2538;
  --navy-700: #12304a;
  --navy-600: #173c5d;
  --navy-500: #1c4b73;
  --navy-400: #205b8a;
  --accent-cyan: #39d1ff;
  --accent-blue: #5aa6ff;
  --text-100: #f4f7fb;
  --text-300: #c7d3e0;
  --muted-500: #7b8a9a;
  --panel-700: rgba(255, 255, 255, 0.04);
  --panel-600: rgba(255, 255, 255, 0.06);
  --border-500: rgba(255, 255, 255, 0.1);
  --shadow-900: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html, body, .app {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, 'Apple Color Emoji', 'Segoe UI Emoji';
  color: var(--text-100);
  background: radial-gradient(1200px 700px at 80% -100px, var(--navy-600), transparent 60%),
              radial-gradient(900px 600px at 20% -100px, var(--navy-700), transparent 55%),
              linear-gradient(160deg, var(--navy-900), var(--navy-800));
  overflow: hidden; /* prevent page scroll so bottom stays 1/4 */
}

.app {
  display: grid;
  grid-template-rows: minmax(0, 3fr) minmax(0, 1fr); /* strict 3/4 + 1/4, no overflow push */
  gap: 18px;
  padding: 18px;
  height: 100dvh; /* lock to viewport height */
  min-height: 100dvh;
  overflow: hidden; /* ensure internal overflow is clipped */
}

.top-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  min-height: 0; /* allow child overflow handling */
  overflow: hidden; /* prevent internal scroll in top section */
}

.sidebar {
  background: var(--panel-700);
  border: 1px solid var(--border-500);
  border-radius: 16px;
  padding: 18px 16px 16px;
  box-shadow: var(--shadow-900);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: auto; /* local scroll */
  min-height: 0; /* allow scrolling inside grid */
}

.sidebar__header {
  position: sticky;
  top: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-500);
  background: var(--panel-700);
  z-index: 1;
}

.app-title {
  margin: 0 0 6px 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.subtitle {
  margin: 0;
  color: var(--text-300);
  font-size: 12px;
}

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

.control-group {
  background: var(--panel-600);
  border: 1px solid var(--border-500);
  border-radius: 12px;
  padding: 12px;
}

.control-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-300);
  margin-bottom: 8px;
}

.control-label .value {
  color: var(--accent-cyan);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
  border-radius: 999px;
  outline: none;
}

.select {
  width: 100%;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-500);
  background: var(--panel-700);
  color: var(--text-100);
  padding: 0 10px;
}

.toggles { display: grid; gap: 8px; }
.toggle-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-300); }

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent-cyan);
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent-cyan);
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.control-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.btn {
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-500);
  font-weight: 600;
  color: var(--text-100);
  cursor: pointer;
  transition: transform 0.06s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(180deg, var(--accent-blue), var(--accent-cyan));
  color: #0a1630;
}

.btn-secondary {
  background: var(--panel-600);
}

.viewport {
  position: relative;
  background: var(--panel-700);
  border: 1px solid var(--border-500);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-900);
}

#simCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* removed watermark overlay */

.graph-area {
  min-height: 0;
  overflow: hidden; /* keep chart within its 1/4 track */
}

/* Ensure the chart respects the container height on all browsers */
.graph-area, .graph-card, .graph-card__body {
  min-height: 0;
}

.graph-card {
  height: 100%;
  background: var(--panel-700);
  border: 1px solid var(--border-500);
  border-radius: 16px;
  box-shadow: var(--shadow-900);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden; /* keep chart fully inside rounded card */
}

.graph-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-500);
}

.graph-card__header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.legend {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-300);
}

.legend__item::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
}

.legend--lift::before {
  background: var(--accent-cyan);
}

.legend--drag::before {
  background: var(--accent-blue);
}

.graph-card__body {
  position: relative;
  padding: 8px 12px 12px;
  height: 100%;
  display: grid; /* allow child (canvas) to stretch */
}

#liftDragChart {
  width: 100% !important;
  height: 100% !important;
  display: block; /* remove inline baseline gap */
}

@media (max-width: 1024px) {
  .top-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    order: 2;
  }
  .viewport {
    order: 1;
    min-height: 40vh;
  }
}

