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

body {
  min-height: 100vh;
  width: 100%;
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
  background: #f1f5f9;
}

/* ===== LAYOUT ===== */
.container {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: row;
  background: #f1f5f9;
}

/* ===== LEFT PANEL ===== */
.if-vid {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
}

.p-head {
  font-weight: 700;
  font-size: 17px;
  color: #1e293b;
  align-self: flex-start;
  margin-bottom: 18px;
  letter-spacing: 0.3px;
}

/* ===== SERVO WRAPPER ===== */
.servo-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  width: 100%;
  background: #ffffff;
  border-radius: 16px;
  padding: 24px 20px 20px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  border: 1px solid #e2e8f0;
  overflow: hidden;
}

#servoSVG {
  width: 100%;
  height: 100%;
  flex: 1;
}

/* ===== ANGLE BADGE ===== */
.angle-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(135deg, #0f172a, #1e3a8a);
  color: #fff;
  border-radius: 14px;
  padding: 10px 32px 8px;
  box-shadow: 0 4px 16px rgba(30, 58, 138, 0.4);
  min-width: 130px;
}

.angle-badge #liveAngle {
  font-size: 42px;
  font-weight: 800;
  line-height: 1;
  color: #fbbf24;
  font-variant-numeric: tabular-nums;
}

.deg-sym {
  font-size: 26px;
  font-weight: 700;
  color: #fbbf24;
  vertical-align: super;
}

.angle-label {
  font-size: 11px;
  color: #93c5fd;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 2px;
}

/* ===== RIGHT PANEL ===== */
.right-panel {
  width: 660px;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-left: 1px solid #e2e8f0;
  overflow: hidden;
}

/* ===== INSTRUCTION BOX ===== */
.instruction-box {
  flex: 0 0 44%;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid #e2e8f0;
  overflow: hidden;
}

.box-title {
  padding: 14px 20px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  font-size: 15px;
  font-weight: 700;
  color: #1e293b;
  margin: 0;
}

.instruction-content {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  font-size: 13.5px;
  line-height: 1.65;
  color: #475569;
}

.instruction-content::-webkit-scrollbar {
  width: 6px;
}

.instruction-content::-webkit-scrollbar-track {
  background: #f1f5f9;
}

.instruction-content::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.instruction-section {
  margin-bottom: 18px;
}

.instruction-section:last-child {
  margin-bottom: 0;
}

.instruction-section h4 {
  color: #0f172a;
  margin-bottom: 7px;
  font-size: 13.5px;
  font-weight: 700;
}

.instruction-section p {
  color: #475569;
  margin-bottom: 6px;
}

.instruction-section ol,
.instruction-section ul {
  margin-left: 18px;
  margin-bottom: 8px;
}

.instruction-section li {
  margin-bottom: 6px;
  line-height: 1.55;
}

.instruction-section strong {
  color: #1e3a8a;
  font-weight: 700;
}

/* ===== CODE BOX ===== */
.code-box {
  flex: 0 0 56%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.code-box-header {
  padding: 12px 16px;
  background: #1e293b;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px solid #334155;
}

.code-box-header .box-title {
  color: #e2e8f0;
  background: transparent;
  border: none;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
}

.code-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ===== SPEED CONTROL ===== */
.speed-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
}

.speed-lbl {
  font-size: 12px;
  color: #94a3b8;
  white-space: nowrap;
}

.speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 4px;
  border-radius: 2px;
  background: #334155;
  outline: none;
  cursor: pointer;
}

.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #3b82f6;
  cursor: pointer;
  box-shadow: 0 0 4px rgba(59, 130, 246, 0.6);
}

.speed-val {
  font-size: 12px;
  color: #60a5fa;
  font-weight: 700;
  min-width: 32px;
}

/* ===== BUTTONS ===== */
.control-btn {
  padding: 7px 16px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.25s ease;
  letter-spacing: 0.3px;
}

.start-btn {
  background: #22c55e;
  color: #fff;
}

.start-btn:hover {
  background: #16a34a;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
}

.stop-btn {
  background: #ef4444;
  color: #fff;
}

.stop-btn:hover {
  background: #dc2626;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.play-icon {
  font-size: 10px;
}

/* ===== ERROR MSG ===== */
.error-msg {
  background: #fef2f2;
  border-left: 4px solid #ef4444;
  color: #991b1b;
  font-size: 12px;
  padding: 10px 14px;
  font-family: monospace;
  white-space: pre-wrap;
  max-height: 100px;
  overflow-y: auto;
  flex-shrink: 0;
  line-height: 1.6;
}

/* ===== CODE CONTENT (CodeMirror) ===== */
.code-content {
  flex: 1;
  overflow: hidden;
  background: #272822;
}

#arduinoCode {
  display: none;
}

/* ── Editable line (angle variable, line 1) ── */
.editable-line {
  background: rgba(251, 191, 36, 0.13) !important;
  border-left: 3px solid #fbbf24 !important;
}

/* ── Read-only lines (all other lines) ── */
.readonly-line {
  background: rgba(15, 23, 42, 0.35) !important;
  opacity: 0.55;
  cursor: not-allowed !important;
}

.code-content .CodeMirror {
  width: 100%;
  height: 100%;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.55;
}

.code-content .CodeMirror-scroll {
  overflow-y: auto !important;
  overflow-x: auto !important;
  min-height: 100%;
}

.code-content .CodeMirror-hscrollbar {
  height: 10px !important;
}

.code-content .CodeMirror-vscrollbar {
  width: 10px !important;
}

.code-content .CodeMirror-scrollbar-filler {
  background: #272822;
}

.code-content .CodeMirror-hscrollbar::-webkit-scrollbar {
  height: 10px;
}

.code-content .CodeMirror-hscrollbar::-webkit-scrollbar-track {
  background: #1e1e1e;
}

.code-content .CodeMirror-hscrollbar::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 5px;
}

.code-content .CodeMirror-vscrollbar::-webkit-scrollbar {
  width: 10px;
}

.code-content .CodeMirror-vscrollbar::-webkit-scrollbar-track {
  background: #1e1e1e;
}

.code-content .CodeMirror-vscrollbar::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 5px;
}

/* ===== RESPONSIVE ===== */
@media screen and (max-width: 1100px) {
  .right-panel {
    width: 560px;
  }
}

@media screen and (max-width: 900px) {
  .container {
    flex-direction: column;
  }

  .if-vid {
    flex: none;
    height: 48%;
    padding: 14px;
  }

  .right-panel {
    width: 100%;
    flex: 1;
    flex-direction: row;
  }

  .instruction-box {
    flex: 0 0 40%;
    border-bottom: none;
    border-right: 1px solid #e2e8f0;
  }

  .code-box {
    flex: 0 0 60%;
  }
}

@media screen and (max-width: 640px) {
  .right-panel {
    flex-direction: column;
    height: 55%;
  }

  .instruction-box {
    flex: 0 0 38%;
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
  }

  .code-box {
    flex: 0 0 62%;
  }

  .code-box-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .angle-badge #liveAngle {
    font-size: 32px;
  }

  .servo-wrapper {
    padding: 14px;
  }
}