:root {
  --bg-main: #0b0f19;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-panel: #111827;
  --border-color: rgba(255, 255, 255, 0.08);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-red: #ef4444;
  --accent-orange: #f59e0b;
  --font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --glass-blur: blur(12px);
}

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

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  position: relative;
}

/* 통증 위험도 Vignette 경고 오버레이 */
#vignette-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.5s ease;
  box-shadow: inset 0 0 80px rgba(239, 68, 68, 0.6);
}

@keyframes pulse-vignette {
  0%, 100% { box-shadow: inset 0 0 40px rgba(239, 68, 68, 0.3); }
  50% { box-shadow: inset 0 0 90px rgba(239, 68, 68, 0.75); }
}

.danger-alert-active {
  opacity: 1 !important;
  animation: pulse-vignette 1.5s infinite ease-in-out;
}

header {
  padding: 1.5rem 2rem;
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.9) 0%, rgba(11, 15, 25, 0) 100%);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: var(--glass-blur);
}

.header-title-area h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-title-area p {
  font-size: 0.825rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.header-btn {
  background: rgba(6, 182, 212, 0.1);
  color: var(--accent-cyan);
  border: 1px solid rgba(6, 182, 212, 0.3);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.header-btn:hover {
  background: rgba(6, 182, 212, 0.2);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.2);
}

/* 메인 대시보드 그리드 */
.dashboard-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.5rem;
  padding: 1.5rem;
  flex: 1;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

.left-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.main-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--card-shadow);
  backdrop-filter: var(--glass-blur);
  transition: border-color 0.3s ease;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-left: 3px solid var(--accent-cyan);
  padding-left: 0.5rem;
}

/* 인풋 폼 스타일 */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group:last-child {
  margin-bottom: 0;
}

label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.label-val {
  font-weight: 600;
  color: var(--text-primary);
}

select {
  width: 100%;
  background: #1f2937;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.625rem;
  border-radius: 6px;
  outline: none;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

select:focus {
  border-color: var(--accent-cyan);
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #1f2937;
  outline: none;
  margin: 0.5rem 0;
}

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

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

/* 스위치 스타일 */
.switch-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 0.25rem 0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-round {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #1f2937;
  transition: .3s;
  border-radius: 34px;
  border: 1px solid var(--border-color);
}

.slider-round:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider-round {
  background-color: var(--accent-cyan);
}

input:checked + .slider-round:before {
  transform: translateX(22px);
}

/* 수치 대시보드 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1rem;
}

.stat-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  padding: 1rem;
  border-radius: 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  font-weight: 500;
}

.stat-val {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  font-feature-settings: "tnum";
}

.stat-box.highlight {
  border-color: rgba(6, 182, 212, 0.3);
  background: rgba(6, 182, 212, 0.02);
}

.stat-box.highlight .stat-val {
  color: var(--accent-cyan);
}

.stat-box.pain-box {
  transition: all 0.3s ease;
}

.pain-level-normal {
  border-color: rgba(16, 185, 129, 0.3) !important;
  background: rgba(16, 185, 129, 0.02) !important;
}
.pain-level-normal .stat-val {
  color: var(--accent-emerald) !important;
}

.pain-level-warn {
  border-color: rgba(245, 158, 11, 0.3) !important;
  background: rgba(245, 158, 11, 0.02) !important;
}
.pain-level-warn .stat-val {
  color: var(--accent-orange) !important;
}

.pain-level-danger {
  border-color: rgba(239, 68, 68, 0.4) !important;
  background: rgba(239, 68, 68, 0.05) !important;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.1);
}
.pain-level-danger .stat-val {
  color: var(--accent-red) !important;
  text-shadow: 0 0 5px rgba(239, 68, 68, 0.5);
}

/* 프로필 디스크립션 */
.profile-desc {
  font-size: 0.8rem;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.05);
  border: 1px dashed rgba(6, 182, 212, 0.2);
  padding: 0.75rem;
  border-radius: 6px;
  line-height: 1.4;
  margin-top: -0.5rem;
  margin-bottom: 0.5rem;
}

/* 중앙 영역: 결과 메인 및 그래프 */
.graph-container-card {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 380px;
}

.tabs-container {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

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

.tab-btn.active {
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid rgba(6, 182, 212, 0.2);
}

.canvas-wrapper {
  position: relative;
  flex: 1;
  background: #090d16;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* 하단 튜닝 패널 */
.tuning-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
}

.tuning-card {
  grid-column: 1 / -1;
}

.tuning-item {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.01);
  padding: 0.75rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.tuning-item input[type="number"] {
  background: #1f2937;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.4rem;
  border-radius: 4px;
  font-size: 0.85rem;
  outline: none;
  width: 80px;
  text-align: center;
}

.tuning-item input[type="number"]:focus {
  border-color: var(--accent-cyan);
}

.tuning-control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* 체크박스 그룹 */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-cyan);
  cursor: pointer;
}

/* 모달 스타일 (수식 확인기) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(7, 10, 19, 0.85);
  backdrop-filter: blur(8px);
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  width: 90%;
  max-width: 780px;
  max-height: 85vh;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transform: translateY(20px);
  transition: transform 0.3s ease;
}

.modal-overlay.show .modal-content {
  transform: translateY(0);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  transition: color 0.2s;
}

.close-btn:hover {
  color: var(--accent-red);
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.math-formula-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem;
}

.formula-header {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent-cyan);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.formula-latex {
  font-family: 'Courier New', Courier, monospace;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.75rem;
  border-radius: 6px;
  font-size: 1.1rem;
  text-align: center;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.03);
  margin: 0.5rem 0;
  overflow-x: auto;
}

.formula-trace {
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: rgba(16, 185, 129, 0.05);
  border-left: 3px solid var(--accent-emerald);
  padding: 0.5rem 0.75rem;
  border-radius: 0 4px 4px 0;
  margin-top: 0.5rem;
  font-family: monospace;
}

.formula-description {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

/* 통증 상태 가이드 박스 */
.pain-status-desc-box {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;
}

.pain-status-desc-box .status-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.pain-status-desc-box .status-text {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

.status-zero {
  border-left: 4px solid var(--text-secondary);
}
.status-zero .status-title { color: var(--text-secondary); }

.status-mild {
  border-left: 4px solid var(--accent-emerald);
  background: rgba(16, 185, 129, 0.05);
}
.status-mild .status-title { color: var(--accent-emerald); }

.status-moderate {
  border-left: 4px solid var(--accent-orange);
  background: rgba(245, 158, 11, 0.05);
}
.status-moderate .status-title { color: var(--accent-orange); }

.status-severe {
  border-left: 4px solid var(--accent-red);
  background: rgba(239, 68, 68, 0.05);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.2);
}
.status-severe .status-title { color: var(--accent-red); }

/* 반응형 모바일 최적화 */
@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}
