:root {
  --bg-dark: #070913;
  --panel-bg: rgba(12, 16, 28, 0.65);
  --panel-border: rgba(255, 255, 255, 0.08);
  
  --accent: #22d3ee;
  --accent-hover: #06b6d4;
  --accent-glow: rgba(34, 211, 238, 0.35);
  
  --accent-orange: #f97316;
  --accent-orange-glow: rgba(249, 115, 22, 0.4);

  --accent-green: #10b981;
  --accent-green-glow: rgba(16, 185, 129, 0.4);

  --accent-red: #ef4444;
  --accent-blue: #3b82f6;

  --text-main: #f0f4f8;
  --text-muted: #8892a4;
  
  --card-bg: rgba(13, 17, 30, 0.85);
  --card-border: rgba(255, 255, 255, 0.07);
  
  --font-family: 'Noto Sans KR', sans-serif;
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-family);
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

.app-container {
  width: 100%;
  max-width: 1600px;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 12px;
}

/* Header Styles */
.app-header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(12px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.back-btn {
  border-color: rgba(255, 255, 255, 0.15);
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.principle-btn {
  background: rgba(34, 211, 238, 0.08);
  color: var(--accent);
  border-color: rgba(34, 211, 238, 0.3);
}

.principle-btn:hover {
  background: rgba(34, 211, 238, 0.15);
  border-color: rgba(34, 211, 238, 0.5);
  box-shadow: 0 0 15px var(--accent-glow);
}

.title-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  background-color: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent-glow), 0 0 20px var(--accent-glow);
  animation: pulse-animation 2s infinite;
}

@keyframes pulse-animation {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(34, 211, 238, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 211, 238, 0);
  }
}

.title-container h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

/* Tab Menu */
.sim-tab-menu {
  display: flex;
  margin-left: 30px;
  margin-right: auto;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 4px;
  margin: 0;
  gap: 4px;
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-family: var(--font-family);
  font-size: 0.85rem;
  white-space: nowrap;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(34, 211, 238, 0.3);
}

/* Tab Panes */
.tab-pane.hidden {
  display: none;
}

/* Main Content */
.main-content {
  display: flex;
  flex: 1;
  gap: 16px;
  height: calc(100% - 80px);
}

/* Simulation Panel (Left) */
.simulation-panel {
  flex: 1;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(12px);
}

.canvas-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #02040a;
  touch-action: none;
}

.hint-overlay {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(5, 7, 15, 0.85);
  border: 1px solid var(--panel-border);
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 10;
  backdrop-filter: blur(6px);
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.hint-dot {
  width: 6px;
  height: 6px;
  background-color: var(--accent-orange);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 8px var(--accent-orange-glow);
}

/* Graph Overlay (Bottom Right of Left Panel) */
.graph-overlay {
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 320px;
  height: 220px;
  background: rgba(8, 12, 24, 0.9);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  z-index: 20;
  backdrop-filter: blur(8px);
  transition: all 0.3s;
}

.graph-header {
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 8px 12px;
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

.graph-canvas-container {
  flex: 1;
  background: #040712;
  position: relative;
}

#graphCanvas {
  width: 100%;
  height: 100%;
  background: transparent;
  display: block;
}

.graph-legend {
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding: 6px;
  font-size: 0.7rem;
  display: flex;
  justify-content: space-around;
  font-weight: 600;
}

.legend-item.plus {
  color: var(--accent-orange);
}
.legend-item.zero {
  color: var(--text-muted);
}
.legend-item.minus {
  color: var(--accent-green);
}

/* Control Panel (Right) */
.control-panel {
  width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 2px;
}

.control-panel::-webkit-scrollbar {
  width: 6px;
}
.control-panel::-webkit-scrollbar-track {
  background: transparent;
}
.control-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
.control-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.control-card, .info-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 14px 18px;
  backdrop-filter: blur(10px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  border-left: 3.5px solid var(--accent);
  padding-left: 8px;
}

.fold-btn {
  display: none; /* PC에서는 보이지 않음 */
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-family: var(--font-family);
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.fold-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.card-body {
  transition: all 0.3s ease;
  overflow: hidden;
}

.card-body.collapsed {
  display: none;
}

/* Control Elements */
.control-group {
  margin-bottom: 14px;
}

.control-label-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  display: block;
  margin-bottom: 6px;
}

.label-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.val-text {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: monospace;
}

input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  margin-top: -6px;
  box-shadow: 0 0 8px var(--accent-glow);
  transition: transform 0.1s, background-color 0.2s;
}

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

input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

input[type=range]:focus {
  outline: none;
}

/* Toggle Options */
.toggle-group {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 12px;
  margin-top: 12px;
}

.toggle-options-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Custom Checkbox */
.checkbox-container {
  display: flex;
  align-items: center;
  position: relative;
  padding-left: 26px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-muted);
  user-select: none;
  font-weight: 500;
}

.checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  height: 16px;
  width: 16px;
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  transition: all 0.2s;
}

.checkbox-container:hover input ~ .checkmark {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
}

.checkbox-container input:checked ~ .checkmark {
  background-color: var(--accent);
  border-color: var(--accent);
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
  display: block;
}

.checkbox-container .checkmark:after {
  left: 5px;
  top: 2px;
  width: 4px;
  height: 8px;
  border: solid #05070f;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.checkbox-container input:checked ~ span:not(.checkmark) {
  color: var(--text-main);
}

/* Switch Buttons */
.switch-button-group {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  padding: 3px;
}

.switch-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 12px;
  font-family: var(--font-family);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.switch-btn:hover {
  color: var(--text-main);
}

.switch-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Action Buttons */
.action-buttons {
  margin-top: 16px;
  display: flex;
}

.action-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  font-family: var(--font-family);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn.secondary {
  background: transparent;
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.action-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.25);
}

/* Info Elements */
.info-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.info-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.info-row .highlight {
  color: #fff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: monospace;
}

.info-row .voltage-text {
  font-size: 1rem;
  padding: 2px 8px;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(3, 5, 12, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: rgba(13, 17, 30, 0.96);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  padding: 24px 28px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  transform: scale(1);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
}

.modal-backdrop.hidden .modal-content {
  transform: scale(0.95) translateY(20px);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 12px;
  flex-shrink: 0;
}

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

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  transition: color 0.2s, transform 0.2s;
  line-height: 1;
}

.close-btn:hover {
  color: #fff;
  transform: rotate(90deg);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding-right: 4px;
}

.modal-body::-webkit-scrollbar {
  width: 4px;
}
.modal-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

.modal-body h3 {
  color: var(--accent);
  font-size: 1rem;
  margin-top: 8px;
  margin-bottom: 2px;
  font-weight: 700;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
  padding-bottom: 4px;
}

.modal-body p {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.6;
}

.modal-body ul {
  padding-left: 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.6;
}

.modal-body li {
  margin-bottom: 4px;
}

.formula-box {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  font-family: 'Times New Roman', Times, serif;
  font-size: 1.1rem;
  color: #fff;
  margin: 6px 0;
}

.law-cases {
  display: grid;
  grid-template-cols: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

.case-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 10px 12px;
}

.case-item h4 {
  font-size: 0.88rem;
  color: var(--accent-orange);
  margin-bottom: 6px;
}
.case-item:last-child h4 {
  color: var(--accent-green);
}

.case-item p, .case-item ul {
  font-size: 0.78rem;
}

/* === 모바일(반응형) 최적화 레이아웃 === */
@media (max-width: 768px) {
  body {
    overflow: auto; 
    height: auto;
    min-height: 100vh;
  }
  
  .app-container {
    height: auto;
    min-height: 100%;
    gap: 12px;
    padding: 10px;
  }

  .main-content {
    flex-direction: column;
    height: auto;
  }

  .simulation-panel {
    width: 100%;
    height: 380px;
    min-height: 360px;
    flex: none;
    border-radius: 12px;
  }

  .control-panel {
    width: 100%;
    padding-right: 0;
    overflow-y: visible; 
  }

  .app-header {
    flex-direction: column;
    padding: 12px;
    gap: 12px;
    align-items: stretch;
  }

  .header-left {
    order: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }

  .sim-tab-menu {
    order: 2;
    position: static;
    transform: none;
    width: 100%;
    margin-left: 0;
  }

  .header-right {
    order: 3;
    width: 100%;
  }

  .title-container h1 {
    font-size: 1rem;
    letter-spacing: -0.5px;
  }

  .sim-tab-menu .tab-btn {
    flex: 1;
    padding: 6px 4px; /* 모바일에서 텍스트가 다 들어갈 수 있게 패딩 축소 */
    font-size: 0.8rem;
  }

  .icon-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
  }

  /* 원리 설명 버튼 가로 확장 */
  .header-right .principle-btn {
    width: 100%;
    justify-content: center;
    padding: 10px;
  }

  /* 모바일에서만 접기 버튼 보이기 */
  .fold-btn {
    display: inline-block;
  }
}
